PluginProbe
MaxButtons – Create buttons / 7.11
MaxButtons – Create buttons v7.11
6.23 6.24 6.25 6.26 6.26.1 6.27 6.28 6.3 6.4 6.5 6.6 6.7 6.8 6.9 7.0 7.1 7.1.1 7.1.2 7.1.3 7.10 7.11 7.13 7.13.1 7.13.2 7.13.3 All 100 releases
maxbuttons / js / media_button.js

media_button.js in MaxButtons – Create buttons 7.11, at js/media_button.js

277 lines 7.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 // media buttons v2
2 jQuery(document).ready(function(jq) {
3 $ = jq;
4
5 maxMedia.prototype = {
6 parent: 'body',
7 is_active: false,
8 maxmodal: null,
9 maxajax: null,
10 callback: null,
11 useShortCodeOptions: true,
12 shortcodeData: null,
13 getPage: 1,
14 ajaxSuccessHandler: null,
15 };
16
17 function maxMedia() {
18
19 if (typeof window.maxFoundry.maxmodal !== 'object')
20 {
21 window.maxFoundry.maxmodal = new maxModal();
22 window.maxFoundry.maxmodal.init();
23 }
24 if (typeof window.maxFoundry.maxAjax !== 'object')
25 {
26
27 window.maxFoundry.maxAjax = new maxAjax();
28
29 window.maxFoundry.maxAjax.init();
30 }
31
32 this.maxmodal = window.maxFoundry.maxmodal;
33 this.maxajax = window.maxFoundry.maxAjax;
34 }
35
36
37 // here the vars go.
38 maxMedia.prototype.init = function(options)
39 {
40 if (typeof options !== 'undefined')
41 {
42 if (typeof options.callback !== 'undefined')
43 this.callback = options.callback || null;
44 // this.bar = options.requiredArg;
45 if (typeof options.useShortCodeOptions !== 'undefined')
46 this.useShortCodeOptions = options.useShortCodeOptions;
47 if (typeof options.parent !== 'undefined')
48 {
49 this.parent = options.parent;
50 }
51
52 }
53 this.ajaxSuccessHandler = $.proxy(this.putContent, this);
54 $(document).off('click','.pagination span, .pagination-links a', $.proxy(this.doPagination, this));
55 $(document).on('click','.pagination span, .pagination-links a', $.proxy(this.doPagination, this)); // should be more specific
56
57 $(document).off('media_button_content_buttons_load', $.proxy(this.hookButtonAction, this));
58 $(document).on('media_button_content_buttons_load', $.proxy(this.hookButtonAction, this));
59
60 $(document).off('media_button_content_shortcode_options', $.proxy(this.hookShortCodeAction, this));
61 $(document).on('media_button_content_shortcode_options', $.proxy(this.hookShortCodeAction, this));
62 }
63
64 maxMedia.prototype.openModal = function()
65 {
66 this.maxmodal.newModal('media-popup');
67
68 this.maxmodal.parent = this.parent;
69 this.maxmodal.setTitle(mbtrans.windowtitle);
70
71 this.maxmodal.setContent('<span class="loading"></span>');
72 this.maxmodal.show();
73
74 this.maxajax.showSpinner( $('.loading') );
75 this.loadButtons();
76
77 this.is_active = true;
78 }
79
80
81 maxMedia.prototype.loadButtons = function()
82 {
83
84 var data = this.maxajax.ajaxInit();
85 data['plugin_action'] = 'getAjaxButtons';
86 data['page'] = this.getPage;
87
88
89 this.maxajax.ajaxPost(data, this.ajaxSuccessHandler);
90 }
91
92 maxMedia.prototype.putContent = function(result)
93 {
94 var result = JSON.parse(result);
95 this.maxajax.removeSpinner();
96
97 if (typeof result.output !== 'undefined')
98 {
99 this.maxmodal.setContent(result.output);
100 }
101 if (typeof result.action !== 'undefined')
102 {
103 $(document).trigger('media_button_content_' + result.action, result);
104 }
105 }
106
107 maxMedia.prototype.hookButtonAction = function()
108 {
109 $(document).off('click', '.button-list');
110 $(document).on('click', '.button-list', $.proxy(function (e) // this selects the button, and enables / disabled the insert button based on that.
111 {
112 var target = $(e.target);
113
114 if ( typeof $(target).data('button') === 'undefined')
115 {
116 target = $(target).parents('.button-list');
117 }
118
119 var button = $(target).data('button');
120 $('.button-list').removeClass('selected');
121 $(target).addClass('selected');
122 $('.controls .button-primary').data('button', button);
123
124 this.maxmodal.currentModal.find('.controls .button-primary').removeClass('disabled');
125 },this));
126
127 $(document).off('click', ".button-preview a");
128 $(document).on('click', ".button-preview a", function(e) { e.preventDefault(); }); // prevent button clicks
129
130 this.maxmodal.resetControls();
131
132
133 if (this.useShortCodeOptions) // check if second window is required
134 this.maxmodal.addControl(mbtrans.use, '', $.proxy(this.shortCodeOptions, this) );
135 else
136 this.maxmodal.addControl(mbtrans.insert, '', $.proxy(this.selectAction, this) );
137
138 this.maxmodal.setControls();
139 this.maxmodal.currentModal.find('.controls .button-primary').addClass('disabled');
140
141 this.maxmodal.checkResize();
142
143 // this.hookPagination();
144
145 }
146
147 // load the shortcode options screen
148 maxMedia.prototype.hookShortCodeAction = function (e, result)
149 {
150
151 this.shortcodeData = result.shortcodeData;
152 var button_id = result.button_id;
153
154 this.maxmodal.resetControls();
155 this.maxmodal.addControl(mbtrans.insert, '', $.proxy(this.selectAction, this) );
156 this.maxmodal.setControls();
157
158 $(this.maxmodal.currentModal).find('.controls .button-primary').data('button', button_id);
159
160 $(this.maxmodal.currentModal).find('.more-options a').off('click');
161 $(this.maxmodal.currentModal).find('.more-options a').on('click', $.proxy(function (e) {
162 $(this.maxmodal.currentModal).find('.more-field').show();
163 $(e.target).parents('.option .more').hide();
164 this.maxmodal.checkResize();
165 }, this));
166
167 this.maxmodal.checkResize();
168
169 }
170
171 // action to select a button, and get button id.
172 maxMedia.prototype.selectAction = function(e)
173 {
174 e.preventDefault();
175 if ($(e.target).hasClass('disabled'))
176 return; // disabled buttons don't say yes.
177
178 var button_id = $(e.target).data('button');
179
180 if (typeof button_id === 'undefined' || parseInt(button_id) <= 0)
181 return; // no button yet.
182
183 if (typeof this.callback == 'function')
184 {
185 this.callback(button_id, $(e.target) );
186 }
187 else
188 {
189 this.buttonToEditor(button_id);
190 this.close();
191 }
192 }
193
194 // ajax query for shortcode options
195 maxMedia.prototype.shortCodeOptions = function (e)
196 {
197 e.preventDefault();
198 if ($(e.target).hasClass('disabled'))
199 return; // disabled buttons don't say yes.
200
201 var button_id = $(e.target).data('button');
202 var data = this.maxajax.ajaxInit();
203 data['plugin_action'] = 'mediaShortcodeOptions';
204 data['button_id'] = button_id;
205
206 this.maxajax.ajaxPost(data, this.ajaxSuccessHandler);
207 }
208
209
210
211 maxMedia.prototype.doPagination = function (e)
212 {
213 e.preventDefault();
214
215 if ( $(e.target).hasClass('disabled'))
216 return false;
217
218 var page = $(e.target).data('page');
219 if (page <= 1) page = 1;
220
221 this.getPage = page;
222 this.loadButtons();
223 }
224
225 // create the shortcode to send to the editor.
226 maxMedia.prototype.generateShortcode = function (button_id)
227 {
228 var shortcode = '[maxbutton id="' + button_id + '"';
229 if (typeof this.shortcodeData !== 'undefined')
230 {
231 $(this.shortcodeData).each(function(index, el){
232 var input = $('input[name="' + el.name + '"]');
233 var inputval = $('input[name="' + el.name + '"]').val();
234
235 if (input.attr('type') == 'checkbox')
236 {
237
238 var checked = input.is(':checked');
239
240 if (checked != el.original)
241 {
242 if (checked)
243 shortcode += ' ' + el.shortcode + '="' + el.checked + '"';
244 else
245 shortcode += ' ' + el.shortcode + '="' + el.unchecked + '"';
246 }
247 }
248 else if (inputval != el.original)
249 {
250 shortcode += ' ' + el.shortcode + '="' + inputval + '"';
251 }
252 });
253 }
254
255
256 shortcode += ' ] ';
257 return shortcode;
258 }
259
260 maxMedia.prototype.buttonToEditor = function (button_id)
261 {
262 shortcode = this.generateShortcode(button_id);
263 window.send_to_editor(shortcode, button_id);
264 }
265
266 maxMedia.prototype.close = function()
267 {
268 this.maxmodal.close();
269 }
270
271 if (typeof window.maxFoundry === 'undefined')
272 window.maxFoundry = {};
273
274 window.maxFoundry.maxMedia = maxMedia;
275
276 }); // jquery
277