PluginProbe
Social Share Buttons / 1.4
Social Share Buttons v1.4
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 / network-editor.js

network-editor.js in Social Share Buttons 1.4, at js/network-editor.js

169 lines 4.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1
2 jQuery(document).ready(function($) {
3
4 mbsEditor = function ()
5 {
6
7 }
8
9 mbsEditor.prototype.init = function ()
10 {
11 $(document).on('maxajax_success_network-settings', $.proxy(this.showSettings, this) );
12 $(document).on('maxajax_success_save-network', $.proxy(this.settingsUpdated, this) );
13 $(document).on('maxajax_success_remove-networksettings', $.proxy(this.settingsUpdated, this));
14 $(document).on('maxajax_success_show-customnetworks', $.proxy(this.showCustomNetworks, this));
15
16 $(document).on('maxajax_success_import-customnetworks', $.proxy(this.networksImported, this));
17
18 }
19
20 mbsEditor.prototype.showSettings = function(e, result, status)
21 {
22 result = JSON.parse(result);
23
24 if (result.output)
25 {
26 $('.network_editor .inside').html(result.output);
27 if (result.title)
28 {
29 $('.network_editor .title').html(result.title);
30 }
31 }
32
33 this.doColorPicker();
34 }
35
36 mbsEditor.prototype.doColorPicker = function()
37 {
38 colorPalette = (mbpro_options.colorPalette !== '' ? mbpro_options.colorPalette : true);
39
40 // colors
41 $('.maxbuttons-social .network_editor .color-field').wpColorPicker(
42 {
43 width: 300,
44 palettes: colorPalette,
45 change: $.proxy( _.throttle(function(event, ui) {
46 event.preventDefault();
47 var target = $(event.target);
48 var color = ui.color.toString();
49
50 if (color.indexOf('#') === -1)
51 color = '#' + color;
52
53 var id = target.attr('id');
54 $('#' + id).val(color).trigger('change');
55
56 }, 200), this),
57 }
58 );
59 }
60
61 mbsEditor.prototype.showCustomNetworks = function (e, result, status)
62 {
63 var result = JSON.parse(result);
64 if (result.status == 'error')
65 {
66 $('.network_editor .inside').html('<h4 class="load-error">' + result.message + '</h4>');
67 }
68 else {
69 $('.network_editor .inside').html(result.output);
70
71 if (result.title)
72 {
73 $('.network_editor .title').html(result.title);
74 }
75 $('.network_editor ul li').off();
76 $('.network_editor ul li').on('click', $.proxy(this.toggleCustom, this));
77
78 }
79 }
80
81 mbsEditor.prototype.networksImported = function (e, result)
82 {
83
84 this.notifySaved(e, result);
85 window.location.reload(true);
86 }
87
88 mbsEditor.prototype.toggleCustom = function (e)
89 {
90 var target = $(e.target);
91 if (! $(target).hasClass('the_network'))
92 {
93 target = $(target).parents('.the_network');
94 }
95
96 if ( $(target).hasClass('selected'))
97 {
98 $(target).removeClass('selected');
99 }
100 else {
101 $(target).addClass('selected');
102 }
103
104 var selected = $('.network_editor ul li.selected');
105 var count = $(selected).length;
106
107 $('.cns-toolbar .selected').html(count);
108
109 if (count > 0)
110 {
111 $('.cns-toolbar button').prop('disabled', false);
112 }
113 else {
114 $('.cns-toolbar button').prop('disabled', true);
115 }
116
117 var networks = [];
118 $(selected).each(function()
119 {
120 networks.push($(this).data('network'));
121
122 })
123 $('#selected_custom').val(networks.join(','));
124
125 }
126
127 mbsEditor.prototype.settingsUpdated = function(e, result, status)
128 {
129 if (typeof result !== 'object')
130 var result = JSON.parse(result);
131
132 if (result.output)
133 {
134 $('.network_editor .inside').html(result.output);
135 this.doColorPicker();
136 }
137
138 this.notifySaved(e, result, status);
139
140 if (result.reload)
141 {
142 window.location.reload(true);
143 }
144 }
145
146 mbsEditor.prototype.notifySaved = function(e,result,status)
147 {
148
149 if (typeof result !== 'object')
150 var result = JSON.parse(result);
151 var modal = window.maxFoundry.maxmodal;
152
153 modal.newModal('save_done');
154 modal.setTitle(result.title);
155 modal.setContent('');
156 modal.show();
157
158 this.form_updated = false; // set updated to false
159 window.maxFoundry.maxSocial.form_updated = false;
160 window.setTimeout( function () { modal.fadeOut(); }, 1000);
161 }
162
163 if (typeof window.maxFoundry === 'undefined')
164 window.maxFoundry = {};
165
166 window.maxFoundry.maxSocialSettings = new mbsEditor();
167 window.maxFoundry.maxSocialSettings.init();
168 }); // jquery
169