"use strict";
if ( typeof thrixty !== "undefined" ) {
thrixty.ManuallyLoadPlugins.ShortcodeGenerator = function (){
this.editor;
this.frame_new;
this.frame_edit_player;
this.frame_edit_layout;
this.overlay;
this.labels = new thrixty.ManuallyLoadPlugins.Tinymcelabels();
this.init = function (){
this.labels.init();
tinymce.create( "tinymce.plugins.thrixty_shortcode_generator", {
init: function ( editor, url ){
this.editor = editor;
this.generate_dialog();
/**
*
* Generate a button to insert the shortcode
*/
editor.addButton("thrixty_shortcode_generator_button", {
title: "Thrixty Player",
image: url + "/../images/PlayerThrixty_50px.png",
onclick: this.show.bind(this)
});
/**
*
* Fires after clicking on the visuell view tab
* Fires after the content was inserted
*/
editor.onSetContent.add(function (d, e) {
this.assign_events();
}.bind(this));
/**
*
* Fires after the initialization
*/
editor.onInit.add(function (editor){
/**
*
* Fires after the visuell type content was set
*/
editor.selection.onSetContent.add(function (d, e){
this.assign_events();
}.bind(this));
}.bind(this));
}.bind(this)
});
tinymce.PluginManager.add( "thrixty_shortcode_generator", tinymce.plugins.thrixty_shortcode_generator );
}
}
thrixty.ManuallyLoadPlugins.ShortcodeGenerator.prototype.show = function (){
this.change_type(jQuery("input[type=radio][name=thrixty_insert_type_radiogroup]:checked").val());
this.overlay.show();
this.frame_new.show();
}
//******************** GENERAL ********************//
thrixty.ManuallyLoadPlugins.ShortcodeGenerator.prototype.generate_dialog = function (){
var output = "";
this.frame_new = jQuery("
");
this.frame_edit_player = jQuery("
");
this.frame_edit_layout = jQuery("
");
this.overlay = jQuery("
");
jQuery("body").append(this.overlay);
jQuery("body").append(this.frame_new);
jQuery("body").append(this.frame_edit_player);
jQuery("body").append(this.frame_edit_layout);
this.overlay.bind( "click", function (){
this.overlay.hide();
this.frame_edit_player.hide();
this.frame_edit_layout.hide();
this.frame_new.hide();
}.bind(this));
// BUILD NEW FRAME
output += "";
output += "
"
output += "
";
output += "
" + this.labels.get_label( "dialogs.main.headline" ) + " ";
output += "";
output += "
";
output += "
"
output += "
";
output += " ";
output += "
";
output += "
";
output += "
";
output += "
";
output += "
" + this.labels.get_label( "dialogs.main.text" ) + " ";
output += "";
output += "
";
output += "
";
output += "
";
output += "
";
output += "
";
output += "
";
output += "
";
this.frame_new.append(output);
this.radio_player = jQuery("#thrixty_insert_dialog_radio_player");
this.radio_layout = jQuery("#thrixty_insert_player_dialog_radio");
this.dialog_content = jQuery("#thrixty_insert_player_dialog_content");
// CLOSE POPUPS
jQuery("#thrixty_insert_dialog").find(".close_button").on("click", function ( element ){
jQuery("#thrixty_insert_dialog").hide();
this.overlay.hide();
}.bind(this));
// CHANAGE TYPE: EVENT TRIGGER
jQuery("input[type=radio][name=thrixty_insert_type_radiogroup]").change(function ( element ){
this.change_type(element.target.value);
}.bind(this));
}
thrixty.ManuallyLoadPlugins.ShortcodeGenerator.prototype.change_type = function ( type ){
if (type == "player") {
this.generate_player_dialog();
}
else if (type == "layout") {
this.generate_layout_dialog();
}
}
//******************** PLAYER ********************//
thrixty.ManuallyLoadPlugins.ShortcodeGenerator.prototype.generate_player_dialog = function (){
var output = "";
jQuery.ajax({
url: ajaxurl,
type: "POST",
dataType: "json",
data: {
action: "thrixty_get_all_players"
},
success: function ( response ){
if ( response != 0 ) {
if ( response.success ) {
var all_players = response.data;
output += "";
for (var i = 0; i < all_players.length; i++) {
output += "";
output += "
"+ all_players[i].id +"
";
output += "
"+ all_players[i].name +"
";
output += "
"+ all_players[i].description +"
";
output += "
" + this.labels.get_label( "dialogs.insert_player.insert_shortcode" ) + "
";
output += "
";
}
} else {
output = "" + this.labels.get_label( "dialogs.insert_player.error_no_players" ) + " " + this.labels.get_label( "dialogs.insert_player.error_no_players_create_player" ) + " ";
}
}
this.dialog_content.html( output );
/**
*
* Bind click events on the insert buttons
*/
this.insert_player();
}.bind(this),
error: function ( error ){
return false;
}
});
}
thrixty.ManuallyLoadPlugins.ShortcodeGenerator.prototype.generate_player_edit_dialog = function ( id ){
var output = "";
/**
*
* Build the main html structure
*/
output += "";
output += "
"
output += "
" + this.labels.get_label( "dialogs.edit_player.headline" ) + " ";
output += "";
output += "
"
output += "
";
output += "
";
output += "
";
output += "
";
output += "
";
output += " ";
output += "
";
output += "
";
output += "
"
output += "
";
output += "
";
output += "
";
output += "
";
this.frame_edit_player.html(output);
/**
*
* Assign a click event to the close button
*/
jQuery("#thrixty_edit_dialog_player").find(".close_button").on("click", function ( element ){
jQuery("#thrixty_edit_dialog_player").hide();
this.overlay.hide();
}.bind(this));
/**
*
* Display the frame
*/
this.overlay.show();
this.frame_edit_player.show();
/**
*
* Load the data via ajax request
*/
jQuery.ajax({
url: ajaxurl,
type: "POST",
dataType: "json",
data: {
action: "thrixty_get_player",
id: id
},
success: function ( response ){
var data = "";
var iframe = "";
var message = "";
if ( response != 0 ) {
if ( response.success ) {
var player = response.data[0];
if ( player != null ) {
/**
*
* Display the main data
*/
data += "";
data += "";
data += "
"+ player.id +"
";
data += "
"+ player.name +"
";
data += "
"+ player.description +"
";
data += "
" + this.labels.get_label( "dialogs.edit_player.button_edit_player" ) + "
";
data += "
";
jQuery("#thrixty_edit_player_dialog_content").html(data);
/**
*
* Create a iframe to edit the player settings
* Display the iframe
*
* @src admin_url + ?page=thrixty_edit_player&mode=edit&id=[player_id]
*/
iframe += " "
iframe += "";
iframe += "";
iframe += "
";
jQuery("#thrixty_edit_player_dialog_container").append(iframe);
/**
*
* Check player path settings
*/
jQuery.ajax({
url: player.small_filelist_absolute_path,
async: false,
type: "POST",
success: function ( response ){},
error: function ( error ){
/**
*
* Display the alert message box
*/
message = this.labels.get_label( "dialogs.edit_player.error_bad_configuration" );
}.bind(this)
});
} else { message = this.labels.get_label( "dialogs.edit_player.error_no_data" ); }
} else { message = this.labels.get_label( "dialogs.edit_player.error_no_data" ); }
}
if ( message != "" ) {
jQuery("#thirtxy_edit_player_dialog_message").html( " " + message + " ");
}
}.bind(this),
error: function ( error ){
return false;
}
});
}
thrixty.ManuallyLoadPlugins.ShortcodeGenerator.prototype.insert_player = function (){
var player_buttons = jQuery("[data-thrixty-insert-button-player]");
for (var i = 0; i < player_buttons.length; i++) {
player_buttons[i].onclick = function ( element ){
this.editor.selection.setContent("[thrixty-player id='"+ element.target.getAttribute("data-thrixty-insert-button-player") +"']");
this.overlay.hide();
this.frame_new.hide();
}.bind(this);
}
}
//******************** LAYOUTS ********************//
thrixty.ManuallyLoadPlugins.ShortcodeGenerator.prototype.generate_layout_dialog = function (){
var output = "";
jQuery.ajax({
url: ajaxurl,
type: "POST",
dataType: "json",
data: {
action: "thrixty_get_all_layouts"
},
success: function ( response ){
if ( response != 0 ) {
if ( response.success ) {
var all_layouts = response.data;
output += "";
for (var i = 0; i < all_layouts.length; i++) {
output += "";
output += "
";
output += "
"
output += "
"+ all_layouts[i].id +"
";
output += "
"+ all_layouts[i].name +"
";
output += "
"+ all_layouts[i].description +"
";
output += "
" + this.labels.get_label( "dialogs.insert_layout.pathsettings.button_edit" ) + "
";
output += "
";
output += "
";
output += "
";
output += "
";
output += "
";
output += "
";
output += "" + this.labels.get_label( "general.pathsettings.basepath" ) + " ";
output += "
";
output += "
";
output += " ";
output += "
";
output += "
";
output += "
";
output += "
";
output += "" + this.labels.get_label( "general.pathsettings.object_name" ) + " ";
output += "
";
output += "
";
output += " ";
output += "
";
output += "
";
output += "
";
output += "
";
output += "" + this.labels.get_label( "general.pathsettings.filelist_small" ) + " ";
output += "
";
output += "
";
output += " ";
output += "
";
output += "
";
output += "
";
output += "
";
output += "" + this.labels.get_label( "general.pathsettings.filelist_large" ) + " ";
output += "
";
output += "
";
output += " ";
output += "
";
output += "
";
output += "
";
output += "
";
output += "" + this.labels.get_label( "general.pathsettings.use_basepath" ) + " ";
output += "
";
output += "
";
output += "
";
output += " ";
output += "";
output += "
0
";
output += "
|
";
output += "
";
output += " ";
output += "
";
output += "
";
output += "
";
output += "
";
output += "Status Filelist small:";
output += "
";
output += "
";
output += " ";
output += "
";
output += "
";
output += "
";
output += "
";
output += "Status Filelist large:";
output += "
";
output += "
";
output += " ";
output += "
";
output += "
";
output += "
";
output += "
";
output += "
";
output += "
" + this.labels.get_label( "dialogs.insert_layout.insert_shortcode" ) + "
";
output += "
";
output += "
";
output += "
";
output += "
";
output += "
";
output += "
";
}
} else {
output = "Es sind keine Layouts vorhanden Layout anlegen ";
}
this.dialog_content.html( output );
/**
*
* Init the js library to check the entered path settings
*/
if ( typeof thrixty !== "undefined" ) {
var object = new thrixty.ManuallyLoadPlugins.Filepaths();
object.init();
}
/**
*
* Bind click events on the insert buttons
*/
this.insert_layout();
}
}.bind(this),
error: function ( error ){
return false;
}
});
}
thrixty.ManuallyLoadPlugins.ShortcodeGenerator.prototype.generate_layout_edit_dialog = function ( element ){
var id = element.getAttribute("data-thrixty-layout-preview");
var basepath = element.getAttribute("data-thrixty-preview-basepath");
var object_name = element.getAttribute("data-thrixty-preview-object-name");
var small_path = element.getAttribute("data-thrixty-preview-small-path");
var large_path = element.getAttribute("data-thrixty-preview-large-path");
var use_basepath = element.getAttribute("data-thrixty-preview-use-basepath");
var output = "";
/**
*
* Build the main html structure
*/
output += "";
output += "
"
output += "
" + this.labels.get_label( "dialogs.edit_layout.headline" ) + " ";
output += "";
output += "
"
output += "
";
output += "
";
output += "
";
output += "
";
output += "
";
output += " ";
output += "
";
output += "
";
output += "
"
output += "
";
output += "
";
output += "
";
output += "
";
this.frame_edit_layout.html(output);
/**
*
* Assign a click event to the close button
*/
jQuery("#thrixty_edit_dialog_layout").find(".close_button").on("click", function ( element ){
jQuery("#thrixty_edit_dialog_layout").hide();
this.overlay.hide();
}.bind(this));
/**
*
* Display the frame
*/
this.overlay.show();
this.frame_edit_layout.show();
/**
*
* Load the data via ajax request
*/
jQuery.ajax({
url: ajaxurl,
type: "POST",
async: false,
dataType: "json",
data: {
action: "thrixty_get_layout",
id: id,
basepath: basepath,
object_name: object_name,
small_path: small_path,
large_path: large_path,
use_basepath: use_basepath
},
success: function ( response ){
var data = "";
var iframe = "";
var change_paths = "";
var buttons = "";
var message = "";
if ( response != 0 ) {
if ( response.success ) {
var layout = response.data[0];
if ( layout != null ) {
/**
*
* Display the main data
*/
data += "";
data += "";
data += "
"+ layout.id +"
";
data += "
"+ layout.name +"
";
data += "
"+ layout.description +"
";
data += "
";
jQuery("#thrixty_edit_layout_dialog_data").html(data);
/**
*
* Display the controll buttons
*/
buttons += "";
jQuery("#thrixty_edit_layout_dialog_container").append(buttons);
/**
*
* Create container to edit the layouts path settings
* Display the container
*
* @src admin_url + ?page=thrixty_edit_layout&mode=edit&id=[layout_id]
*/
change_paths += " "
change_paths += "";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "" + this.labels.get_label( "general.pathsettings.basepath" ) + " ";
change_paths += "
";
change_paths += "
";
change_paths += " ";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "" + this.labels.get_label( "general.pathsettings.object_name" ) + " ";
change_paths += "
";
change_paths += "
";
change_paths += " ";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "" + this.labels.get_label( "general.pathsettings.filelist_small" ) + " ";
change_paths += "
";
change_paths += "
";
change_paths += " ";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "" + this.labels.get_label( "general.pathsettings.filelist_large" ) + " ";
change_paths += "
";
change_paths += "
";
change_paths += " ";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "" + this.labels.get_label( "general.pathsettings.use_basepath" ) + " ";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += " ";
change_paths += "";
change_paths += "
0
";
change_paths += "
|
";
change_paths += "
";
change_paths += " ";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "Status Filelist small:";
change_paths += "
";
change_paths += "
";
change_paths += " ";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "Status Filelist large:";
change_paths += "
";
change_paths += "
";
change_paths += " ";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "
" + this.labels.get_label( "dialogs.edit_layout.button_refresh_paths" ) + "
";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "
";
change_paths += "";
jQuery("#thrixty_edit_layout_dialog_container").append(change_paths);
/**
*
* Create a iframe to edit the layout settings
* Display the iframe
*
* @src admin_url + ?page=thrixty_edit_layout&mode=edit&id=[layout_id]
*/
iframe += " "
iframe += "";
iframe += "";
iframe += "
";
jQuery("#thrixty_edit_layout_dialog_container").append(iframe);
/**
*
* Check layout path settings
*/
jQuery.ajax({
url: layout.small_filelist_absolute_path,
async: false,
type: "POST",
success: function ( response ){},
error: function ( error ){
/**
*
* Display the alert message box
*/
message = this.labels.get_label( "dialogs.edit_layout.error_bad_configuration" );
}.bind(this)
});
/**
*
* Init the js library to check the entered path settings
*/
if ( typeof thrixty !== "undefined" ) {
var object = new thrixty.ManuallyLoadPlugins.Filepaths().init();
}
} else {
message = this.labels.get_label( "dialogs.edit_layout.error_no_data" );
}
} else {
message = this.labels.get_label( "dialogs.edit_layout.error_no_data" );
}
}
if ( message != "" ) {
jQuery("#thirtxy_edit_layout_dialog_message").html( " " + message + " " );
}
this.edit_layout();
}.bind(this),
error: function ( error ){
return false;
}
});
}
thrixty.ManuallyLoadPlugins.ShortcodeGenerator.prototype.edit_layout = function (){
var update_button = jQuery("[data-thrixty-edit-layout-update]");
update_button.bind("click", function (){
var id = update_button.attr("data-thrixty-edit-layout-update");
var basepath = jQuery("#thrixty_edit_layout_basepath").val();
var object_name = jQuery("#thrixty_edit_layout_object_name").val();
var small_path = jQuery("#thrixty_edit_layout_small_filelist").val();
var large_path = jQuery("#thrixty_edit_layout_large_filelist").val();
var use_basepath = ( jQuery("#thrixty_edit_layout_use_basepath").is(":checked") ? "on" : "off" );
var content = this.editor.getContent();
if ( content != null && content != "" ){
var regex = new RegExp("\\[thrixty\\-layout id=[\"|\']"+ id +"[\"|\'][^\\]]*\\]", "g");
var match;
while ((match = regex.exec(content)) !== null) {
if (match.index === regex.lastIndex) {
regex.lastIndex++;
}
var shortcode = "[thrixty-layout id='"+ id +"' basepath='"+ basepath +"' object_name='"+ object_name +"' small_path='"+ small_path +"' large_path='"+ large_path +"' use_basepath='"+ use_basepath +"']";
this.editor.setContent( content.replace(match[0], shortcode) );
this.overlay.hide();
this.frame_edit_layout.hide();
}
}
}.bind(this));
}
thrixty.ManuallyLoadPlugins.ShortcodeGenerator.prototype.insert_layout = function (){
var layout_buttons = jQuery("[data-thrixty-insert-layout-submit]");
for (var i = 0; i < layout_buttons.length; i++) {
layout_buttons[i].onclick = function ( element ){
var id = element.target.getAttribute("data-thrixty-insert-layout-submit");
if ( !isNaN(id) ) {
id = parseInt(id);
var container = jQuery("[data-thrixty-insert-layout='" + id + "']");
var basepath = container.find("[data-thrixty-insert-layout-basepath]").val();
var object_name = container.find("[data-thrixty-insert-layout-object-name]").val();
var small_path = container.find("[data-thrixty-insert-layout-filelist-small]").val();
var large_path = container.find("[data-thrixty-insert-layout-filelist-large]").val();
var use_basepath = ( container.find("[data-thrixty-insert-layout-use-basepath]").is(":checked") ? "on" : "off" );
this.editor.selection.setContent("[thrixty-layout id='"+ id +"' basepath='"+ basepath +"' object_name='"+ object_name +"' small_path='"+ small_path +"' large_path='"+ large_path +"' use_basepath='"+ use_basepath +"']");
}
this.overlay.hide();
this.frame_new.hide();
}.bind(this);
}
}
//******************** EVENTS ******************//
thrixty.ManuallyLoadPlugins.ShortcodeGenerator.prototype.assign_events = function (){
var iframe_element = tinymce.activeEditor.iframeElement;
var iframe_document = iframe_element.contentDocument || iframe_element.contentWindow.document;
var player_icons = iframe_document.querySelectorAll("img[data-thrixty-player-preview]");
var layout_icons = iframe_document.querySelectorAll("img[data-thrixty-layout-preview]");
for (var i = 0; i < player_icons.length; i++) {
player_icons[i].addEventListener("click", this.generate_player_edit_dialog.bind(this, player_icons[i].getAttribute("data-thrixty-player-preview")));
}
for (var i = 0; i < layout_icons.length; i++) {
layout_icons[i].addEventListener("click", this.generate_layout_edit_dialog.bind(this, layout_icons[i]));
}
}
document.addEventListener("DOMContentLoaded", function (){
var object = new thrixty.ManuallyLoadPlugins.ShortcodeGenerator();
object.init();
});
}