fix typo
[openemr.git] / public / assets / jquery-modern-blink-0-1-3 / jquery.modern-blink.js
blob64ef8f468d4262fbc0b6db99ed4167408931398b
1 /*!
2  * jQuery Modern Blink plugin
3  * https://github.com/leonderijke/jQuery-Modern-Blink
4  *
5  * Version: 0.1.3
6  * Author: @leonderijke
7  * Licensed under the MIT license
8  */
10 ;(function ( $, window, document, undefined ) {
11         "use strict";
13         var domPrefixes = 'Webkit Moz O ms'.split( ' ' ),
14                 prefix = '',
15                 supportsAnimations = false,
16                 keyframeprefix = '',
17                 keyframes = '',
18                 defaults = {
19                         // Duration specified in milliseconds (integer)
20                         duration:       1000,
22                         // Number of times the element should blink ("infinite" or integer)
23                         iterationCount: "infinite",
25                         // Whether to start automatically or not (boolean)
26                         auto:          true
27                 },
28                 animationCss,
29                 i;
31         if( document.documentElement.style.animationName ) {
32                 supportsAnimations = true;
33         }
35         if ( !supportsAnimations ) {
36                 for( i = 0; i < domPrefixes.length; i++ ) {
37                         if( document.documentElement.style[ domPrefixes[ i ] + 'AnimationName' ] !== undefined ) {
38                                 prefix = domPrefixes[ i ];
39                                 keyframeprefix = '-' + prefix.toLowerCase() + '-';
40                                 supportsAnimations = true;
41                                 break;
42                         }
43                 }
44         }
46         if ( supportsAnimations ) {
47                 keyframes = '@' + keyframeprefix + 'keyframes modernBlink { '+
48                                                 '50% { opacity: 0; }'+
49                                         '}';
51                 var styleSheet = null;
52                 if ( document.styleSheets && document.styleSheets.length ) {
53                         for ( i = 0; i < document.styleSheets.length; i++ ) {
54                                 if ( document.styleSheets[ i ].href.indexOf( window.location.hostname ) == -1) {
55                                         continue;
56                                 }
58                                 styleSheet = document.styleSheets[ i ];
59                                 break;
60                         }
61                 }
63                 if ( styleSheet !== null ) {
64                         styleSheet.insertRule( keyframes, 0 );
65                 }
66                 else {
67                         var s = document.createElement( 'style' );
68                         s.innerHTML = keyframes;
69                         document.getElementsByTagName( 'head' )[ 0 ].appendChild( s );
70                 }
71         }
73         function ModernBlink( element, options ) {
74                 this.el = $(element);
76                 this.options = $.extend( {}, defaults, options );
78                 this._init();
79         }
81         /*
82          * @function _init
83          * Wraps the element, starts the animation
84          */
85         ModernBlink.prototype._init = function _init() {
86                 if ( this.options.auto ) {
87                         this.start();
88                 }
90                 this._bindEventHandlers();
91         };
93         /*
94          * @function start
95          * Starts the animation
96          */
97         ModernBlink.prototype.start = function start( event ) {
98                 if ( supportsAnimations ) {
99                         this.el.css({
100                                 'animation-name':            'modernBlink',
101                                 'animation-duration':        '' + this.options.duration + 'ms',
102                                 'animation-iteration-count': '' + this.options.iterationCount
103                         });
104                 } else {
105                         this._fallbackAnimation( this.options.iterationCount );
106                 }
107         };
109         /*
110          * @function stop
111          * Stops the animation
112          */
113         ModernBlink.prototype.stop = function stop( event ) {
114                 if ( supportsAnimations ) {
115                         return this.el.css({
116                                 'animation-name'            : '',
117                                 'animation-duration'        : '',
118                                 'animation-iteration-count' : ''
119                         });
120                 }
121                 return this.el.stop( true, true );
122         };
124         /*
125          * @function _fallbackAnimation
126          * Provides a jQuery Animation fallback for browsers not supporting CSS Animations
127          */
128         ModernBlink.prototype._fallbackAnimation = function _fallbackAnimation( iterationCount ) {
129                 var self = this,
130                         duration = this.options.duration / 2;
132                 if ( iterationCount > 0 || iterationCount === 'infinite' ) {
133                         iterationCount = iterationCount === "infinite" ? "infinite" : iterationCount - 1;
135                         this.el.animate( { 'opacity': 0 }, duration ).promise().done( function() {
136                                 self.el.animate( { 'opacity': 1 }, duration );
137                                 self._fallbackAnimation( iterationCount );
138                         });
139                 }
140         };
142         /*
143          * @function _bindEventHandlers
144          * Binds some useful event handlers to the element
145          */
146         ModernBlink.prototype._bindEventHandlers = function _bindEventHandlers() {
147                 this.el.on( 'modernBlink.start', $.proxy( this.start, this ) );
148                 this.el.on( 'modernBlink.stop', $.proxy( this.stop, this ) );
149         };
151         /*
152          * @function modernBlink
153          * jQuery plugin wrapper around ModernBlink
154          *
155          * @param options object
156          */
157         $.fn.modernBlink = function ( options ) {
158                 return this.each( function () {
159                         if ( !$.data( this, "plugin_modernBlink" ) ) {
160                                 $.data( this, "plugin_modernBlink", new ModernBlink( this, options ) );
161                         } else {
162                                 options = ( options || "" ).replace( /^_/ , "" );
163                                 if ( $.isFunction( ModernBlink.prototype[ options ] ) ) {
164                                         $.data( this, 'plugin_modernBlink' )[ options ]();
165                                 }
166                         }
167                 });
168         };
170 })( jQuery, window, document );