PluginProbe
MaxButtons – Create buttons / 7.1.2
MaxButtons – Create buttons v7.1.2
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 7.1.2, at js/maxtabs.js

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