PluginProbe
Social Share Buttons / 1.8
Social Share Buttons v1.8
trunk 0.9 1.0 1.1 1.1.1 1.1.2 1.10 1.11 1.12 1.15 1.16 1.17 1.18 1.19 1.2 1.20 1.3 1.30 1.4 1.5 1.6 1.7 1.8 1.9
share-button / js / maxbuttons-custom.js

maxbuttons-custom.js in Social Share Buttons 1.8, at js/maxbuttons-custom.js

185 lines 5.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 jQuery(document).ready(function(jq) {
3 $ = jq;
4
5 var MBCustom = function() {
6 $(document).off('click', '#networkBlock .item .config_button button');
7 $(document).on('click', '#networkBlock .item .config_button button', $.proxy(this.openMBCustomModal, this) );
8 }
9
10 MBCustom.prototype = {
11 share_mm: new window.maxFoundry.maxMedia,
12 custom_target: '',
13 clone: null,
14 option_index: 0,
15 };
16
17 /** Function to open MB Custom selection modal, for custom buttons **/
18 MBCustom.prototype.openMBCustomModal = function (e)
19 {
20 this.custom_target = $(e.target).parents('.item');
21 var self = this;
22
23 this.createSettings();
24 this.share_mm.init({callback: $.proxy(this.selectMBCustomButton,this), useShortCodeOptions: true, parent: '#maxbuttons'});
25
26 // init off the events.
27 $(document).on('media_button_content_buttons_load', $.proxy(this.checkButtonConfig, this) );
28 $(document).on('media_button_content_shortcode_options', $.proxy(this.shortcodeOptions, this) );
29
30 this.share_mm.openModal();
31 }
32
33 MBCustom.prototype.checkButtonConfig = function (result)
34 {
35 var button_id = $(this.clone).find('input[name="mbcustom_id[' + this.option_index +']"]').val();
36 if (! isNaN(button_id) && button_id > 0)
37 {
38 // Button present: fake event, order next page.
39 var event = {}; // { target: $('<div data-button="' + button_id + '">') }
40 event.target = $('<div data-button="' + button_id + '">');
41 event.preventDefault = function () {};
42
43 this.share_mm.shortCodeOptions(event);
44 }
45
46 }
47
48 // clone and index custom settings | more to other index due to unique ID issues.
49 MBCustom.prototype.createSettings = function()
50 {
51 this.option_index = $(this.custom_target).find('input[name="mbcustom_index[]"]').val();
52 var options = $(this.custom_target).find('.mbcustom-options');
53
54 if (options.length > 0)
55 {
56 this.clone = $(options).clone();
57
58 // redo some problem fields
59 var option = $(options).find('select[name="mbcustom_network[' + this.option_index + ']"]').val();
60 $(this.clone).find('select[name="mbcustom_network[' + this.option_index + ']"]').val(option);
61
62 }
63 else
64 { // if no options present, add options to a new index to prevent overwrite
65 var nextdex = 0;
66 $('input[name="mbcustom_index[]"]').each(function()
67 {
68 if ($(this).val() > nextdex)
69 nextdex = $(this).val();
70 }); // find next index
71 nextdex++;
72
73 this.clone = $('.mbcustom-helper .mbcustom-options').clone();
74
75 // put next index at clone
76 $(this.clone).find('input, select, label').each(function() {
77
78 if (typeof $(this).attr('name') !== 'undefined')
79 $(this).attr('name', $(this).attr('name').replace(/-1/i, nextdex));
80
81 if (typeof $(this).attr('id') !== 'undefined')
82 $(this).attr('id', $(this).attr('id').replace(/-1/i, nextdex));
83
84 if (typeof $(this).attr('for') !== 'undefined')
85 $(this).attr('for', $(this).attr('for').replace(/-1/i, nextdex));
86 });
87
88 $(this.clone).find('input[name="mbcustom_index[]"]').val(nextdex); // put index on the counter
89 this.option_index = nextdex;
90
91 }
92
93 var the_switch = $(this.clone).find('.switch_button');
94 $(the_switch).find('label').attr('for', 'mbcustom_usenetwork_active');
95 $(the_switch).find('input').attr('id', 'mbcustom_usenetwork_active');
96
97
98 }
99
100 MBCustom.prototype.shortcodeOptions = function(event, result)
101 {
102
103 var button_id = result.button_id;
104 $(this.clone).find('input[name="mbcustom_id[' + this.option_index +']"]').val(button_id);
105
106 var index = $(this.custom_target).find('input[name="mbcustom_index[]"]').val();
107 var modal = this.share_mm.maxmodal;
108
109 // get setting from options
110 var url = $(this.clone).find('input[name="mbcustom_url[' + this.option_index + ']"]').val();
111 var text = $(this.clone).find('input[name="mbcustom_text[' + this.option_index + ']"]').val();
112
113 // put settings in interface
114 $(modal.currentModal).find('input[name="shortcode_url"]').val(url);
115 $(modal.currentModal).find('input[name="shortcode_text"]').val(text);
116
117 // hide not supported stuff
118 $(modal.currentModal).find('.shortcode_text2,.option.more').hide();
119
120 }
121
122 // Select shortcode window, add MB Custom specific fields
123 MBCustom.prototype.selectMBCustomButton = function (button_id, event)
124 {
125 options = (typeof options !== 'undefined') ? options : false;
126 var modal = this.share_mm.maxmodal; // find modal
127
128 // get settings from modal
129 var url = $(modal.currentModal).find('input[name="shortcode_url"]').val();
130 var text = $(modal.currentModal).find('input[name="shortcode_text"]').val();
131
132 // find these settings and write them to the options.
133 $(this.clone).find('input[name="mbcustom_url[' + this.option_index +']"]').val(url);
134 $(this.clone).find('input[name="mbcustom_text[' + this.option_index +']"]').val(text);
135
136 modal.resetControls();
137 modal.addControl(mbtrans.insert, '', $.proxy(this.putMBCustomOptions, this) );
138
139 this.clone.removeClass('hidden');
140 modal.setContent(this.clone); // insert the fields
141 modal.setControls();
142
143 modal.checkResize();
144
145 }
146
147 // Write back custom options to the main editor
148 MBCustom.prototype.putMBCustomOptions = function(event)
149 {
150 var modal = this.share_mm.maxmodal;
151
152 // find the options in the modal
153 var options = $(modal.currentModal).find('.mbcustom-options');
154 var the_switch = $(options).find('.switch_button'); // move back ID
155 $(the_switch).find('label').attr('for', 'mbcustom_usenetwork_' + this.option_index);
156 $(the_switch).find('input').attr('id', 'mbcustom_usenetwork_' + this.option_index);
157
158 if (options.length > 0)
159 {
160 $(options).addClass('hidden');
161 if ($(this.custom_target).find('.mbcustom-options').length > 0)
162 $(this.custom_target).find('.mbcustom-options').replaceWith(options);
163 else {
164 $(this.custom_target).append(options); // new entries
165 }
166 }
167 else {
168
169 }
170
171 $('#network_trigger_change').trigger('change');
172 this.share_mm.close();
173
174 }
175
176
177
178 if (typeof window.maxFoundry === 'undefined')
179 window.maxFoundry = {};
180
181 window.maxFoundry.MBCustom = new MBCustom();
182
183
184 });
185