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 = $('', { type: 'text', name: id, id: id, rows: 6, class: 'field' }); if(attr.isRequired) elem.addClass('required'); if(attr.placeholder) elem.attr('placeholder',attr.placeholder); if(attr.std) elem.html(attr.std); control.append(elem); control.find("#" + id).live("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_checkbox: function ( attr, control, id ) { var d = this, elem = $('', { type: 'checkbox', name: id, id: id, value: 1 }), label = $('', { for: id, class: 'checkbox' }); if(attr.isRequired) elem.addClass('required'); if(attr.std && attr.std == 1) elem.attr('checked','checked'); label.append(elem).append(attr.label); control.append(label); control.find("#" + id).live("change focusout", function (e) { if (e.type == "change" || e.type == "focusout") { d.preview_action(e.target); d.needsPreview = false } }); }, create_multi_checkbox: function ( attr, control, id ) { var d = this; for (var c in attr.options) { m_id = id + '_' + attr.options[c].value; elem = $('', { type: 'checkbox', name: id+'['+c+']', id: m_id, value: attr.options[c].value }); label = $('', { for: m_id, class: 'checkbox' }); if(attr.std && attr.std[c] == 1) elem.attr('checked','checked'); label.append(elem).append(attr.options[c].label); control.append(label); control.find("#" + m_id).live("change focusout", function (e) { if (e.type == "change" || e.type == "focusout") { d.preview_action(e.target); d.needsPreview = false } }); } }, create_radio: function ( attr, control, id ) { var d = this; // if any target merge options if (attr.target != null) { if (attr.options == null) attr.options = []; $.extend(attr.options, this.get_target_options(attr.target)); } for (var c in attr.options) { m_id = id + '_' + attr.options[c].value; elem = $('', { type: 'radio', name: id, id: m_id, value: attr.options[c].value }); label = $('', { for: m_id, class: 'checkbox' }); if(attr.std && attr.std[c] == attr.options[c].value) elem.attr('checked','checked'); label.append(elem).append(attr.options[c].label); control.append(label); label.click(function(){ d.preview_action(); d.needsPreview = false; }); control.find("#" + m_id).live("change focusout", function (e) { d.preview_action(); d.needsPreview = false; }); } }, create_select: function ( attr, control, id ) { var d = this, elem = $('', { class: 'chosen', name: id, id: id }); if( attr.isRequired) elem.addClass('required'); // append empty option elem.append(''); // if any target merge options if (attr.target != null) { if (attr.options == null) { attr.options = []; $.extend(attr.options, d.get_target_options(attr.target)); } else { $.merge(attr.options,d.get_target_options(attr.target)); } } for (var c in attr.options) { d.render_option(elem, attr.options[c].value, attr.options[c].label, attr.options[c].name, attr.std); } if (attr.onchange != null) elem.change(attr.onchange); control.append(elem); }, create_multi_select: function ( attr, control, id ) { var d = this, elem = $('', { class: 'chosen', name: id+'[]', id: id, multiple: 'multiple' }); if( attr.isRequired) elem.addClass('required'); // append empty option elem.append(''); // if any target merge options if (attr.target != null) { if (attr.options == null) attr.options = []; $.extend(attr.options, this.get_target_options(attr.target)); } for (var c in attr.options) { d.render_option(elem, attr.options[c].value, attr.options[c].label, attr.options[c].name, attr.std); } control.append(elem); }, render_option: function(elem, k, v, name, selected) { var d = this; k = (k.length) ? k : v.toLowerCase(); if( $.isArray(v)) { group = $('', { label: name }); if( !$.isEmptyObject(v) ) { for (var c in v) d.render_option(group, v[c].value, v[c].label, name, selected); } elem.append(group); } else { elem.append(''.format( k, ($.in_array(k, selected)) ? ' selected="selected"' : '', v)); } }, create_range_slider: function ( attr, control, id ) { var d = this, rs = $('', { class: 'range-slider'}), rs_div = $('', { class: 'slider', id: id }), rs_inp = $('', { type: 'text', name: id, id: id+'_field', class: 'field'}); if(attr.value != null) rs_inp.val(attr.value); // settings settings = { animate: true, range: 'min', slide: function( event, ui ) { $(this).next('input').val( ui.value ); }, change: function() { d.preview_action(id); } }; $.extend( settings, attr ); rs_div.slider(settings); rs.append(rs_div); rs.append(rs_inp); rs.append(''); control.append(rs); }, create_color_picker: function ( attr, control, id ) { var d = this, cp = $('', { class: 'color-picker'}), cp_div = $('