PageSourceSearch

https://www.brcixopo.co.za/modules/mod_jaimagehotspot/assets/js/jquery.dropdown.js

js brcixopo.co.za collected 2026-10-09 00:29:38 UTC 6,601 bytes, 211 lines download raw bytes

1/**
2 * jquery.dropdown.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 2012, Codrops
9 * http://www.codrops.com
10 */
11;( function( $, window, undefined ) {
12	'use strict';
13
14	$.jaDropDown = function( options, element ) {
15		this.$el = $( element );
16		this._init( options );
17	};
18
19	// the options
20	$.jaDropDown.defaults = {
21		speed : 300,
22		easing : 'ease',
23		gutter : 0,
24		// initial stack effect
25		stack : true,
26		// delay between each option animation
27		delay : 0,
28		// random angle and positions for the options
29		random : false,
30		// rotated [right||left||false] : the options will be rotated to thr right side or left side.
31		// make sure to tune the transform origin in the stylesheet
32		rotated : false,
33		// effect to slide in the options. value is the margin to start with
34		slidingIn : false,
35		onOptionSelect : function(opt) { return false; }
36	};
37
38	$.jaDropDown.prototype = {
39
40		_init : function( options ) {
41
42			// options
43			this.options = $.extend( true, {}, $.jaDropDown.defaults, options );
44			this._layout();
45			this._initEvents();
46
47		},
48		_layout : function() {
49
50			var self = this;
51			this.minZIndex = 1000;
52			var value = this._transformSelect();
53			this.opts = this.listopts.children( 'li' );
54			this.optsCount = this.opts.length;
55			this.size = { width : this.dd.width(), height : this.dd.height() };
56
57			var elName = this.$el.attr( 'name' ), elId = this.$el.attr( 'id' ),
58				inputName = elName !== undefined ? elName : elId !== undefined ? elId : 'cd-dropdown-' + ( new Date() ).getTime();
59
60			this.inputEl = $( '<input type="hidden" name="' + inputName + '" value="' + value + '"></input>' ).insertAfter( this.selectlabel );
61
62			this.selectlabel.css( 'z-index', this.minZIndex + this.optsCount );
63			this._positionOpts();
64			if( Modernizr.csstransitions ) {
65				setTimeout( function() { self.opts.css( 'transition', 'all ' + self.options.speed + 'ms ' + self.options.easing ); }, 25 );
66			}
67
68		},
69		_transformSelect : function() {
70
71			var optshtml = '', selectlabel = '', value = -1;
72			this.$el.children( 'option' ).each( function() {
73
74				var $this = $( this ),
75					val = isNaN( $this.attr( 'value' ) ) ? $this.attr( 'value' ) : Number( $this.attr( 'value' ) ) ,
76					classes = $this.attr( 'class' ),
77					selected = $this.attr( 'selected' ),
78					label = $this.text();
79
80				if( val !== -1 ) {
81					optshtml +=
82						classes !== undefined ?
83							'<li data-value="' + val + '"><span class="' + classes + '" title="' + (label.replace(/'/g, "\\'")) + '">' + label + '</span></li>' :
84							'<li data-value="' + val + '"><span title="' + (label.replace(/'/g, "\\'")) + '">' + label + '</span></li>';
85				}
86
87				if( selected ) {
88					selectlabel = label;
89					value = val;
90				}
91
92			} );
93
94			this.listopts = $( '<ul/>' ).append( optshtml );
95			this.selectlabel = $( '<span/>' ).append( selectlabel );
96			this.dd = $( '<div class="cd-dropdown"/>' ).append( this.selectlabel, this.listopts ).insertAfter( this.$el );
97			this.$el.remove();
98
99			return value;
100
101		},
102		_positionOpts : function( anim ) {
103
104			var self = this;
105
106			this.listopts.css( 'height', 'auto' );
107			this.opts
108				.each( function( i ) {
109					$( this ).css( {
110						zIndex : self.minZIndex + self.optsCount - 1 - i,
111						top : self.options.slidingIn ? ( i + 1 ) * ( self.size.height + self.options.gutter ) : 0,
112						left : 0,
113						marginLeft : self.options.slidingIn ? i % 2 === 0 ? self.options.slidingIn : - self.options.slidingIn : 0,
114						opacity : self.options.slidingIn ? 0 : 1,
115						transform : 'none'
116					} );
117				} );
118
119			if( !this.options.slidingIn ) {
120				this.opts
121					.eq( this.optsCount - 1 )
122					.css( { top : this.options.stack ? 9 : 0, left : this.options.stack ? 4 : 0, width : this.options.stack ? this.size.width - 8 : this.size.width, transform : 'none' } )
123					.end()
124					.eq( this.optsCount - 2 )
125					.css( { top : this.options.stack ? 6 : 0, left : this.options.stack ? 2 : 0, width : this.options.stack ? this.size.width - 4 : this.size.width, transform : 'none' } )
126					.end()
127					.eq( this.optsCount - 3 )
128					.css( { top : this.options.stack ? 3 : 0, left : 0, transform : 'none' } );
129			}
130
131		},
132		_initEvents : function() {
133
134			var self = this;
135
136			this.selectlabel.on( 'mousedown.dropdown', function( event ) {
137				self.opened ? self.close() : self.open();
138				return false;
139
140			} );
141
142			this.opts.on( 'click.dropdown', function() {
143				if( self.opened ) {
144					var opt = $( this );
145					self.options.onOptionSelect( opt );
146					self.inputEl.val( opt.data( 'value' ) );
147					self.selectlabel.html( opt.html() );
148					self.close();
149				}
150			} );
151
152		},
153		open : function() {
154			var self = this;
155			this.dd.toggleClass( 'cd-active' );
156			this.listopts.css( 'height', ( this.optsCount + 1 ) * ( this.size.height + this.options.gutter ) );
157			this.opts.each( function( i ) {
158
159				$( this ).css( {
160					opacity : 1,
161					top : self.options.rotated ? self.size.height + self.options.gutter : ( i + 1 ) * ( self.size.height + self.options.gutter ),
162					left : self.options.random ? Math.floor( Math.random() * 11 - 5 ) : 0,
163					width : self.size.width,
164					marginLeft : 0,
165					transform : self.options.random ?
166						'rotate(' + Math.floor( Math.random() * 11 - 5 ) + 'deg)' :
167						self.options.rotated ?
168							self.options.rotated === 'right' ?
169								'rotate(-' + ( i * 5 ) + 'deg)' :
170								'rotate(' + ( i * 5 ) + 'deg)'
171							: 'none',
172					transitionDelay : self.options.delay && Modernizr.csstransitions ? self.options.slidingIn ? ( i * self.options.delay ) + 'ms' : ( ( self.optsCount - 1 - i ) * self.options.delay ) + 'ms' : 0
173				} );
174
175			} );
176			this.opened = true;
177
178		},
179		close : function() {
180
181			var self = this;
182			this.dd.toggleClass( 'cd-active' );
183			if( this.options.delay && Modernizr.csstransitions ) {
184				this.opts.each( function( i ) {
185					$( this ).css( { 'transition-delay' : self.options.slidingIn ? ( ( self.optsCount - 1 - i ) * self.options.delay ) + 'ms' : ( i * self.options.delay ) + 'ms' } );
186				} );
187			}
188			this._positionOpts( true );
189			this.opened = false;
190
191		}
192
193	}
194
195	$.fn.jadropdown = function( options ) {
196		var instance = $.data( this, 'dropdown' );
197		if ( typeof options === 'string' ) {
198			var args = Array.prototype.slice.call( arguments, 1 );
199			this.each(function() {
200				instance[ options ].apply( instance, args );
201			});
202		}
203		else {
204			this.each(function() {
205				instance ? instance._init() : instance = $.data( this, 'dropdown', new $.jaDropDown( options, this ) );
206			});
207		}
208		return instance;
209	};
210
211} )( jQuery, 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.