1 /* ***** BEGIN LICENSE BLOCK *****
  2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3 *
  4 * The contents of this file are subject to the Mozilla Public License Version
  5 * 1.1 (the "License"); you may not use this file except in compliance with
  6 * the License. You may obtain a copy of the License at
  7 * http://www.mozilla.org/MPL/
  8 *
  9 * Software distributed under the License is distributed on an "AS IS" basis,
 10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 11 * for the specific language governing rights and limitations under the
 12 * License.
 13 *
 14 * The Original Code is TelaSocial TagVisor
 15 *
 16 * The Initial Developer of the Original Code is Taboca TelaSocial.
 17 * Portions created by the Initial Developer are Copyright (C) 2011
 18 * the Initial Developer. All Rights Reserved.
 19 *
 20 * Contributor(s):
 21 * Marcio Galli <mgalli@taboca.com>
 22 *
 23 * Alternatively, the contents of this file may be used under the terms of
 24 * either the GNU General Public License Version 2 or later (the "GPL"), or
 25 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 26 * in which case the provisions of the GPL or the LGPL are applicable instead
 27 * of those above. If you wish to allow use of your version of this file only
 28 * under the terms of either the GPL or the LGPL, and not to allow others to
 29 * use your version of this file under the terms of the MPL, indicate your
 30 * decision by ddomElementting the provisions above and replace them with the notice
 31 * and other provisions required by the GPL or the LGPL. If you do not ddomElementte
 32 * the provisions above, a recipient may use your version of this file under
 33 * the terms of any one of the MPL, the GPL or the LGPL.
 34 *
 35 * ***** END LICENSE BLOCK ***** */
 36 
 37 var rulesCounter=0;
 38 var scaleold=null;
 39 var scale=null;
 40 var timer = null;
 41 
 42 var dataStyle = " #pagetranslate { -moz-transform-origin:0 0; } #pagescale { } .slide { position:relative; } "; 
 43 
 44 
 45 function setStage() { 
 46 	//document.getElementById("viewport").setAttribute("style", "margin:auto;position:relative;background-color:white; height:500px; -moz-transform-origin:0 0; -o-transform-origin:0 0; -webkit-transform-origin:0 0; overflow:hidden;"); 
 47 //	document.getElementById("pagetranslate").setAttribute("style", "width:1200px; height:1200px"); 
 48 } 
 49 
 50 function setup() { 
 51 	var inlinestyle = document.createElement('link');
 52 	inlinestyle.setAttribute("rel","stylesheet");
 53 	inlinestyle.setAttribute("href","data:text/css,"+ escape(dataStyle));
 54 	document.getElementsByTagName("head")[0].appendChild(inlinestyle);
 55 } 
 56 
 57 function reload() { 
 58 	document.location= document.location;
 59 } 
 60 
 61 function sortArray(arr){
 62   var sortedKeys = new Array();
 63   var sortedObj = {};
 64   for (var i in arr){
 65 	sortedKeys.push(i);
 66   }
 67   sortedKeys.sort(sortNumber);
 68   for (var i in sortedKeys){
 69 	sortedObj[sortedKeys[i]] = arr[sortedKeys[i]];
 70   }
 71   return sortedObj;
 72 }
 73 
 74 function sortNumber(a,b)
 75 {
 76 return a - b;
 77 }
 78 
 79 function add(list) { 
 80 	for(var i=0;i<list.length;i++) { 
 81 		var item = list[i];
 82 		var time = item.getAttribute("data-time");
 83 		if(time) { 
 84 		if(time.indexOf("s")>-1) { 
 85 			var secs = time.split("s")[0];
 86 			// we use 2 ticks per sec
 87 			var tickStamp = parseInt(secs*2); 
 88 			itemsByTicks[tickStamp] = item; 
 89 		} 
 90 		} 
 91 	} 	
 92 } 
 93 
 94 var currentTick = null; 
 95 var playMode = false; 
 96 var counterSequential = 0;
 97 var ticksSerialized = new Array();
 98 var itemsByTicks = new Array();
 99 
100 var sortedItems = new Array();
101 
102 function play() { 
103 
104 	setStage();
105 	playMode=true; 
106 	
107 	sortedItems = sortArray(itemsByTicks);
108 
109 	var i=0;
110 	for (key in sortedItems) { 
111 		ticksSerialized[i]=key;
112 		i++;
113 	} 
114 	ticksSerialized[i]=-1;
115 	currentTick=0;
116 	counterSequential=0;
117 	tick();
118 } 
119 
120 function tick() { 
121 	if(playMode) { 
122 		try { 
123 			var nextTick = ticksSerialized[counterSequential];
124 			if(nextTick > -1) {
125 				if(nextTick==currentTick) { 
126 					var lookUpElement = itemsByTicks[currentTick];
127 					if(lookUpElement) { 
128 						var fAction = lookUpElement.getAttribute("data-duration"); 
129 						var dur = 2;
130 						if(fAction) { 
131 							dur=parseInt(fAction);	
132 						} 
133 						animateNext(lookUpElement,dur);
134 						counterSequential++;
135 						
136 					} 
137 				
138 				} 
139 						currentTick++;
140 						setTimeout("tick()",500); 
141 			} else { 
142 				//end
143 			} 
144 
145 		} catch (i) { 
146 			currentTick++;
147 			setTimeout("tick()",500); 
148 		}
149 	} 
150 } 
151 
152 function offset(domElement) {
153         if(!domElement) domElement = this;
154         var x = domElement.offsetLeft;
155         var y = domElement.offsetTop;
156         while (domElement = domElement.offsetParent) {
157                 x += domElement.offsetLeft;
158                 y += domElement.offsetTop;
159         }
160         return { left: x, top: y };
161 }
162 
163 function animateNext(a,t) { 
164 
165 	var el = offset(a);
166 	var x= el.left; 	
167 	var y= el.top; 	
168 	var ww = a.offsetWidth;
169 	var www = window.innerWidth;		        
170         var scale = www/(ww+800);
171 
172 	//document.getElementById("pagetranslate").setAttribute("style"," -moz-transition-property: -moz-transform; -moz-transform:scale("+scale+"); -moz-transition-duration:3s;  -webkit-transition-property: -webkit-transform; -webkit-transform:scale("+scale+"); -webkit-transition-duration:3s;  -o-transition-property: -o-transform; -o-transform:scale("+scale+"); -o-transition-duration:3s;");
173 
174 	scaleold = scale; 
175 	x-=0;
176         document.getElementById("pagescale").setAttribute("style","-moz-transition-property: -moz-transform; -moz-transform:translate("+-1*x+","+-1*y+"); -moz-transition-duration:"+t+"s; -webkit-transition-property: -webkit-transform; -webkit-transform:translate("+parseInt(-1*x)+"px,"+parseInt(-1*y)+"px); -webkit-transition-duration:"+t+"s; -o-transition-property: -o-transform; -o-transform:translate("+parseInt(-1*x)+"px,"+parseInt(-1*y)+"px); -o-transition-duration:"+t+"s;");
177 	
178 //	rulesCounter+=2;
179 } 
180 
181 setup();
182 
183