1/** 2 * ATW JS module: 3 * selectalt.js 4 * 5 * Desc: 6 * Provides alternate <select> fallback for tabgroup.js 7 * 8 * Requires: 9 * jQuery, bootstrap, util, mediator, tabgroup 10 */ 11 12var krnl = ( function( app, $ ) { 13 14 "use strict"; 15 16 /* define new module */ 17 app.selectalt = ( function( $ ) { 18 19 // private vars 20 var _name = 'SelectAlt', 21 _initialized = null, 22 _debug_enable = true, 23 debug = null, 24 _enable = true, 25 26 _collection = [], 27 _config = { 28 'selectors': { 29 'wrap': '.select-alt', 30 'disable_classes': [ 31 { 32 'id': 'phone', 33 'class_name': 'selectalt-disable-phone' 34 }, 35 { 36 'id': 'tablet', 37 'class_name': 'selectalt-disable-tablet' 38 }, 39 { 40 'id': 'narrow-desktop', 41 'class_name': 'selectalt-disable-narrow-desktop' 42 }, 43 { 44 'id': 'wide-desktop', 45 'class_name': 'selectalt-disable-wide-desktop' 46 } 47 ] 48 }, 49 'transition_duration': 150 50 } 51 ; 52 53 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 54 55 function _init() { 56 57 if ( _initialized ) { 58 59 return; 60 61 } 62 63 /* * * * * * * * * * * * * * * * * * * */ 64 65 debug = ( _debug_enable ) ? krnl.util.debug : function(){}; 66 67 // Subscribe to mediator 68 _subscribe(); 69 70 _create(); 71 72 // Example broadcast 73 krnl.mediator.broadcast( 'SelectAltInit' ); 74 75 /* * * * * * * * * * * * * * * * * * * */ 76 77 _initialized = true; 78 79 } 80 81 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 82 83 /* 84 * Find elements and create objects 85 * 86 */ 87 88 function _create() { 89 90 $.each( $( _config.selectors.wrap ), function( index, node ) { 91 92 var new_object = new SelectAlt({ 93 '$wrap': $( node ) 94 }); 95 96 _collection.push( new_object ); 97 98 }); 99 100 } 101 102 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 103 104 function _update_all() { 105 106 var i, 107 display = krnl.displaydetect.get_display(); 108 109 for ( i = 0; i < _collection.length; i++ ) { 110 111 _collection[ i ].update( display ); 112 113 } 114 115 } 116 117 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 118 119 /* 120 * Allow an external action to set the currently selected option 121 * 122 */ 123 124 function _update_selection( args ) { 125 126 var i, 127 $this = null, 128 $wrap = args.$wrap, 129 selected_index = args.selected_index 130 ; 131 132 for ( i = 0; i < _collection.length; i++ ) { 133 134 var $node = _collection[ i ].$wrap; 135 136 if ( $node.is( $wrap ) ) { 137 138 $this = _collection[ i ]; 139 140 } 141 142 } 143 144 // Reset 145 $this.$select.find( 'option' ).attr('selected', false); 146 147 // Set 148 $this.$select.find( 'option' ).eq( selected_index ).attr('selected', true); 149 150 } 151 152 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 153 154 function SelectAlt( args ) { 155 156 var display = krnl.displaydetect.get_display(), 157 $this = this; 158 159 this.$wrap = args.$wrap; 160 161 this.$select = args.$wrap.find( 'select' ); 162 163 /* The following is used for associating with an alternate non-phone menu */ 164 165 this.$counterpart = null; 166 167 if ( args.$wrap.attr( 'data-counterpart-nav-selector' ) !== 'undefined' ) { 168 169 this.$counterpart = $( args.$wrap.attr( 'data-counterpart-nav-selector' ) ); 170 171 } 172 173 this.counterpart_item_selector = null; 174 175 if ( typeof args.$wrap.attr( 'data-counterpart-item-selector' ) !== 'undefined' ) { 176 177 this.counterpart_item_selector = args.$wrap.attr( 'data-counterpart-item-selector' ); 178 179 } 180 181 this.counterpart_button_selector = null; 182 183 if ( typeof args.$wrap.attr( 'data-counterpart-button-selector' ) !== 'undefined' ) { 184 185 this.counterpart_button_selector = args.$wrap.attr( 'data-counterpart-button-selector' ); 186 187 } 188 189 /* * * * * * * * * * * * * * * * * * * */ 190 191 this.bind_handlers(); 192 193 /* * * * * * * * * * * * * * * * * * * */ 194 195 this.update(); 196 197 } 198 199 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 200 201 /* 202 * Bind an onload handler for load detection 203 * and aspect ratio detection 204 * 205 */ 206 207 SelectAlt.prototype.bind_handlers = function() { 208 209 var $this = this; 210 211 $this 212 .$select 213 .off( 'change' ) 214 .on( 'change', function( e ) { 215 216 e.preventDefault(); 217 218 $this.on_change(); 219 220 krnl.mediator.broadcast( 'SelectAltChange', [ this ] ); 221 222 }); 223 224 }; 225 226 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 227 228 SelectAlt.prototype.on_change = function() { 229 230 // debug( _name + ': on_change' ); 231 232 var $this = this, 233 selected_index = $this.$select.prop( 'selectedIndex' ) 234 ; 235 236 $this.select_action( selected_index ); 237 238 }; 239 240 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 241 242 SelectAlt.prototype.select_action = function( selected_index ) { 243 244 var $this = this, 245 $nav_item = null, 246 $button = null, 247 item_selector, 248 button_selector 249 ; 250 251 if ( this.$counterpart === null ) { 252 253 return; 254 255 } 256 257 item_selector = this.counterpart_item_selector; 258 259 button_selector = this.counterpart_button_selector; 260
261 $nav_item = $( this.$counterpart.find( item_selector ).eq( selected_index ) ); 262 263 $button = $nav_item.find( button_selector ); 264 265 if ( typeof krnl.tabgroup === 'undefined' ) { 266 267 return; 268 269 } 270 271 krnl.tabgroup.select_tab({ 272 '$button': $button 273 }); 274 275 }; 276 277 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 278 279 SelectAlt.prototype.update = function( display ) { 280 281 282 283 }; 284 285 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 286 287 SelectAlt.prototype.update_selection = function( selected_index ) { 288 289 290 291 }; 292 293 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 294 295 /* Subscribe to mediator 296 * 297 */ 298 299 function _subscribe() { 300 301 app.mediator.add( _name, function() { 302 303 return { 304 305 name: _name, 306 307 onSelectAltInit: function() { 308 309 // debug( _name + ': module has initialized' ); 310 311 }, 312 313 onCssLoaded: function() { 314 315 // debug( _name + ': css loaded' ); 316 317 }, 318 319 onWindowResize: function() { 320 321 // debug( _name + ': window resize' ); 322 323 }, 324 325 onDisplayChange: function( display_id ) { 326 327 // debug( _name + ': display change' ); 328 329 }, 330 331 onSelectAltChange: function( collection_item ) { 332 333 // debug( _name + ': selectalt change' ); 334 335 } 336 337 }; 338 339 }()); 340 341 } 342 343 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 344 345 /* return public-facing methods and/or vars */ 346 return { 347 init : _init, 348 update_selection : _update_selection 349 }; 350 351 }($)); 352 353 return app; /* return augmented app object */ 354 355}( krnl || {}, jQuery ) ); /* import app if exists, or create new; import jQuery */ 356 357/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 358 359// register this module for initialization 360krnl.bootstrap.register( krnl.selectalt.init );
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.