https://www4.ti.ch/typo3conf/ext/theme/Resources/Public/Extensions…/Powermail/Tabs.min.js?1776399231
1/*************************************************************** 2 * Copyright notice 3 * 4 * (c) 2012 Alexander Kellner <[email protected]>, in2code 5 * 6 * All rights reserved 7 * 8 * This script is part of the TYPO3 project. The TYPO3 project is 9 * free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 3 of the License, or 12 * (at your option) any later version. 13 * 14 * The GNU General Public License can be found at 15 * http://www.gnu.org/copyleft/gpl.html. 16 * 17 * This script is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * GNU General Public License for more details. 21 * 22 * This copyright notice MUST APPEAR in all copies of the script! 23 ***************************************************************/ 24 25jQuery(document).ready(function($) { 26 $.fn.powermailTabs = function(options) { 27 'use strict'; 28 var $form = jQuery(this); 29 options = jQuery.extend({ 30 container: 'fieldset', 31 header: 'legend', 32 tabs: true, 33 navigation: true, 34 openTabOnError: true, 35 tabIndex: true, 36 tabMenuClassName: 'btn-group', 37 tabMenuItemActiveClassName: 'btn-primary', 38 tabMenuItemErrorClassName: 'btn-danger' 39 }, options); 40 41 showOnlyFirstFieldset($form, options); 42 generateTabNavigation($form, options); 43 generateButtonNavigation($form, options); 44 cleanAndAddErrorClassToTabs($form, options); 45 openTabWithError($form, options); 46 }; 47 48 /** 49 * initial show first fieldset 50 * 51 * @param {object} $form Complete form object 52 * @param {array} options 53 * @returns {void} 54 */ 55 function showOnlyFirstFieldset($form, options) { 56 hideAllFieldsets($form, options); 57 $form.find(options.container).first().show(); 58 } 59 60 /** 61 * Generate Tabs 62 * 63 * @param {jQuery} $form Complete form object 64 * @param {array} options 65 * @return {void} 66 */ 67 function generateTabNavigation($form, options) { 68 if (!options.tabs) { 69 return; 70 } 71 72 // generate menu 73 var $tabMenu = $('<div />', { 74 'class': options.tabMenuClassName 75 }).insertBefore( 76 $form.children(options.container).filter(':first') 77 ); 78 79 // all containers 80 $form.children(options.container).each(function(i, $fieldset) { 81 //tab_menu 82 //<button type="button" class="btn btn-default">Left</button> 83 var li = $('<button/>') 84 .html($(this).children(options.header).html()) 85 .addClass((i==0) ? options.tabMenuItemActiveClassName : '') 86 .addClass('item' + i) 87 .addClass('btn btn-default') 88 .prop('type', 'button') 89 .on('click keypress', { 90 container: $form.children(options.container), 91 fieldset: $($fieldset) 92 }, function() { 93 var $listItem = $(this); 94 var indexTab = $listItem.parent().children().index($listItem); 95 showTab($form, options, $listItem, indexTab); 96 }); 97 if (options.tabIndex) { 98 li.prop('tabindex', i); 99 } 100 $tabMenu.append(li); 101 }); 102 } 103 104 /** 105 * Generate Button Navigation 106 * 107 * @param {object} $form Complete form object 108 * @param {array} options 109 * @return {void} 110 */ 111 function generateButtonNavigation($form, options) { 112 if (!options.navigation) { 113 return; 114 } 115 116 // buttons 117 $form.children(options.container).each(function(i) {
118 var navigationContainer = $('<div />') 119 .addClass('powermail_fieldwrap') 120 .addClass('powermail_tab_navigation') 121 .appendTo($(this)); 122 if (i > 0) { 123 navigationContainer.append(createPreviousButton($form, options)); 124 } 125 if (i < ($form.children(options.container).length - 1)) { 126 navigationContainer.append(createNextButton($form, options)); 127 } 128 }); 129 } 130 131 /** 132 * Add error class to tab and show first if Parsley.js is active 133 * 134 * @param {object} $form Complete form object 135 * @param {array} options 136 * @return {void} 137 */ 138 function cleanAndAddErrorClassToTabs($form, options) { 139 if ($.fn.parsley && $form.data('parsley-validate') === 'data-parsley-validate') { 140 $form.parsley().subscribe('parsley:field:validated', function() { 141 removeErrorClassFromTabs($form, options); 142 addErrorClassToTabs($form, options); 143 }); 144 } 145 } 146 147 /** 148 * Open Tab with error 149 * 150 * @param {object} $form Complete form object 151 * @param {array} options 152 * @return {void} 153 */ 154 function openTabWithError($form, options) { 155 if (options.openTabOnError && $.fn.parsley) { 156 $.listen('parsley:field:error', function() { 157 // setTimeout(function() { 158 // $form 159 // .find('.' + options.tabMenuClassName + ' > .' + options.tabMenuItemErrorClassName + ':first') 160 // .click(); 161 // }, 50); 162 }); 163 } 164 } 165 166 /** 167 ************* Internal ************* 168 */ 169 170 /** 171 * Show Tab by index 172 * 173 * @param {object} $form Complete form object 174 * @param {array} options 175 * @param {object} $listItem 176 * @param {int} clickedIndex 177 * @return {void} 178 */ 179 function showTab($form, options, $listItem, clickedIndex) { 180 $activeTab = getActiveTabMenuListItem($form, options); 181 $activeTab.removeClass(options.tabMenuItemActiveClassName); 182 $listItem.addClass(options.tabMenuItemActiveClassName); 183 hideAllFieldsets($form, options); 184 $('.powermail_fieldset', $form).slice(clickedIndex, clickedIndex + 1).show(); 185 } 186 187 /** 188 * Hide all fieldsets 189 * 190 * @param {object} $form Complete form object 191 * @param {array} options 192 * @return {void} 193 */ 194 function hideAllFieldsets($form, options) { 195 $form.children(options.container).hide(); 196 } 197 198 /** 199 * Create next button 200 * 201 * @param {object} $form Complete form object 202 * @param {array} options 203 * @return {object} 204 */ 205 function createPreviousButton($form, options) { 206 return $('<a />') 207 .prop('href', '#') 208 .addClass('btn btn-default powermail_tab_navigation_previous') 209 .html('< precedente') 210 .click(function(e) { 211 e.preventDefault(); 212 showPreviousTab($form, options); 213 }); 214 } 215 216 /** 217 * Create next button 218 * 219 * @param {object} $form Complete form object 220 * @param {array} options 221 * @return {object} 222 */ 223 function createNextButton($form, options) { 224 return $('<a />') 225 .prop('href', '#') 226 .addClass('btn btn-default powermail_tab_navigation_next') 227 .html('successivo >') 228 .click(function(e) { 229 e.preventDefault(); 230 showNextTab($form, options); 231 }); 232 } 233 234 /** 235 * Show next Tab 236 * 237 * @param {object} $form Complete form object 238 * @param {array} options 239 * @return {void} 240 */ 241 function showNextTab($form, options) { 242 var currentActiveTabIndex = getIndexOfCurrentActiveTab($form, options); 243 $activeTab = getActiveTabMenuListItem($form, options); 244 $activeTab.removeClass(options.tabMenuItemActiveClassName).next().addClass(options.tabMenuItemActiveClassName); 245 showFieldsetByIndex($form, options, currentActiveTabIndex + 1); 246 } 247 248 /** 249 * Show previous Tab 250 * 251 * @param {object} $form Complete form object 252 * @param {array} options 253 * @return {void} 254 */ 255 function showPreviousTab($form, options) { 256 var currentActiveTabIndex = getIndexOfCurrentActiveTab($form, options); 257 $activeTab = getActiveTabMenuListItem($form, options); 258 $activeTab.removeClass(options.tabMenuItemActiveClassName).prev().addClass(options.tabMenuItemActiveClassName); 259 showFieldsetByIndex($form, options, currentActiveTabIndex - 1); 260 } 261 262 /** 263 * Show a powermail fieldset by given index 264 * 265 * @param {object} $form Complete form object 266 * @param {array} options 267 * @param {int} index 268 * @return {void} 269 */ 270 function showFieldsetByIndex($form, options, index) { 271 hideAllFieldsets($form, options); 272 $form.find('.powermail_fieldset').slice(index, index + 1).show(); 273 } 274 275 /** 276 * Get index of current active tab 277 * 278 * @param {object} $form Complete form object 279 * @param {array} options 280 * @returns {int} 281 */ 282 function getIndexOfCurrentActiveTab($form, options) { 283 var $listItems = getCurrentTabMenuListItems($form, options); 284 var currentActiveTabIndex = $listItems.index(getActiveTabMenuListItem($form, options)); 285 return parseInt(currentActiveTabIndex); 286 } 287 288 /** 289 * Get all list items from tabmenu 290 * 291 * @param {object} $form Complete form object 292 * @param {array} options 293 * @returns {jQuery} 294 */ 295 function getCurrentTabMenuListItems($form, options) { 296 return $form.find('.' + options.tabMenuClassName).children(); 297 } 298 299 /** 300 * Get active list item in tabmenu 301 * 302 * @param {object} $form Complete form object 303 * @param {array} options 304 * @returns {jQuery} 305 */ 306 function getActiveTabMenuListItem($form, options) { 307 var $listItems = getCurrentTabMenuListItems($form, options); 308 return $listItems.filter('.' + options.tabMenuItemActiveClassName); 309 } 310 311 /** 312 * Remove error classes from tab navigation 313 * 314 * @param {object} $form Complete form object 315 * @param {array} options 316 * @returns {void} 317 */ 318 function removeErrorClassFromTabs($form, options) { 319 var $tabMenuListItems = getCurrentTabMenuListItems($form, options); 320 $tabMenuListItems.removeClass(options.tabMenuItemErrorClassName); 321 } 322 323 /** 324 * Add error classes to tab navigation 325 * 326 * @param {object} $form Complete form object 327 * @param {array} options 328 * @returns {void} 329 */ 330 function addErrorClassToTabs($form, options) { 331 if (!$form.parsley().isValid()) { 332 // iterate through all fields with errors 333 $form.find('.parsley-error').each(function() { 334 var errorIndex = $form.find('.powermail_fieldset').index($(this).closest('.powermail_fieldset')); 335 var $tabMenuListItems = getCurrentTabMenuListItems($form, options); 336 var $tabWithError = $tabMenuListItems.slice(errorIndex, errorIndex + 1); 337 $tabWithError.addClass(options.tabMenuItemErrorClassName); 338 }); 339 } 340 } 341 342 343 344 var i = setInterval(function (){ 345 346 if($('.tx-powermail > div > form > .btn-group').length){ 347 348 clearInterval(i); 349 var n = 1; 350 351 var width = 25; 352 var l = $('.tx-powermail > div > form > .btn-group button').length; 353 if(l == 2) width = 49; 354 else if(l == 4) width = 25; 355 else if(l == 5) width = 20; 356 else if(l == 6) width = 16.66666; 357 358 var html = '<ul class="powermail_tabmenu nav nav-pills">'; 359 for(i=0;i<l;i++){ 360 html += '<li class="'+(i == 0 ? 'act ' : '')+'item'+i+'" tabindex="'+i+'" style="width: '+width+'%;"><a>passo '+(i+1)+'<span></span></a></li>'; 361 } 362 html += '</ul>'; 363 364 $('.tx-powermail > div > form > .btn-group').after(html); 365 366 $('.powermail_tabmenu.nav-pills a').click(function (){ 367 var index = $(this).parent().index(); 368 $('.tx-powermail > div > form > .btn-group button:eq('+index+')').trigger('click'); 369 370 $('.powermail_tabmenu.nav-pills .act').removeClass('act'); 371 $(this).parent().addClass('act'); 372 }) 373 374 $('.powermail_tab_navigation_previous').click(function (){ 375 var i = $('.powermail_tabmenu .act').index() - 1; 376 if(i >= 0){ 377 $('.powermail_tabmenu .act').removeClass('act'); 378 $('.powermail_tabmenu li:eq('+i+')').addClass('act'); 379 } 380 }); 381 382 $('.powermail_tab_navigation_next').click(function (){ 383 var i = $('.powermail_tabmenu .act').index() + 1; 384 if(i >= 0){ 385 $('.powermail_tabmenu .act').removeClass('act'); 386 $('.powermail_tabmenu li:eq('+i+')').addClass('act'); 387 } 388 }); 389 390 $('.btn-powermail-new').click(function (){ 391 setTimeout(function (){ 392 var i = $('.tx-powermail > div > form > .btn-group button.btn-primary').index(); 393 $('.powermail_tabmenu .act').removeClass('act'); 394 $('.powermail_tabmenu li:eq('+i+')').addClass('act') 395 396 $('.powermail_tabmenu li.parsley-error').removeClass('parsley-error'); 397 398 $('.tx-powermail > div > form > .btn-group button.btn-danger').each(function (){ 399 $('.powermail_tabmenu li:eq('+$(this).index()+')').addClass('parsley-error'); 400 }); 401 402 }, 500); 403 }) 404 405 if($('.powermail_message.powermail_message_error li').length == 1 && $('.powermail_message.powermail_message_error li').text().indexOf('Codice captcha errato') > -1){ 406 $('.powermail_tabmenu li:last a').trigger('click') 407 $('.powermail_tabmenu li:last').addClass('parsley-error'); 408 } 409 } 410 }, 50); 411 412 413});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.