1function compareVersion( v1, v2 ) { 2 3 if( v1 === v2 ) 4 return 0; 5 6 var a1 = v1.toString().split("."); 7 var a2 = v2.toString().split("."); 8 9 for( var i = 0; i < a1.length && i < a2.length; i++ ) { 10 11 var diff = parseInt( a1[i], 10 ) - parseInt( a2[i], 10 ); 12 if( diff > 0 ) 13 return 1; 14 else if( diff < 0 ) 15 return -1; 16 } 17 diff = a1.length - a2.length; 18 return ( diff > 0 ) ? 1 : ( diff < 0 ) ? -1 : 0; 19} 20 21jQuery(document).ready(function($) { 22 23 if( 'undefined' === typeof( tab_settings ) || 'undefined' === typeof( $.ui ) ) 24 return; 25 26 if( 'undefined' === typeof( tab_settings.enabled_tabs ) ) 27 tab_settings.enabled_tabs = {}; 28 29 if( 'undefined' === typeof( tab_settings.disabled_tabs ) ) 30 tab_settings.disabled_tabs = {}; 31 32 tab_settings.tab_ends = {}; 33 34 var i = 1; 35 36 // Get jQuery UI Version 37 var uiversion = $.ui.version; 38 39 // Check if jQuery 1.8 40 var is_old_ui = compareVersion( uiversion, "1.9") < 0; 41 42 // Post UI Tabs functions 43 var PostUITabs = { 44 45 // Function to create the tab sets 46 create_tabsets: function( total ) { 47 48 for( ;i <= total; i++ ) { 49 50 var 51 tabs_el = '#tabs-' + i; 52 leftmost_tab = null, 53 rightmost_tab = null, 54 settings = {}; 55 56 if( tab_settings.enabled_tabs.hasOwnProperty(i) ) { 57 leftmost_tab = Math.min.apply( null, tab_settings.enabled_tabs[i] ); 58 rightmost_tab = Math.max.apply( null, tab_settings.enabled_tabs[i] ); 59 tab_settings.tab_ends[tabs_el] = { left: leftmost_tab, right: rightmost_tab }; 60 } 61 if( tab_settings.disabled_tabs.hasOwnProperty(i) ) 62 settings.disabled = tab_settings.disabled_tabs[i]; 63 64 if( tab_settings.select_active === '1' ) 65 is_old_ui ? settings.selected = leftmost_tab : settings.active = leftmost_tab; 66 67 $(tabs_el).tabs(settings); 68 } 69 }, 70 71 // Function to switch tab using navigation buttons 72 move_to_tab: function( o ) { 73 74 var put_tabset = $( $(this).attr('href') ); 75 76 if( 'undefined' === typeof( put_tabset ) ) 77 return false; 78 79 var tab_ends = tab_settings.tab_ends[put_tabset.selector]; 80 81 if( 'undefined' === typeof( tab_ends ) ) 82 return false; 83 84 var index, wrap_to_index, adding; 85 var tabs = $( put_tabset.selector + ' ul' ).children(); 86 87 // Move index one place 88 switch( o.data.direction ) { 89 case 'left': 90 index = PostUITabs.get_sibling_tab( put_tabset, 'left' ); 91 wrap_to_index = tab_ends.right; 92 adding = false; 93 break; 94 case 'right': 95 index = PostUITabs.get_sibling_tab( put_tabset, 'right' ); 96 wrap_to_index = tab_ends.left; 97 adding = true; 98 break; 99 default: return false; 100 } 101 // Check the next index is valid 102 if( 'undefined' === typeof( tabs[index] ) || index > tab_ends.right || index < 0 ) { 103 PostUITabs.set_active_tab( put_tabset, wrap_to_index ); 104 return false; 105 } 106 107 // Loop through additional tabs if required 108 while( index < tabs.length ) { 109 110 // Negatives are valid, but will not work when the tab is disabled 111 if( index < 0 ) { 112 PostUITabs.set_active_tab( put_tabset, wrap_to_index ); 113 break; 114 } 115 // Move the index up/down if the index is a disabled tab 116 if( PostUITabs.is_disabled_tab( put_tabset, index ) ) { 117 index = adding ? index + 1 : index - 1; 118 continue; 119 } 120 // Ok valid index, set tab 121 PostUITabs.set_active_tab( put_tabset, index ); 122 return false; 123 } 124 return false; 125 }, 126 // Function to get the next tab index 127 get_sibling_tab: function( selector, dir ) { 128 var option = is_old_ui ? "selected" : "active"; 129 return dir === 'left' ? selector.tabs( "option", option ) - 1 : selector.tabs( "option", option ) + 1; 130 }, 131 132 // Function to select active tab 133 set_active_tab: function( selector, index ) { 134 is_old_ui ? selector.tabs( 'select', index ) : selector.tabs( 'option', 'active', index ); 135 }, 136 137 // Function to determine if tab is diabled 138 is_disabled_tab: function( selector, index ) { 139 return $.inArray( index, selector.tabs("option", "disabled") ) > -1; 140 } 141 }; 142 143 PostUITabs.create_tabsets( tab_settings.total_tabsets ); 144 145 // Attach function to click for nav buttons 146 $('.put-prev').click({ direction:"left" }, PostUITabs.move_to_tab ); 147 $('.put-next').click({ direction:"right" }, PostUITabs.move_to_tab ); 148 149 // Disable the click functionality of disabled tabs(deals with single case where all tabs are disabled in a set) 150 $('.ui-state-disabled a').click(function(e){ e.preventDefault(); }); 151});
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.