PluginProbe
MaxButtons – Create buttons / 6.28
MaxButtons – Create buttons v6.28
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 / maxtabs.js

maxtabs.js in MaxButtons – Create buttons 6.28, at js/maxtabs.js

249 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 //var maxTabs;
2
3 jQuery(document).ready(function($) {
4
5 var maxTabs = function () {
6
7 }
8
9 maxTabs.prototype.init = function()
10 {
11 this.tabs();
12 this.previewTab();
13
14 }
15
16 maxTabs.prototype.tabs = function ()
17 {
18
19 var tabslocation = '.sub-tabs'; // tab area selector
20 var tabs = '.mb_tab'; //actual tabs
21 var main_parent = '#maxbuttons'; // the boss of the page, used for view selectors.
22
23 if ($(tabs).length === 0)
24 {
25 return; // no tabs
26 }
27
28 var view = $(main_parent).data('view');
29 if (typeof view == 'undefined')
30 view = 'list';
31
32
33 if (view == 'list')
34 {
35 return; // list view no tabs.
36 }
37
38
39 // start to do tabs.
40 $(main_parent).addClass('mb_tabs_active');
41
42 if ($(tabslocation).length === 0) // no placeholder, create
43 {
44 $tabslocation = $('<h2 class="nav-tab-wrapper sub-tabs"></h2>');
45 $tabslocation.insertBefore($(tabs).first());
46 $tabslocation = $(tabslocation);
47 }
48 else
49 $tabslocation = $(tabslocation);
50
51 $(tabs).hide();
52 $.each($(tabs), function ()
53 {
54 var titlediv = $(this).children('div.title').first();
55 var el = titlediv.clone(); //.text();
56
57
58
59 // extract icon from el
60 var icon = el.children('span:first').clone().wrap('<p>').parent().html();
61 // get title
62 var title = el.children('span.title').text();
63
64 // remove all spans to get title
65 $(el).children('span').remove();
66 $(el).children('input,button').remove(); // remove interface elements.
67
68 // remove tab information from the title
69 titlediv.children('span:first').remove();
70 titlediv.children('.title').remove();
71
72
73
74 if (typeof icon != 'undefined')
75 tab_title = icon + title;
76 else
77 tab_title = title;
78
79 var tab = $('<a class="nav-tab" href="javascript:void(0);">' + tab_title + '</a>');
80
81 title = title.trim();
82 title = title.replace(/ /g,"-");
83 $(tab).attr('data-tab', title.toLowerCase() );
84
85 $(tabslocation).append(tab);
86
87 $(this).attr('data-tab', title.toLowerCase());
88
89
90 });
91
92 // show first tab
93 var active_tab = $('input[name="tab"]').val();
94 if(typeof active_tab == 'undefined')
95 active_tab = '';
96
97 if (active_tab == '')
98 {
99 $tabslocation.children('.nav-tab').first().addClass('nav-tab-active');
100 $(tabs).first().show();
101 }
102 else
103 {
104 $tabslocation.children('[data-tab="' + active_tab + '"]').addClass('nav-tab-active');
105 $(tabs + '[data-tab="' + active_tab + '"]').show();
106 }
107
108 $tabslocation.children('a').on('click', this.toggleTabs);
109 this.addSaveTab($tabslocation);
110 }
111
112 maxTabs.prototype.addSaveTab = function ($tabslocation)
113 {
114 //var submitButton = $('input[type="submit"]').clone();
115 /*var submitText = submitButton = $('input[type="submit"]').attr('value');
116 var saveTab = $('<ul class="submit-tab"></ul>').append('<li><span class="dashicons dashicons-thumbs-up"></span> ' + submitText + '</li>');
117 $(document).on('click', '.submit-tab', function (e) {
118 $(e.target).parents('form').submit();
119 }); */
120
121 var saveTab = '<div class="save-indicator dashicons dashicons-warning"></div>';
122 $tabslocation.append(saveTab);
123
124 }
125
126 maxTabs.prototype.toggleTabs = function (e)
127 {
128 e.preventDefault();
129 var tabslocation = '.sub-tabs'; // tab area selector
130 var tabs = '.mb_tab'; //actual tabs
131
132 $(tabslocation).children('a').removeClass('nav-tab-active');
133 $(this).addClass('nav-tab-active');
134
135 $(tabs).hide();
136
137 var tab = $(this).data('tab');
138
139 $(tabs + '[data-tab="' + tab + '"]').show();
140 $('input[name="tab"]').val(tab);
141
142
143 $(document).trigger('maxTabChange', [ tab ]);
144
145 }
146
147 maxTabs.prototype.previewTab = function ()
148 {
149 var isVisible = $('.mb-preview-window').is(':visible');
150 var tabslocation = '.sub-tabs';
151
152 var previewtab = tabslocation + ' a[data-tab="preview"]';
153
154 // init
155 this.togglePreview();
156
157 $(previewtab).off('click'); // overrule
158
159 $(document).on('click',previewtab, $.proxy(function (e) {
160 e.preventDefault();
161 e.stopPropagation();
162
163
164 //var previewtab = e.data["previewtab"];
165 var isVisible = $('.mb-preview-window').is(':visible');
166
167 if (isVisible)
168 {
169 this.togglePreview(false);
170
171 } else
172 {
173 this.togglePreview(true);
174 }
175
176 $(document).trigger('updatePreviewWindow'); // fix sizes
177 return false;
178
179 }, this));
180
181 $('.mb-preview-window .close').on('click', {tab: previewtab }, function (e) {
182 $(e.data.tab).trigger('click');
183
184 });
185
186 }
187
188 maxTabs.prototype.togglePreview = function(show) {
189
190 var tabslocation = '.sub-tabs';
191 var previewtab = tabslocation + ' a[data-tab="preview"]';
192
193 if (typeof show == 'undefined')
194 {
195 // no preference, check localStorage
196 if(!localStorage.getItem('mb-col-preview')) {
197 this.togglePreview(true);
198
199 }
200 else
201 {
202 var preview = localStorage.getItem('mb-col-preview');
203
204 if (typeof preview == 'string') // convert
205 {
206 if (preview == 'true')
207 preview = true;
208 else
209 preview = false;
210 }
211 if (typeof preview == 'boolean')
212 {
213 this.togglePreview(preview);
214 }
215
216 }
217
218 }
219 else if (show)
220 {
221
222 $('.mb-preview-window').show();
223 $(previewtab).addClass(' preview-on');
224 $(previewtab + ' .dashicons').addClass("dashicons-yes").removeClass('dashicons-no');
225 $(previewtab).removeClass('preview-off');
226 localStorage.setItem('mb-col-preview', true);
227
228 }
229 else
230 {
231 $('.mb-preview-window').hide();
232 $(previewtab).removeClass("preview-on");
233 $(previewtab + ' .dashicons').removeClass('dashicons-yes').addClass('dashicons-no');
234
235 //$(previewtab).css('backgroundColor','#fff');
236 $(previewtab).addClass('preview-off');
237 localStorage.setItem('mb-col-preview', false);
238 }
239
240 }
241
242
243
244 var mt = new maxTabs();
245 mt.init();
246
247 }); /* END OF JQUERY */
248
249