PluginProbe
WP Ultimate Post Grid / 1.7.2
WP Ultimate Post Grid v1.7.2
4.1.1 trunk 1.5 1.6 1.7 1.7.1 1.7.2 1.8 1.9 2.0 2.1 2.2 2.3 2.4.0 2.5.0 2.6.0 2.7.0 2.8.0 2.8.2 3.0.0 3.3.0 3.4.0 3.5.0 3.6.0 3.7.0 All 32 releases
wp-ultimate-post-grid / vendor / vafpress / public / js / shortcode-menu.js

shortcode-menu.js in WP Ultimate Post Grid 1.7.2, at vendor/vafpress/public/js/shortcode-menu.js

234 lines 6.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function($){
2 $(document).ready(function(){
3 if(!jQuery.fn.insertAtCaret)
4 {
5 jQuery.fn.insertAtCaret = function(text) {
6 return this.each(function() {
7 if (document.selection && this.tagName == 'TEXTAREA') {
8 //IE textarea support
9 this.focus();
10 sel = document.selection.createRange();
11 sel.text = text;
12 this.focus();
13 } else if (this.selectionStart || this.selectionStart == '0') {
14 //MOZILLA/NETSCAPE support
15 startPos = this.selectionStart;
16 endPos = this.selectionEnd;
17 scrollTop = this.scrollTop;
18 this.value = this.value.substring(0, startPos) + text + this.value.substring(endPos, this.value.length);
19 this.focus();
20 this.selectionStart = startPos + text.length;
21 this.selectionEnd = startPos + text.length;
22 this.scrollTop = scrollTop;
23 } else {
24 // IE input[type=text] and other browsers
25 this.value += text;
26 this.focus();
27 this.value = this.value;
28 }
29 });
30 };
31 }
32
33 var decodeEntities = (function() {
34 // this prevents any overhead from creating the object each time
35 var element = document.createElement('div');
36
37 function decodeHTMLEntities (str) {
38 if(str && typeof str === 'string') {
39 // strip script/html tags
40 str = str.replace(/<script[^>]*>([\S\s]*?)<\/script>/gmi, '');
41 str = str.replace(/<\/?\w(?:[^"'>]|"[^"]*"|'[^']*')*>/gmi, '');
42 element.innerHTML = str;
43 str = element.textContent;
44 element.textContent = '';
45 }
46
47 return str;
48 }
49
50 return decodeHTMLEntities;
51 })();
52
53 jQuery.fn.scReset = function(){
54 if( $(this).is('form') )
55 $(this)[0].reset();
56
57 $(this).find('.vp-sc-field').each(function(i){
58 var type = $(this).attr('data-vp-type');
59 switch (type)
60 {
61 case 'vp-upload':
62 $(this).find('.image > img').attr('src', '');
63 break;
64 case 'vp-color':
65 $(this).find('.vp-js-colorpicker').colorpicker('update', '');
66 break;
67 case 'vp-slider':
68 var val = $(this).find('input').val();
69 var $slider = $(this).find('.vp-js-slider');
70 if(!val)
71 {
72 val = $(this).find('.vp-js-slider').slider('option', 'min');
73 }
74 $slider.slider('value', val);
75 break;
76 case 'vp-textarea':
77 $(this).find('textarea').val($(this).find('textarea').text());
78 break;
79 case 'vp-checkimage':
80 // trigger change since form reset doesn't trigger it
81 $(this).find('input').change();
82 break;
83 case 'vp-radioimage':
84 // trigger change since form reset doesn't trigger it
85 $(this).find('input').change();
86 break;
87 case 'vp-codeeditor':
88 $(this).find('textarea').first().val($(this).find('textarea').text()).change();
89 break;
90 }
91 });
92
93 if ($.fn.select2)
94 {
95 // re-init select2
96 $(this).find('.vp-js-select2').select2("destroy");
97 // re-init select2 sortable
98 if ($.fn.select2Sortable) $(this).find('.vp-js-sorter').select2("destroy");
99 // re-init select2 fontawesome
100 $(this).find('.vp-js-fontawesome').select2("destroy");
101
102 vp.init_fontawesome_chooser($(this).find('.vp-js-fontawesome'));
103 vp.init_select2($(this).find('.vp-js-select2'));
104 vp.init_sorter($(this).find('.vp-js-sorter'));
105 }
106 return $(this);
107 };
108
109 // init controls
110 vp.init_controls($('.vp-sc-main'));
111
112 // shortcode image controls event bind
113 vp.custom_check_radio_event(".vp-sc-dialog", ".vp-checkimage .field .input label");
114 vp.custom_check_radio_event(".vp-sc-dialog", ".vp-radioimage .field .input label");
115
116 $('.vp-sc-menu li a').on('click', function(ev){
117 ev.preventDefault();
118
119 var $modal = $(this).parents('.vp-sc-dialog'),
120 $parent = $(this).parent('li'),
121 targetId = $(this).attr('href').substring(1),
122 $target = $modal.find('.vp-sc-sub-menu-' + targetId);
123
124 // set clicked menu item as current
125 $parent.siblings().removeClass('current');
126 $parent.addClass('current');
127
128 // show menu content
129 $target.siblings().addClass('vp-hide');
130 $target.removeClass('vp-hide');
131
132 // stop event propagation
133 return false;
134 });
135
136 $('.vp-sc-element .vp-sc-element-heading').unbind();
137 $('.vp-sc-element .vp-sc-element-heading a').bind('click.vp_sc', function(e){
138 e.preventDefault();
139
140 var $parent = $(this).parents('li'),
141 id = $parent.attr('id'),
142 $form = $parent.find('.vp-sc-element-form').first();
143
144 if($parent.hasClass('active'))
145 {
146 $form.vp_slideUp();
147 $form.scReset();
148 $parent.removeClass('active');
149 }
150 else
151 {
152 var code = $parent.find('.vp-sc-code').first().html(),
153 $modal = $(this).parents('.vp-sc-dialog').first();
154
155 $modal.find('.vp-sc-element').removeClass('active');
156 $modal.find('.vp-sc-element-form').vp_slideUp();
157
158 if($form.exists())
159 {
160 $parent.addClass('active');
161 $form.vp_slideDown();
162 }
163 else
164 {
165 code = decodeEntities(code);
166 $modal.trigger('vp_insert_shortcode', code);
167 $modal.trigger('reveal:close');
168 }
169 }
170 });
171
172 $('.vp-sc-insert').bind('click.vp_sc_insert', function(e){
173 e.preventDefault();
174 var $modal = $(this).parents('.vp-sc-dialog'),
175 $parent = $(this).parents('.vp-sc-element'),
176 $form = $(this).parents('.vp-sc-element-form'),
177 $fields = $form.find('.vp-sc-field'),
178 values = {},
179 code = $parent.find('.vp-sc-code').first().html(),
180 atts = '';
181
182 // trigger non reloading form submit, so that any event binded on this called
183 $form.on('submit', function(e){vp.tinyMCE_save(); e.preventDefault();});
184 $form.submit();
185
186 // gather unique names of the options
187 $fields.each(function(i){
188 var $input = $(this).find(':not(div).vp-input'),
189 name = $input.attr('name'),
190 val = $input.validationVal(),
191 type = $(this).attr('data-vp-type');
192
193 if(type === 'vp-toggle')
194 {
195 if(val) val = 'true';
196 else val = 'false';
197 }
198
199 if(val && val !== '')
200 {
201 values[name.substring(1)] = val;
202 }
203 });
204
205 for (var name in values)
206 {
207 if(values.hasOwnProperty(name))
208 {
209 atts += (" " + name + '="' + values[name] + '"');
210 }
211 }
212
213 // print shortcode to editor
214 code = code.replace(']', atts + ']');
215 code = decodeEntities(code);
216 $modal.trigger('vp_insert_shortcode', code);
217
218 // reset form and close dialog
219 $('.vp-sc-element').removeClass('active');
220 $form.vp_slideUp();
221 $form.scReset();
222 $modal.trigger('reveal:close');
223 });
224
225 $('.vp-sc-cancel').bind('click.vp_sc_cancel', function(e){
226 e.preventDefault();
227 $('.vp-sc-element').removeClass('active');
228 var $form = $(this).parents('.vp-sc-element-form')
229 $form.vp_slideUp();
230 $form.scReset();
231 });
232
233 });
234 })(jQuery);