hare-script.js 11.9 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416
/**
 * @author Arlan Viray, arlan.viray@creativewiz.net
 * @modified: Gustavo Rodrigues
 * @email: gugateider@gmail.com 
 * @modified: Dan Rempel
 * @email: dan@gotenzing.com 
 */

'use strict';

var Advert = {
	width: null,
	height: null,
	animationArr: [],
	debugMode: 0,
	duration: 0.2,	
	timeline: new TimelineMax({
		delay: 0,
		onComplete: function(){}
	}),
	timelineGeneric: new TimelineMax( { 
		delay: 0,
		onComplete: function() {}
	}),
	clickId: 0,
	ft: undefined,
	stopWatcher: 0,
	stopWatcherUpdate: 200,

	/**
		Initializes the banner 
		@param width  -> Banner width
		@param height -> Banner height
		@param ft     -> Flash Talking Component / Double Click
		@param animationArr -> Animation array of objects that needs to be animated
		@param duration -> Duration of each tween
		@param debugMode -> In case you wish to see a certain static frame 
	**/
	init: function(width, height, ft, animationArr, duration, debugMode){
		this.width = width;
		this.height = height;
		this.ft = ft;
		this.animationArr = animationArr;
		this.debugMode = debugMode;
		this.duration = duration;

		TweenMax.set($('#container'), {display: 'block'});
		TweenMax.set($('#container, .section, .clickTag'), {width: this.width, height: this.height});
		// TweenMax.set( $("#logo"), { left: 220, top: 154, scale: 0.72, opacity: 0 });
		TweenMax.set($("#yellow_frame") , { display: "none" } );
		//TweenMax.set($(".copyright") , { scale: .8 } );

		var isiPad = navigator.userAgent.match(/iPad/i) != null;
		if( isiPad ) $("#yellow_frame #text-start p").css("marginTop" , 0);
		
		this.setAnim();
		this.startStopWatcher();
		//this.initVideo();
	},

	/**
		Function responsible to initialize the animation of the generic stuff
		@param none
	**/
	startGenericAnimation: function() {

		// Show Yellow Frame again
		TweenMax.set($("#yellow_frame") , { display: "block" } );
		
		var _this = this;

		// Delays !
		var delayFirstText		   = 4;//4
		var delayYellowBoxText	   = 6;//6
		var delayEndCopy		   = 2;//2

		// Transition Speed
		var firstTextSpeed		   = .5;
		var frameSpeedTransition   = .2;
		var endFrameCopyTransition = .5;
		var delayEndFrameCopy 	   = 1;


		// Add to timeline generic animation
		// Animate Logo!
		//this.timelineGeneric.to( $("#logo") , 1 , { opacity: 1 } );

		// Bottom Animation
		this.timelineGeneric.to( $("#bottom"), frameSpeedTransition , { width: 26 } );//26
		this.timelineGeneric.to( $("#bottom"), frameSpeedTransition , { width: 38 } );//38
		this.timelineGeneric.to( $("#bottom"), frameSpeedTransition , { width: 50 } );//50
		this.timelineGeneric.to( $("#bottom"), frameSpeedTransition , { width: 217 } );//136

		// Right Frame colunm animation
		this.timelineGeneric.to( $("#right"), frameSpeedTransition , { height: 185, top: 40 } );

		// Top Yellow Frame animation
		this.timelineGeneric.to( $("#top"), frameSpeedTransition , { left: 10, top: 36 } );//132

		// Yellow Frame left animation
		this.timelineGeneric.to( $("#left"), frameSpeedTransition , { height: 147 } );

		// Dark transparent fill 
		this.timelineGeneric.from( $("#tintfill"), frameSpeedTransition , { opacity: 0 }, "-=" + frameSpeedTransition );

		// First text to appear within the square
		this.timelineGeneric.from( $("#text-start"), firstTextSpeed , { opacity: 0 },  "-=" + frameSpeedTransition );

		// Transition out text and dark transparent
		this.timelineGeneric.to( $("#tintfill"), frameSpeedTransition , { opacity: 0 }, "+=" + delayFirstText );
		this.timelineGeneric.to( $("#text-start"), frameSpeedTransition , { opacity: 0 } );

		// Move Yellow square up
		this.timelineGeneric.from( $(".holder"), frameSpeedTransition , { top: 190 } );
		
		// Fade in Text within yellow square
		this.timelineGeneric.from( $(".holder div p"), frameSpeedTransition , { opacity: 0 } );
		// Fade Out Text within yellow square
		this.timelineGeneric.to( $(".holder div p"), frameSpeedTransition , { opacity: 0 }, "+=" + delayYellowBoxText );

		// Scale Down Yellow Square
		this.timelineGeneric.to( $("#yellowfill"), frameSpeedTransition * 2 , { scale: 0 , left: -50, top: -5, onStart: function() {
			TweenMax.set($("#bottom, #top, #left, #right,#yellowfill .holder object"), { opacity: 0 });
			TweenMax.set($("#bottom") , { top: 88, width: 50 } );

			TweenMax.set($("#threedots .dot1") , { top: 85, left: 0 } );
		}});

		// Increase Logo Size
		//this.timelineGeneric.to($("#logo") , frameSpeedTransition * 2 , { scale: 1, left: 210, top: 138  }, "-=" + frameSpeedTransition );
		
		// Animate First Copy ( "The better the question" )
		this.timelineGeneric.from( $("#endFrame .copy .copy1"), endFrameCopyTransition , { width: "270px", onStart: function(){
			$("#endFrame").css("display","block");
			
			TweenMax.to( $("#blackBaseGrad") , frameSpeedTransition * 10,  {opacity: .5});

			TweenMax.set( $(".answer , .worldworks") , { opacity: 0 } );


		} });

		// Animate first dots
		this.timelineGeneric.to( $("#threedots .dot1"), endFrameCopyTransition , { left: 270, onComplete: function(){
			
			TweenMax.set($("#threedots .dot1") , { top: 61, left: 62 } );
			TweenMax.from($("#threedots .dot1") , endFrameCopyTransition , { left: 0 } );


		} } , "-=" + (endFrameCopyTransition)  );
		
/*		
		// Animate the copy ( "Question" )
		this.timelineGeneric.from( $("#endFrame .copy .question"), endFrameCopyTransition , { width: "0%", onComplete: function(){
			
			TweenMax.set($("#threedots .dot1") , { top: 60, left: 46 } );
			TweenMax.from($("#threedots .dot1") , endFrameCopyTransition , { left: 0 } );

		} } );
		
*/
		// Fade Out First Copy, make 2nd dot appear
		this.timelineGeneric.to( $("#endFrame .copy .question , #endFrame .copy .copy1"), endFrameCopyTransition * .5 , { opacity: 0, onComplete: function(){
			
			// make second little dot visible
			TweenMax.set($("#threedots .dot2") , { top: 85, left: 0 } );

			// Set "The better the" width 0
			TweenMax.set($("#endFrame .copy .copy1 , .answer") , { width: 0, opacity: 1 } );


		} } , "+=" + (delayEndFrameCopy));





		// Animate second dots
		this.timelineGeneric.to( $("#threedots .dot2"), endFrameCopyTransition , { left: 270, onComplete: function(){
			
			TweenMax.set($("#threedots .dot2") , { top: 61, left: 45 } );
			TweenMax.from($("#threedots .dot2") , endFrameCopyTransition , { left: 0 } );

		} } );
		

		// Animate Copy ( "The better the answer" )
		this.timelineGeneric.to( $("#endFrame .copy .answer"), endFrameCopyTransition , { width: "270px", onStart: function(){
			
		} } , "-=" + endFrameCopyTransition );
/*
		// Animate the copy ( "Answer" )
		this.timelineGeneric.to( $("#endFrame .copy .answer"), endFrameCopyTransition , { width: "120%", onComplete: function(){
			
			TweenMax.set($("#threedots .dot2") , { top: 61, left: 28 } );
			TweenMax.from($("#threedots .dot2") , endFrameCopyTransition , { left: 0 } );

		} });
*/
		// Fade Out Second Copy
		this.timelineGeneric.to( $("#endFrame .copy .answer , #endFrame .copy .copy1"), endFrameCopyTransition * .5 , { opacity: 0, onComplete: function(){
			
			// make third little dot visible
			TweenMax.set($("#threedots .dot3") , { top: 85, left: 0 } );

			// Set "The better the" width 0
			TweenMax.set($("#endFrame .copy .copy1 , .worldworks") , { width: 0, opacity: 1 } );


		} } , "+=" + (delayEndFrameCopy));





		// Animate third dots
		this.timelineGeneric.to( $("#threedots .dot3"), endFrameCopyTransition , { left: 270, onComplete: function(){
			
			TweenMax.set($("#threedots .dot3") , { top: 61, left: 28 } );
			TweenMax.from($("#threedots .dot3") , endFrameCopyTransition , { left: 0 } );

		} } );

		// Animate Copy ( "The better the " )
		this.timelineGeneric.to( $("#endFrame .copy .worldworks"), endFrameCopyTransition , { width: "270px", onStart: function(){
    		//_this.clearStopWatcher();
			
		} } , "-=" + endFrameCopyTransition );
/*
		// Animate the copy ( "Answer" )
		this.timelineGeneric.to( $("#endFrame .copy .worldworks"), endFrameCopyTransition , { width: "120%", onComplete: function(){
			
			TweenMax.set($("#threedots .dot3") , { top: 61, left: 25 } );
			TweenMax.from($("#threedots .dot3") , endFrameCopyTransition , { left: 0 } );

			_this.clearStopWatcher();

		} });
*/

		// Fade In CTA
		this.timelineGeneric.from( $("#endFrame #cta"), endFrameCopyTransition , { opacity: 0, onStart: function(){
    		// make the play button visible
    		TweenMax.set($("#play") , { display: "block" } );
    		_this.clearStopWatcher();
			
		} } , "+=" + endFrameCopyTransition );
        

	},

	/**
		Function responsible to start counting the length
		in seconds of this banner
		@param none
	**/
	startStopWatcher: function() { 
		
		var _this = this;
		this.stopWatcher = window.setInterval( function() { _this.setStopWatcher() }, this.stopWatcherUpdate);
		
	}, 

	/**
		Set the current length of the banner
		@param none
	**/
	setStopWatcher: function() { 

		if( this.stopWatcher != -1 )
		{
			this.stopWatcher += this.stopWatcherUpdate;
			//console.log("Current banner seconds length: " + parseFloat( this.stopWatcher / 1000 ) + " seconds ..." );
		}
			
	},

	/**
		Clear stop watcher 
		@param none
	**/
	clearStopWatcher: function() { 


		console.log( " ------------------------------------------------------------ ");
		console.log( "clearStopWatcher: Your banner " + parseFloat( this.stopWatcher / 1000 ) + " seconds long ...");
		console.log( " ------------------------------------------------------------ ");
		this.stopWatcher = window.clearInterval( this.stopWatcher );
		this.stopWatcher = -1;
	},

	/**
		Start playing video
		@param none
	**/
	initVideo: function() { 

		$("video").get(0).play();

	},

	/**
		Fades out playing video
		@param none
	**/
	hideVideo: function() { 
		TweenMax.to( $("video") , 1, { autoAlpha: 0 });
		// $("video").get(0).pause();
	},

	/**
		This function is responsible to animate your items
		@param none
	**/
	setAnim: function(){
		
		var _this = this;

		// set animations as array object
		var anims = _this.animationArr; 

		// test specific section for styling purpose
		// has to be greater than 0. Animation will be disable
		var testSection = _this.debugMode;
		if(testSection > 0){
			TweenMax.set($('.section').eq(testSection - 1), {display: 'block'});
		} else {
			TweenMax.set($('.section'), {display: 'block'});
		}

		/**
			Loop through the animation objects and add them to timeline 
			@param anims -> Animation array
			@param index -> Index count of array
			@param animObjs -> Obj within anims
		**/
		$.each(anims, function(index, animObjs){
			if(testSection > 0){
				if(index + 1 !== testSection){
					return;
				}

			} else {

				$.each(animObjs, function(i, obj){
					var elem = $('.section'+ (index + 1));
					var duration = _this.duration;
					var objects = obj.object;
					var overlap = '-=0';
					if(obj.child){
						elem = elem.find(obj.child);
					}
					if(obj.exdur){
						duration += obj.exdur;
					}
					if(obj.overlap){
						overlap = obj.overlap;
					}
					if(obj.duration) duration = obj.duration;
					
					if( obj.complete == "startGenericAnimation") obj.object.onComplete = function() { Advert.startGenericAnimation(); };
					if( obj.start == "startGenericAnimation" ) obj.object.onStart = function() { Advert.startGenericAnimation(); };


					// set timeline
					if(obj.type === 'from'){
						_this.timeline.from(elem, duration, objects, overlap);
					} else {
						_this.timeline.to(elem, duration, objects, overlap);
					}

				});
			}
		});

		this.setClickTag();
		this.setElements();
	},

	/**
		Set Flash Talking clickTag
		@param id -> ID of clickTag
	**/
	setClickTag: function(id){
		var _this = this;
		$('.clickTag').click(function(){
            console.log("clickTag!");
            // Enabler.exit("ClickThrough");
			//_this.ft.clickTag(_this.clickId + 1);
		});
	},

	setElements: function(){
		var _this = this;
		
	},

	setEnd: function(){
		console.log('end');
	},

	restartAnim: function(){
		console.log('restart');
	}
};


$(document).ready(function() {
  var icon = $('.play');
  icon.click(function() {
     icon.toggleClass('active');
     console.log("clickPlay!");
     location.reload();
     return false;
  });
});