String.prototype.format = function() { var formatted = this; for (var i = 0; i < arguments.length; i++) { var regexp = new RegExp('\\{'+i+'\\}', 'gi'); formatted = formatted.replace(regexp, arguments[i]); } return formatted; }; ;(function($) { $.in_array = function(v, a) { r = $.inArray(v,a); if(r > -1) return true; if(r == -1) return false; }; window.dialog_ui; dialog_ui = { needsPreview: false, // init routine init: function() { var d = this; d.setup_buttons(); d.load_shortcode_details(); d.setup_select(); }, // setup buttons and there actions setup_buttons: function () { var d = this; $("#spyropress-btn-cancel").click(function () { d.close_dialog(); }); $("#spyropress-btn-insert").click(function () { d.insert_action(); }); $("#spyropress-btn-preview").click(function () { d.preview_action(); }); }, close_dialog: function () { this.needsPreview = false; tb_remove(); $("#spyropress-dialog").remove() }, insert_action: function () { if (typeof spyropressShortcodeMeta != "undefined") { var a = this.makeShortcode('insert'); tinyMCE.activeEditor.execCommand("mceInsertContent", false, a); this.close_dialog() } }, preview_action: function (a) { $("#spyropress-preview h3:first").addClass("spyropress-loading"); $("#spyropress-preview-iframe").attr("src", spyropress_admin_settings['shortcode_url']+"preview-shortcode-external.php?shortcode=" + encodeURIComponent(this.makeShortcode('preview'))); }, // setup chosen setup_select: function() { var d = this; var t = setTimeout(function(){ $('.chosen', '#spyropress-shortcode-gen').delay(800).chosen({ allow_single_deselect: true }).change(function(){ d.preview_action(); }); }, 500); }, // load shortcode details load_shortcode_details: function () { if (spyropressSelectedShortcodeType) { var d = this; $.getScript(spyropress_admin_settings['shortcode_url']+"sc/" + spyropressSelectedShortcodeType + ".js", function () { d.initializeDialog() }); } }, initializeDialog: function () { if (typeof spyropressShortcodeMeta == "undefined") $("#spyropress-shortcode-gen").append("

Error loading details for shortcode: " + spyropressSelectedShortcodeType + "

"); else { if (spyropressShortcodeMeta.disablePreview) { $("#spyropress-btn-preview").remove(); $("#spyropress-preview-iframe").remove(); $('.sc-head', "#spyropress-preview").remove(); } preview = $('#spyropress-preview'); $('#TB_ajaxContent').scroll(function(e){ var scrollAmount = $(this).scrollTop(); var newPosition = 90+scrollAmount; preview.stop().animate({top: newPosition}, 1000, 'linear'); }); var a = spyropressShortcodeMeta.attributes, b = $("#spyropress-shortcode-gen"); for (var c in a) { var type = a[c].type, id = a[c].id; // create section var section = $('
', { class: 'section section-full section-'+a[c].type, //id: 'section-'+a[c].id }); // add extra class if (a[c].target != null && a[c].target == 'font-awesome') section.addClass('section-fontawesome'); // create title title = $('

', { class: 'heading' }).text(a[c].name); if ( a[c].isRequired ) title.append('*'); section.append(title); // create control div control = $( '
', { class: 'controls' } ); // generate control switch (type) { case 'text': this.create_text( a[c], control, id ); break; case 'upload': this.create_upload( a[c], control, id ); break; case 'textarea': this.create_textarea( a[c], control, id ); break; case 'checkbox': this.create_checkbox( a[c], control, id ); break; case 'multi_checkbox': this.create_multi_checkbox( a[c], control, id ); break; case 'radio': this.create_radio( a[c], control, id ); break; case 'select': this.create_select( a[c], control, id ); break; case 'multi_select': this.create_multi_select( a[c], control, id ); break; case 'range_slider': this.create_range_slider( a[c], control, id ); break; case 'colorpicker': this.create_color_picker( a[c], control, id ); break; } control.append('
'); section.append(control); // create desc if ( a[c].desc ) { desc = $( '
', { class: 'description' } ); desc.html(a[c].desc); section.append(desc) } section.append('
').appendTo(b); } } }, create_text: function ( attr, control, id ) { var d = this, elem = $('', { type: 'text', name: id, id: id, class: 'field' }); if(attr.isRequired) elem.addClass('required'); if(attr.placeholder) elem.attr('placeholder',attr.placeholder); if(attr.std) elem.attr('value',attr.std); control.append(elem); if (attr.bind != null) elem.bind("keydown focusout", attr.bind); else { control.find("#" + id).bind("keydown focusout", function (e) { if (e.type == "keydown" && e.which != 13 && e.which != 9 && !e.shiftKey) d.needsPreview = true; else if (d.needsPreview && (e.type == "focusout" || e.which == 13)) { d.preview_action(e.target); d.needsPreview = false } }); } }, create_upload: function ( attr, control, id ) { var d = this, div = $('
'), elem = $('', { type: 'text', name: id, id: id, class: 'field upload' }); btn = $(''); if(attr.isRequired) elem.addClass('required'); div.append(elem); div.append(btn); control.append(div); if (attr.bind != null) elem.bind("keydown focusout", attr.bind); else { control.find("#" + id).bind("keydown focusout", function (e) { if (e.type == "keydown" && e.which != 13 && e.which != 9 && !e.shiftKey) d.needsPreview = true; else if (d.needsPreview && (e.type == "focusout" || e.which == 13)) { d.preview_action(e.target); d.needsPreview = false } }); } }, create_textarea: function ( attr, control, id ) { var d = this, elem = $('