Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*!
- * classie - class helper functions
- * from bonzo https://github.com/ded/bonzo
- *
- * classie.has( elem, 'my-class' ) -> true/false
- * classie.add( elem, 'my-new-class' )
- * classie.remove( elem, 'my-unwanted-class' )
- * classie.toggle( elem, 'my-class' )
- */
- /*jshint browser: true, strict: true, undef: true */
- /*global define: false */
- ( function( window ) {
- 'use strict';
- // class helper functions from bonzo https://github.com/ded/bonzo
- function classReg( className ) {
- return new RegExp("(^|\\s+)" + className + "(\\s+|$)");
- }
- // classList support for class management
- // altho to be fair, the api sucks because it won't accept multiple classes at once
- var hasClass, addClass, removeClass;
- if ( 'classList' in document.documentElement ) {
- hasClass = function( elem, c ) {
- return elem.classList.contains( c );
- };
- addClass = function( elem, c ) {
- elem.classList.add( c );
- };
- removeClass = function( elem, c ) {
- elem.classList.remove( c );
- };
- }
- else {
- hasClass = function( elem, c ) {
- return classReg( c ).test( elem.className );
- };
- addClass = function( elem, c ) {
- if ( !hasClass( elem, c ) ) {
- elem.className = elem.className + ' ' + c;
- }
- };
- removeClass = function( elem, c ) {
- elem.className = elem.className.replace( classReg( c ), ' ' );
- };
- }
- function toggleClass( elem, c ) {
- var fn = hasClass( elem, c ) ? removeClass : addClass;
- fn( elem, c );
- }
- var classie = {
- // full names
- hasClass: hasClass,
- addClass: addClass,
- removeClass: removeClass,
- toggleClass: toggleClass,
- // short names
- has: hasClass,
- add: addClass,
- remove: removeClass,
- toggle: toggleClass
- };
- // transport
- if ( typeof define === 'function' && define.amd ) {
- // AMD
- define( classie );
- } else {
- // browser global
- window.classie = classie;
- }
- })( window );
- /**
- * pathLoader.js v1.0.0
- * http://www.codrops.com
- *
- * Licensed under the MIT license.
- * http://www.opensource.org/licenses/mit-license.php
- *
- * Copyright 2014, Codrops
- * http://www.codrops.com
- */
- ;( function( window ) {
- 'use strict';
- function PathLoader( el ) {
- this.el = el;
- // clear stroke
- this.el.style.strokeDasharray = this.el.style.strokeDashoffset = this.el.getTotalLength();
- }
- PathLoader.prototype._draw = function( val ) {
- this.el.style.strokeDashoffset = this.el.getTotalLength() * ( 1 - val );
- }
- PathLoader.prototype.setProgress = function( val, callback ) {
- this._draw(val);
- if( callback && typeof callback === 'function' ) {
- // give it a time (ideally the same like the transition time) so that the last progress increment animation is still visible.
- setTimeout( callback, 200 );
- }
- }
- PathLoader.prototype.setProgressFn = function( fn ) {
- if( typeof fn === 'function' ) { fn( this ); }
- }
- // add to global namespace
- window.PathLoader = PathLoader;
- })( window );
- /**
- * main.js
- * http://www.codrops.com
- *
- * Licensed under the MIT license.
- * http://www.opensource.org/licenses/mit-license.php
- *
- * Copyright 2014, Codrops
- * http://www.codrops.com
- */
- (function() {
- var support = { animations : Modernizr.cssanimations },
- container = document.getElementById( 'ip-container' ),
- header = container.querySelector( 'header.ip-header' ),
- loader = new PathLoader( document.getElementById( 'ip-loader-circle' ) ),
- animEndEventNames = { 'WebkitAnimation' : 'webkitAnimationEnd', 'OAnimation' : 'oAnimationEnd', 'msAnimation' : 'MSAnimationEnd', 'animation' : 'animationend' },
- // animation end event name
- animEndEventName = animEndEventNames[ Modernizr.prefixed( 'animation' ) ];
- function init() {
- var onEndInitialAnimation = function() {
- if( support.animations ) {
- this.removeEventListener( animEndEventName, onEndInitialAnimation );
- }
- startLoading();
- };
- // disable scrolling
- window.addEventListener( 'scroll', scroll );
- // initial animation
- classie.add( container, 'loading' );
- if( support.animations ) {
- container.addEventListener( animEndEventName, onEndInitialAnimation );
- }
- else {
- onEndInitialAnimation();
- }
- }
- function startLoading() {
- // simulate loading something..
- var simulationFn = function(instance) {
- var progress = 0,
- interval = setInterval( function() {
- progress = Math.min( progress + Math.random() * 0.1, 1 );
- instance.setProgress( progress );
- // reached the end
- if( progress === 1 ) {
- classie.remove( container, 'loading' );
- classie.add( container, 'loaded' );
- clearInterval( interval );
- var onEndHeaderAnimation = function(ev) {
- if( support.animations ) {
- if( ev.target !== header ) return;
- this.removeEventListener( animEndEventName, onEndHeaderAnimation );
- }
- classie.add( document.body, 'layout-switch' );
- window.removeEventListener( 'scroll', scroll );
- };
- if( support.animations ) {
- header.addEventListener( animEndEventName, onEndHeaderAnimation );
- }
- else {
- onEndHeaderAnimation();
- }
- }
- }, 80 );
- };
- loader.setProgressFn( simulationFn );
- }
- function noscroll() {
- window.scrollTo( 0, 0 );
- }
- init();
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement