1/** 2 * uiMorphingButton_inflow.js v1.0.0 3 * http://www.codrops.com 4 * 5 * Licensed under the MIT license. 6 * http://www.opensource.org/licenses/mit-license.php 7 * 8 * Copyright 2014, Codrops 9 * http://www.codrops.com 10 */ 11;( function( window ) { 12 13 'use strict'; 14 15 var transEndEventNames = { 16 'WebkitTransition': 'webkitTransitionEnd', 17 'MozTransition': 'transitionend', 18 'OTransition': 'oTransitionEnd', 19 'msTransition': 'MSTransitionEnd', 20 'transition': 'transitionend' 21 }, 22 transEndEventName = transEndEventNames[ Modernizr.prefixed( 'transition' ) ], 23 support = { transitions : Modernizr.csstransitions }; 24 25 function extend( a, b ) { 26 for( var key in b ) { 27 if( b.hasOwnProperty( key ) ) { 28 a[key] = b[key]; 29 } 30 } 31 return a; 32 } 33 34 function UIMorphingButtonInflow( el, options ) { 35 this.el = el; 36 this.options = extend( {}, this.options ); 37 extend( this.options, options ); 38 this._init(); 39 } 40 41 UIMorphingButtonInflow.prototype.options = { 42 closeEl : '', 43 onBeforeOpen : function() { return false; }, 44 onAfterOpen : function() { return false; }, 45 onBeforeClose : function() { return false; }, 46 onAfterClose : function() { return false; } 47 } 48 49 UIMorphingButtonInflow.prototype._init = function() { 50 // save element height 51 this.elH = this.el.offsetHeight; 52 // the button 53 this.button = this.el.querySelector( 'button' ); 54 // state 55 this.expanded = false; 56 // content el 57 this.contentEl = this.el.querySelector( '.morph-content' ); 58 // init events 59 this._initEvents(); 60 } 61 62 UIMorphingButtonInflow.prototype._initEvents = function() { 63 var self = this; 64 // open 65 this.button.addEventListener( 'click', function() { self.toggle(); } ); 66 // close 67 if( this.options.closeEl !== '' ) { 68 var closeEl = this.el.querySelector( this.options.closeEl ); 69 if( closeEl ) { 70 closeEl.addEventListener( 'click', function() { self.toggle(); } ); 71 } 72 } 73 } 74 75 UIMorphingButtonInflow.prototype.toggle = function() { 76 if( this.isAnimating ) return false; 77 78 // callback 79 if( this.expanded ) { 80 this.options.onBeforeClose(); 81 } 82 else { 83 // add class active (solves z-index problem when more than one button is in the page) 84 classie.addClass( this.el, 'active' ); 85 this.options.onBeforeOpen(); 86 } 87 88 this.isAnimating = true; 89 90 var self = this, 91 onEndTransitionFn = function( ev ) { 92 if( ev.target !== this ) return false; 93 94 if( support.transitions ) { 95 this.removeEventListener( transEndEventName, onEndTransitionFn ); 96 } 97 self.isAnimating = false; 98 99 // callback 100 if( self.expanded ) { 101 // remove class active (after closing) 102 classie.removeClass( self.el, 'active' ); 103 self.options.onAfterClose(); 104 } 105 else { 106 self.options.onAfterOpen(); 107 } 108 109 self.expanded = !self.expanded; 110 }; 111 112 if( support.transitions ) { 113 this.el.addEventListener( transEndEventName, onEndTransitionFn ); 114 } 115 else { 116 onEndTransitionFn(); 117 } 118 119 // add/remove class "open" to the button wraper 120 this.el.style.height = this.expanded ? this.elH + 'px' : this.contentEl.offsetHeight + 'px'; 121 122 if( this.expanded ) { 123 classie.removeClass( this.el, 'open' ); 124 } 125 else { 126 classie.addClass( this.el, 'open' ); 127 } 128 } 129 130 // add to global namespace 131 window.UIMorphingButtonInflow = UIMorphingButtonInflow; 132 133})( window );
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.