action.js 105 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180
  1. $axure.internal(function($ax) {
  2. var _actionHandlers = {};
  3. var _action = $ax.action = {};
  4. var queueTypes = _action.queueTypes = {
  5. none: 0,
  6. move: 1,
  7. setState: 2,
  8. fade: 3,
  9. resize: 4,
  10. rotate: 5
  11. };
  12. var animationQueue = {};
  13. // using array as the key doesn't play nice
  14. var nextAnimationId = 1;
  15. var animationsToCount = {};
  16. var actionToActionGroups = {};
  17. var getAnimation = function(id, type) {
  18. return animationQueue[id] && animationQueue[id][type] && animationQueue[id][type][0];
  19. };
  20. var _addAnimation = _action.addAnimation = function (id, type, func, suppressFire) {
  21. var wasEmpty = !getAnimation(id, type);
  22. // Add the func to the queue. Create the queue if necessary.
  23. var idQueue = animationQueue[id];
  24. if(!idQueue) animationQueue[id] = idQueue = {};
  25. var queue = idQueue[type];
  26. if(!queue) idQueue[type] = queue = [];
  27. queue[queue.length] = func;
  28. // If it was empty, there isn't a callback waiting to be called on this. You have to fire it manually.
  29. // If this is waiting on something, suppress it, and it will fire when it's ready
  30. if(wasEmpty && !suppressFire) func();
  31. };
  32. var _addAnimations = function (animations) {
  33. if(animations.length == 1) {
  34. _addAnimation(animations[0].id, animations[0].type, animations[0].func);
  35. return;
  36. }
  37. var allReady = true;
  38. var readyCount = 0;
  39. for(var i = 0; i < animations.length; i++) {
  40. var animation = animations[i];
  41. var thisReady = !getAnimation(animation.id, animation.type);
  42. allReady = allReady && thisReady;
  43. if (thisReady) readyCount++;
  44. else {
  45. var typeToGroups = actionToActionGroups[animation.id];
  46. if (!typeToGroups) actionToActionGroups[animation.id] = typeToGroups = {};
  47. var groups = typeToGroups[animation.type];
  48. if (!groups) typeToGroups[animation.type] = groups = [];
  49. groups[groups.length] = animations;
  50. }
  51. }
  52. for(i = 0; i < animations.length; i++) {
  53. animation = animations[i];
  54. _addAnimation(animation.id, animation.type, animation.func, true);
  55. }
  56. if (allReady) {
  57. for (i = 0; i < animations.length; i++) animations[i].func();
  58. } else {
  59. animations.id = nextAnimationId++;
  60. animationsToCount[animations.id] = readyCount;
  61. }
  62. }
  63. var _fireAnimationFromQueue = _action.fireAnimationFromQueue = function (id, type) {
  64. _removeAnimationFromQueue(id, type);
  65. // Fire the next func if there is one
  66. var func = getAnimation(id, type);
  67. if(func && !_checkFireActionGroup(id, type, func)) func();
  68. };
  69. var _removeAnimationFromQueue = _action.removeAnimationFromQueue = function (id, type) {
  70. if (animationQueue[id] && animationQueue[id][type]) $ax.splice(animationQueue[id][type], 0, 1);
  71. }
  72. var _checkFireActionGroup = function(id, type, func) {
  73. var group = actionToActionGroups[id];
  74. group = group && group[type];
  75. if (!group || group.length == 0) return false;
  76. var animations = group[0];
  77. var found = false;
  78. for (var i = 0; i < animations.length; i++) {
  79. var animation = animations[i];
  80. if (animation.id == id && animation.type == type) {
  81. found = func == animation.func;
  82. break;
  83. }
  84. }
  85. // if found then update this action group, otherwise, keep waiting for right action to fire
  86. if(!found) return false;
  87. $ax.splice(group, 0, 1);
  88. var count = animationsToCount[animations.id] + 1;
  89. if(count != animations.length) {
  90. animationsToCount[animations.id] = count;
  91. return true;
  92. }
  93. delete animationsToCount[animations.id];
  94. // Funcs is needed because an earlier func can try to cascade right away (when no animation for example) and will kill this func and move on to the
  95. // next one (which may not even exist). If we get all funcs before calling any, then we know they are all the func we want.
  96. var funcs = [];
  97. for(i = 0; i < animations.length; i++) {
  98. animation = animations[i];
  99. var func = getAnimation(animation.id, animation.type);
  100. if(func) funcs.push(func);
  101. }
  102. for(i = 0; i < funcs.length; i++) {
  103. funcs[i]();
  104. }
  105. return true;
  106. }
  107. var _refreshing = [];
  108. _action.refreshStart = function(repeaterId) { _refreshing.push(repeaterId); };
  109. _action.refreshEnd = function() { _refreshing.pop(); };
  110. // TODO: [ben] Consider moving this to repeater.js
  111. var _repeatersToRefresh = _action.repeatersToRefresh = [];
  112. var _ignoreAction = function(repeaterId) {
  113. for(var i = 0; i < _refreshing.length; i++) if(_refreshing[i] == repeaterId) return true;
  114. return false;
  115. };
  116. var _addRefresh = function(repeaterId) {
  117. if(_repeatersToRefresh.indexOf(repeaterId) == -1) _repeatersToRefresh.push(repeaterId);
  118. };
  119. var _getIdToResizeMoveState = function(eventInfo) {
  120. if(!eventInfo.idToResizeMoveState) eventInfo.idToResizeMoveState = {};
  121. return eventInfo.idToResizeMoveState;
  122. }
  123. var _queueResizeMove = function (id, type, eventInfo, actionInfo) {
  124. if (type == queueTypes.resize || type == queueTypes.rotate) $ax.public.fn.convertToSingleImage($jobj(id));
  125. var idToResizeMoveState = _getIdToResizeMoveState(eventInfo);
  126. if(!idToResizeMoveState[id]) {
  127. idToResizeMoveState[id] = {};
  128. idToResizeMoveState[id][queueTypes.move] = { queue: [], used: 0 };
  129. idToResizeMoveState[id][queueTypes.resize] = { queue: [], used: 0 };
  130. idToResizeMoveState[id][queueTypes.rotate] = { queue: [], used: 0 };
  131. }
  132. var state = idToResizeMoveState[id];
  133. // If this is not a type being queued (no action of it's type waiting already) then if it is an instant, fire right away.
  134. var myOptions = type == queueTypes.resize ? actionInfo : actionInfo.options;
  135. if(!state[type].queue.length && (!myOptions.easing || myOptions.easing == 'none' || !myOptions.duration)) {
  136. var func = type == queueTypes.resize ? _addResize : type == queueTypes.rotate ? _addRotate : _addMove;
  137. func(id, eventInfo, actionInfo, { easing: 'none', duration: 0, stop: { instant: true } });
  138. return;
  139. }
  140. // Check other 2 types to see if either is empty, if so, we can't do anything, so just queue it up
  141. var otherType1 = type == queueTypes.move ? queueTypes.resize : queueTypes.move;
  142. var otherType2 = type == queueTypes.rotate ? queueTypes.resize : queueTypes.rotate;
  143. if (!state[otherType1].queue.length || !state[otherType2].queue.length) {
  144. state[type].queue.push({ eventInfo: eventInfo, actionInfo: actionInfo });
  145. } else {
  146. var duration = myOptions.duration;
  147. var used1 = state[otherType1].used;
  148. var used2 = state[otherType2].used;
  149. while(state[otherType1].queue.length && state[otherType2].queue.length && duration != 0) {
  150. var other1 = state[otherType1].queue[0];
  151. var otherOptions1 = otherType1 == queueTypes.resize ? other1.actionInfo : other1.actionInfo.options;
  152. // If queue up action is a non animation, then don't combo it, just queue it and move on
  153. if(!otherOptions1.easing || otherOptions1.easing == 'none' || !otherOptions1.duration) {
  154. func = otherType1 == queueTypes.resize ? _addResize : otherType1 == queueTypes.rotate ? _addRotate : _addMove;
  155. func(id, eventInfo, actionInfo, { easing: 'none', duration: 0, stop: { instant: true } });
  156. continue;
  157. }
  158. var other2 = state[otherType2].queue[0];
  159. var otherOptions2 = otherType2 == queueTypes.resize ? other2.actionInfo : other2.actionInfo.options;
  160. // If queue up action is a non animation, then don't combo it, just queue it and move on
  161. if(!otherOptions2.easing || otherOptions2.easing == 'none' || !otherOptions2.duration) {
  162. func = otherType2 == queueTypes.resize ? _addResize : otherType2 == queueTypes.rotate ? _addRotate : _addMove;
  163. func(id, eventInfo, actionInfo, { easing: 'none', duration: 0, stop: { instant: true } });
  164. continue;
  165. }
  166. // Other duration is what is left over. When in queue it may be partly finished already
  167. var otherDuration1 = otherOptions1.duration - used1;
  168. var otherDuration2 = otherOptions2.duration - used2;
  169. var resizeInfo = type == queueTypes.resize ? actionInfo : otherType1 == queueTypes.resize ? other1.actionInfo : other2.actionInfo;
  170. var rotateInfo = type == queueTypes.rotate ? actionInfo : otherType1 == queueTypes.rotate ? other1.actionInfo : other2.actionInfo;
  171. var moveInfo = type == queueTypes.move ? actionInfo : otherType1 == queueTypes.move ? other1.actionInfo : other2.actionInfo;
  172. var options = { easing: moveInfo.options.easing, duration: Math.min(duration, otherDuration1, otherDuration2) };
  173. // Start for self is whole duration - duration left, end is start plus duration of combo to be queued, length is duration
  174. var stop = { start: myOptions.duration - duration, len: myOptions.duration };
  175. stop.end = stop.start + options.duration;
  176. // Start for other is used (will be 0 after 1st round), end is start plus length is duration of combo to be queued, length is other duration
  177. var otherStop1 = { start: used1, end: options.duration + used1, len: otherOptions1.duration };
  178. var otherStop2 = { start: used2, end: options.duration + used2, len: otherOptions2.duration };
  179. options.stop = type == queueTypes.resize ? stop : otherType1 == queueTypes.resize ? otherStop1 : otherStop2;
  180. options.moveStop = type == queueTypes.move ? stop : otherType1 == queueTypes.move ? otherStop1 : otherStop2;
  181. options.rotateStop = type == queueTypes.rotate ? stop : otherType1 == queueTypes.rotate ? otherStop1 : otherStop2;
  182. _addResize(id, eventInfo, resizeInfo, options, moveInfo, rotateInfo);
  183. // Update duration for this animation
  184. duration -= options.duration;
  185. // For others update used and remove from queue if necessary
  186. if(otherDuration1 == options.duration) {
  187. $ax.splice(state[otherType1].queue, 0, 1);
  188. used1 = 0;
  189. } else used1 += options.duration;
  190. if(otherDuration2 == options.duration) {
  191. $ax.splice(state[otherType2].queue, 0, 1);
  192. used2 = 0;
  193. } else used2 += options.duration;
  194. }
  195. // Start queue for new type if necessary
  196. if(duration) {
  197. state[type].queue.push({ eventInfo: eventInfo, actionInfo: actionInfo });
  198. state[type].used = myOptions.duration - duration;
  199. }
  200. // Update used for others
  201. state[otherType1].used = used1;
  202. state[otherType2].used = used2;
  203. }
  204. };
  205. _action.flushAllResizeMoveActions = function (eventInfo) {
  206. var idToResizeMoveState = _getIdToResizeMoveState(eventInfo);
  207. for(var id in idToResizeMoveState) _flushResizeMoveActions(id, idToResizeMoveState);
  208. };
  209. var _flushResizeMoveActions = function(id, idToResizeMoveState) {
  210. var state = idToResizeMoveState[id];
  211. var move = state[queueTypes.move];
  212. var moveInfo = move.queue[0];
  213. var resize = state[queueTypes.resize];
  214. var resizeInfo = resize.queue[0];
  215. var rotate = state[queueTypes.rotate];
  216. var rotateInfo = rotate.queue[0];
  217. while (moveInfo || resizeInfo || rotateInfo) {
  218. var eventInfo = moveInfo ? moveInfo.eventInfo : resizeInfo ? resizeInfo.eventInfo : rotateInfo.eventInfo;
  219. moveInfo = moveInfo && moveInfo.actionInfo;
  220. resizeInfo = resizeInfo && resizeInfo.actionInfo;
  221. rotateInfo = rotateInfo && rotateInfo.actionInfo;
  222. // Resize is used by default, then rotate
  223. if(resizeInfo) {
  224. // Check for instant resize
  225. if(!resizeInfo.duration || resizeInfo.easing == 'none') {
  226. _addResize(id, resize.queue[0].eventInfo, resizeInfo, { easing: 'none', duration: 0, stop: { instant: true } });
  227. _updateResizeMoveUsed(id, queueTypes.resize, 0, idToResizeMoveState);
  228. resizeInfo = resize.queue[0];
  229. continue;
  230. }
  231. var duration = resizeInfo.duration - resize.used;
  232. if(moveInfo) duration = Math.min(duration, moveInfo.options.duration - move.used);
  233. if(rotateInfo) duration = Math.min(duration, rotateInfo.options.duration - rotate.used);
  234. var baseOptions = moveInfo ? moveInfo.options : resizeInfo;
  235. var options = { easing: baseOptions.easing, duration: duration };
  236. options.stop = { start: resize.used, end: resize.used + duration, len: resizeInfo.duration };
  237. if(moveInfo) options.moveStop = { start: move.used, end: move.used + duration, len: moveInfo.options.duration };
  238. if(rotateInfo) options.rotateStop = { start: rotate.used, end: rotate.used + duration, len: rotateInfo.options.duration };
  239. _addResize(id, eventInfo, resizeInfo, options, moveInfo, rotateInfo);
  240. _updateResizeMoveUsed(id, queueTypes.resize, duration, idToResizeMoveState);
  241. resizeInfo = resize.queue[0];
  242. if(rotateInfo) {
  243. _updateResizeMoveUsed(id, queueTypes.rotate, duration, idToResizeMoveState);
  244. rotateInfo = rotate.queue[0];
  245. }
  246. if(moveInfo) {
  247. _updateResizeMoveUsed(id, queueTypes.move, duration, idToResizeMoveState);
  248. moveInfo = move.queue[0];
  249. }
  250. } else if (rotateInfo) {
  251. // Check for instant rotate
  252. if(!rotateInfo.options.duration || rotateInfo.options.easing == 'none') {
  253. _addRotate(id, rotate.queue[0].eventInfo, rotateInfo, { easing: 'none', duration: 0, stop: { instant: true } });
  254. _updateResizeMoveUsed(id, queueTypes.rotate, 0, idToResizeMoveState);
  255. rotateInfo = rotate.queue[0];
  256. continue;
  257. }
  258. duration = rotateInfo.options.duration - rotate.used;
  259. if(moveInfo) duration = Math.min(duration, moveInfo.options.duration - move.used);
  260. baseOptions = moveInfo ? moveInfo.options : rotateInfo.options;
  261. options = { easing: baseOptions.easing, duration: duration };
  262. options.stop = { start: rotate.used, end: rotate.used + duration, len: rotateInfo.options.duration };
  263. if(moveInfo) options.moveStop = { start: move.used, end: move.used + duration, len: moveInfo.options.duration };
  264. _addRotate(id, eventInfo, rotateInfo, options, moveInfo);
  265. _updateResizeMoveUsed(id, queueTypes.rotate, duration, idToResizeMoveState);
  266. rotateInfo = rotate.queue[0];
  267. if(moveInfo) {
  268. _updateResizeMoveUsed(id, queueTypes.move, duration, idToResizeMoveState);
  269. moveInfo = move.queue[0];
  270. }
  271. } else {
  272. if(!moveInfo.options.duration || moveInfo.options.easing == 'none') {
  273. _addMove(id, eventInfo, moveInfo, { easing: 'none', duration: 0, stop: { instant: true } });
  274. _updateResizeMoveUsed(id, queueTypes.move, 0, idToResizeMoveState);
  275. moveInfo = move.queue[0];
  276. continue;
  277. }
  278. duration = moveInfo.options.duration - move.used;
  279. options = { easing: moveInfo.options.easing, duration: duration };
  280. options.stop = { start: move.used, end: moveInfo.options.duration, len: moveInfo.options.duration };
  281. _addMove(id, eventInfo, moveInfo, options);
  282. _updateResizeMoveUsed(id, queueTypes.move, duration, idToResizeMoveState);
  283. moveInfo = move.queue[0];
  284. }
  285. }
  286. };
  287. var _updateResizeMoveUsed = function(id, type, duration, idToResizeMoveState) {
  288. var state = idToResizeMoveState[id][type];
  289. state.used += duration;
  290. var options = state.queue[0].actionInfo;
  291. if(options.options) options = options.options;
  292. var optionDur = (options.easing && options.easing != 'none' && options.duration) || 0;
  293. if(optionDur <= state.used) {
  294. $ax.splice(state.queue, 0, 1);
  295. state.used = 0;
  296. }
  297. }
  298. var _dispatchAction = $ax.action.dispatchAction = function(eventInfo, actions, currentIndex) {
  299. currentIndex = currentIndex || 0;
  300. //If no actions, you can bubble
  301. if(currentIndex >= actions.length) return;
  302. //actions are responsible for doing their own dispatching
  303. _actionHandlers[actions[currentIndex].action](eventInfo, actions, currentIndex);
  304. };
  305. _actionHandlers.wait = function(eventInfo, actions, index) {
  306. var action = actions[index];
  307. var infoCopy = $ax.eventCopy(eventInfo);
  308. window.setTimeout(function() {
  309. infoCopy.now = new Date();
  310. infoCopy.idToResizeMoveState = undefined;
  311. _dispatchAction(infoCopy, actions, index + 1);
  312. _action.flushAllResizeMoveActions(infoCopy);
  313. }, action.waitTime);
  314. };
  315. _actionHandlers.expr = function(eventInfo, actions, index) {
  316. var action = actions[index];
  317. $ax.expr.evaluateExpr(action.expr, eventInfo); //this should be a block
  318. _dispatchAction(eventInfo, actions, index + 1);
  319. };
  320. _actionHandlers.setFunction = _actionHandlers.expr;
  321. _actionHandlers.linkWindow = function(eventInfo, actions, index) {
  322. linkActionHelper(eventInfo, actions, index);
  323. };
  324. _actionHandlers.closeCurrent = function(eventInfo, actions, index) {
  325. $ax.closeWindow();
  326. _dispatchAction(eventInfo, actions, index + 1);
  327. };
  328. _actionHandlers.linkFrame = function(eventInfo, actions, index) {
  329. linkActionHelper(eventInfo, actions, index);
  330. };
  331. _actionHandlers.setAdaptiveView = function(eventInfo, actions, index) {
  332. var action = actions[index];
  333. var view = action.setAdaptiveViewTo;
  334. if(view) $ax.adaptive.setAdaptiveView(view);
  335. };
  336. var linkActionHelper = function(eventInfo, actions, index) {
  337. var action = actions[index];
  338. eventInfo.link = true;
  339. if(action.linkType != 'frame') {
  340. var includeVars = _includeVars(action.target, eventInfo);
  341. if(action.target.targetType == "reloadPage") {
  342. $ax.reload(action.target.includeVariables);
  343. } else if(action.target.targetType == "backUrl") {
  344. $ax.back();
  345. }
  346. var url = action.target.url;
  347. if(!url && action.target.urlLiteral) {
  348. url = $ax.expr.evaluateExpr(action.target.urlLiteral, eventInfo, true);
  349. }
  350. if(url) {
  351. let useStartHtml = shouldUseStartHtml(action);
  352. if(useStartHtml) {
  353. //use start.html to load player
  354. url = urlWithStartHtml(url);
  355. //collapse player for popup
  356. if(action.linkType == "popup") url = urlWithCollapseSitemap(url);
  357. }
  358. //set useGlobalVarNameInUrl to true to use GLOBAL_VAR_NAME in the url, so player knows how to parse it
  359. //without this, we are assuming everything after '#' are global vars
  360. if(action.linkType == "popup") {
  361. $ax.navigate({
  362. url: url,
  363. target: action.linkType,
  364. includeVariables: includeVars,
  365. popupOptions: action.popup,
  366. useGlobalVarNameInUrl : useStartHtml
  367. });
  368. } else {
  369. $ax.navigate({
  370. url: url,
  371. target: action.linkType,
  372. includeVariables: includeVars,
  373. useGlobalVarNameInUrl : useStartHtml
  374. });
  375. }
  376. }
  377. } else linkFrame(eventInfo, action);
  378. eventInfo.link = false;
  379. _dispatchAction(eventInfo, actions, index + 1);
  380. };
  381. //use start.html will add a player to the prototype
  382. var shouldUseStartHtml = function(linkAction) {
  383. return linkAction.target.targetType == 'page' //only adding player for page, not external links
  384. && (linkAction.linkType == "popup" || linkAction.linkType == "new") //only add for popup and new tabs
  385. && $axure.utils.isInPlayer() //allow user to view without player (maybe useful for user testing)
  386. && !$axure.utils.isShareApp() //share app use special handling on its link, add start.html breaks the handling
  387. }
  388. var urlWithStartHtml = function(url) {
  389. var pageName = url.substring(0, url.lastIndexOf('.html'));
  390. var pageQuery = $axure.utils.setHashStringVar(START_URL_NAME, PAGE_URL_NAME, pageName);
  391. return START_URL_NAME + pageQuery;
  392. }
  393. var urlWithCollapseSitemap = function(url) {
  394. return url + '&' + SITEMAP_COLLAPSE_VAR_NAME + '=' + SITEMAP_COLLAPSE_VALUE;
  395. }
  396. var _includeVars = function(target, eventInfo) {
  397. if(target.includeVariables) return true;
  398. // If it is a url literal, that is a string literal, that has only 1 sto, that is an item that is a page, include vars.
  399. if(target.urlLiteral) {
  400. var literal = target.urlLiteral;
  401. var sto = literal.stos[0];
  402. if(literal.exprType == 'stringLiteral' && literal.value.indexOf('[[') == 0 && literal.value.indexOf(']]' == literal.value.length - 2) && literal.stos.length == 1 && sto.sto == 'item' && eventInfo.item) {
  403. var data = $ax.repeater.getData(eventInfo, eventInfo.item.repeater.elementId, eventInfo.item.index, sto.name, 'data');
  404. if (data && $ax.public.fn.IsPage(data.type)) return true;
  405. }
  406. }
  407. return false;
  408. };
  409. var linkFrame = function(eventInfo, action) {
  410. for(var i = 0; i < action.framesToTargets.length; i++) {
  411. var framePath = action.framesToTargets[i].framePath;
  412. var target = action.framesToTargets[i].target;
  413. var includeVars = _includeVars(target, eventInfo);
  414. var url = target.url;
  415. if(!url && target.urlLiteral) {
  416. url = $ax.expr.evaluateExpr(target.urlLiteral, eventInfo, true);
  417. }
  418. var id = $ax.getElementIdsFromPath(framePath, eventInfo)[0];
  419. if(id) $ax('#' + $ax.INPUT(id)).openLink(url, includeVars);
  420. }
  421. };
  422. var _repeatPanelMap = {};
  423. _actionHandlers.setPanelState = function(eventInfo, actions, index) {
  424. var action = actions[index];
  425. for(var i = 0; i < action.panelsToStates.length; i++) {
  426. var panelToState = action.panelsToStates[i];
  427. var stateInfo = panelToState.stateInfo;
  428. var elementIds = $ax.getElementIdsFromPath(panelToState.panelPath, eventInfo);
  429. for(var j = 0; j < elementIds.length; j++) {
  430. var elementId = elementIds[j];
  431. var oldTarget = eventInfo.targetElement;
  432. eventInfo.targetElement = elementId;
  433. // Need new scope for elementId and info
  434. (function(elementId, stateInfo) {
  435. _addAnimation(elementId, queueTypes.setState, function () {
  436. var stateNumber = stateInfo.stateNumber;
  437. if(stateInfo.setStateType == "value") {
  438. var stateName = $ax.expr.evaluateExpr(stateInfo.stateValue, eventInfo);
  439. // Try for state name first
  440. var states = $ax.getObjectFromElementId(elementId).diagrams;
  441. var stateNameFound = false;
  442. for(var k = 0; k < states.length; k++) {
  443. if(states[k].label == stateName) {
  444. stateNumber = k + 1;
  445. stateNameFound = true;
  446. }
  447. }
  448. // Now check for index
  449. if(!stateNameFound) {
  450. stateNumber = Number(stateName);
  451. var panelCount = $('#' + elementId).children().length;
  452. // Make sure number is not NaN, is in range, and is a whole number.
  453. // Wasn't a state name or number, so return
  454. if(isNaN(stateNumber) || stateNumber <= 0 || stateNumber > panelCount || Math.round(stateNumber) != stateNumber) return _fireAnimationFromQueue(elementId, queueTypes.setState);
  455. }
  456. } else if(stateInfo.setStateType == 'next' || stateInfo.setStateType == 'previous') {
  457. var info = $ax.deepCopy(stateInfo);
  458. var repeat = info.repeat;
  459. // Only map it, if repeat exists.
  460. if(typeof (repeat) == 'number') _repeatPanelMap[elementId] = info;
  461. return _progessPanelState(elementId, info, eventInfo, info.repeatSkipFirst);
  462. }
  463. delete _repeatPanelMap[elementId];
  464. // If setting to current (to stop repeat) break here
  465. if(stateInfo.setStateType == 'current') return _fireAnimationFromQueue(elementId, queueTypes.setState);
  466. $ax('#' + elementId).SetPanelState(stateNumber, stateInfo.options, eventInfo, stateInfo.showWhenSet);
  467. });
  468. })(elementId, stateInfo);
  469. eventInfo.targetElement = oldTarget;
  470. }
  471. }
  472. _dispatchAction(eventInfo, actions, index + 1);
  473. };
  474. var _progessPanelState = function(id, stateInfo, eventInfo, skipFirst) {
  475. var direction = stateInfo.setStateType;
  476. var loop = stateInfo.loop;
  477. var repeat = stateInfo.repeat;
  478. var options = stateInfo.options;
  479. var hasRepeat = typeof (repeat) == 'number';
  480. var currentStateId = $ax.visibility.GetPanelState(id);
  481. var stateNumber = '';
  482. if(currentStateId != '') {
  483. currentStateId = $ax.repeater.getScriptIdFromElementId(currentStateId);
  484. var currentStateNumber = Number(currentStateId.substr(currentStateId.indexOf('state') + 5));
  485. if(direction == "next") {
  486. stateNumber = currentStateNumber + 2;
  487. if(stateNumber > $ax.visibility.GetPanelStateCount(id)) {
  488. if(loop) stateNumber = 1;
  489. else {
  490. delete _repeatPanelMap[id];
  491. return _fireAnimationFromQueue(id, queueTypes.setState);
  492. }
  493. }
  494. } else if(direction == "previous") {
  495. stateNumber = currentStateNumber;
  496. if(stateNumber <= 0) {
  497. if(loop) stateNumber = $ax.visibility.GetPanelStateCount(id);
  498. else {
  499. delete _repeatPanelMap[id];
  500. return _fireAnimationFromQueue(id, queueTypes.setState);
  501. }
  502. }
  503. }
  504. if(hasRepeat && _repeatPanelMap[id] != stateInfo) return _fireAnimationFromQueue(id, queueTypes.setState);
  505. if (!skipFirst) $ax('#' + id).SetPanelState(stateNumber, options, eventInfo, stateInfo.showWhenSet);
  506. else _fireAnimationFromQueue(id, queueTypes.setState);
  507. if(hasRepeat) {
  508. var animate = options && options.animateIn;
  509. if(animate && animate.easing && animate.easing != 'none' && animate.duration > repeat) repeat = animate.duration;
  510. animate = options && options.animateOut;
  511. if(animate && animate.easing && animate.easing != 'none' && animate.duration > repeat) repeat = animate.duration;
  512. window.setTimeout(function() {
  513. // Either new repeat, or no repeat anymore.
  514. if(_repeatPanelMap[id] != stateInfo) return;
  515. _addAnimation(id, queueTypes.setState, function() {
  516. _progessPanelState(id, stateInfo, eventInfo, false);
  517. });
  518. }, repeat);
  519. } else delete _repeatPanelMap[id];
  520. }
  521. };
  522. _actionHandlers.fadeWidget = function(eventInfo, actions, index) {
  523. var action = actions[index];
  524. for(var i = 0; i < action.objectsToFades.length; i++) {
  525. var fadeInfo = action.objectsToFades[i].fadeInfo;
  526. var elementIds = $ax.getElementIdsFromPath(action.objectsToFades[i].objectPath, eventInfo);
  527. for(var j = 0; j < elementIds.length; j++) {
  528. var elementId = elementIds[j];
  529. // Need new scope for elementId and info
  530. (function(elementId, fadeInfo) {
  531. _addAnimation(elementId, queueTypes.fade, function () {
  532. if (fadeInfo.options.compress && fadeInfo.options.compressDistanceType == "custom") {
  533. var oldTarget = eventInfo.targetElement;
  534. eventInfo.targetElement = elementId;
  535. fadeInfo.options.compressDelta = Number($ax.expr.evaluateExpr(fadeInfo.options.compressValue, eventInfo));
  536. eventInfo.targetElement = oldTarget;
  537. }
  538. if(fadeInfo.fadeType == "hide") {
  539. $ax('#' + elementId).hide(fadeInfo.options);
  540. } else if(fadeInfo.fadeType == "show") {
  541. $ax('#' + elementId).show(fadeInfo.options, eventInfo);
  542. } else if(fadeInfo.fadeType == "toggle") {
  543. $ax('#' + elementId).toggleVisibility(fadeInfo.options);
  544. }
  545. });
  546. })(elementId, fadeInfo);
  547. }
  548. }
  549. _dispatchAction(eventInfo, actions, index + 1);
  550. };
  551. _actionHandlers.applyStyle = function (eventInfo, actions, index) {
  552. var action = actions[index];
  553. for (var i = 0; i < action.objectsToStyleApply.length; i++) {
  554. var applyStyleInfo = action.objectsToStyleApply[i].applyStyleInfo;
  555. var elementIds = $ax.getElementIdsFromPath(action.objectsToStyleApply[i].objectPath, eventInfo);
  556. if (elementIds.length == 0) return;
  557. var firstId = elementIds[0];
  558. if (!$ax.style.isLastAppliedStyle(firstId, applyStyleInfo.className)) {
  559. $ax.style.setApplyStyleTag(applyStyleInfo.className, applyStyleInfo.cssRule);
  560. }
  561. for (var j = 0; j < elementIds.length; j++) {
  562. var id = elementIds[j];
  563. if ($ax.public.fn.IsLayer($obj(id).type)) {
  564. var childrenIds = $ax.public.fn.getLayerChildrenDeep(id, true);
  565. for (var n = 0; n < childrenIds.length; n++) {
  566. $ax.style.applyWidgetStyle(childrenIds[n], applyStyleInfo.className, applyStyleInfo.style, applyStyleInfo.image, applyStyleInfo.clearPrevious);
  567. }
  568. } else $ax.style.applyWidgetStyle(id, applyStyleInfo.className, applyStyleInfo.style, applyStyleInfo.image, applyStyleInfo.clearPrevious);
  569. }
  570. }
  571. _dispatchAction(eventInfo, actions, index + 1);
  572. }
  573. _actionHandlers.setOpacity = function(eventInfo, actions, index) {
  574. var action = actions[index];
  575. for(var i = 0; i < action.objectsToSetOpacity.length; i++) {
  576. var opacityInfo = action.objectsToSetOpacity[i].opacityInfo;
  577. var elementIds = $ax.getElementIdsFromPath(action.objectsToSetOpacity[i].objectPath, eventInfo);
  578. for(var j = 0; j < elementIds.length; j++) {
  579. var elementId = elementIds[j];
  580. (function(elementId, opacityInfo) {
  581. _addAnimation(elementId, queueTypes.fade, function () {
  582. var oldTarget = eventInfo.targetElement;
  583. eventInfo.targetElement = elementId;
  584. var opacity = $ax.expr.evaluateExpr(opacityInfo.opacity, eventInfo);
  585. eventInfo.targetElement = oldTarget;
  586. opacity = Math.min(100, Math.max(0, opacity));
  587. $ax('#' + elementId).setOpacity(opacity/100, opacityInfo.easing, opacityInfo.duration);
  588. })
  589. })(elementId, opacityInfo);
  590. }
  591. }
  592. _dispatchAction(eventInfo, actions, index + 1);
  593. }
  594. _actionHandlers.moveWidget = function(eventInfo, actions, index) {
  595. var action = actions[index];
  596. for(var i = 0; i < action.objectsToMoves.length; i++) {
  597. var moveInfo = action.objectsToMoves[i].moveInfo;
  598. var objPath = action.objectsToMoves[i].objectPath;
  599. var below = objPath == 'widgetsBelow';
  600. var right = objPath == 'widgetsRight';
  601. if (right || below) {
  602. var isDelta = moveInfo.moveType == 'delta';
  603. var xDelta = isDelta ? Number($ax.expr.evaluateExpr(moveInfo.xValue, eventInfo)) : NaN;
  604. var yDelta = isDelta ? Number($ax.expr.evaluateExpr(moveInfo.yValue, eventInfo)) : NaN;
  605. var srcId = eventInfo.srcElement;
  606. var isResize = action.parentEventType == 'onResize' || action.parentEventType == 'onPanelStateChange';
  607. //if it's resizing, use the old rect for the threshold and clamp; otherwise, use the current rect
  608. var obj = $obj(srcId);
  609. var clampRect = $ax('#' + srcId).offsetBoundingRect(true);
  610. if(isResize) {
  611. var oldRect = $ax.visibility.getResizingRect(srcId);
  612. if(oldRect) clampRect = oldRect;
  613. }
  614. $ax.dynamicPanelManager.compressMove(srcId, below, isResize, clampRect, moveInfo.options.easing, moveInfo.options.duration, below ? yDelta : xDelta, below ? xDelta : yDelta);
  615. continue;
  616. }
  617. var elementIds = $ax.getElementIdsFromPath(objPath, eventInfo);
  618. for(var j = 0; j < elementIds.length; j++) {
  619. var elementId = elementIds[j];
  620. _queueResizeMove(elementId, queueTypes.move, eventInfo, moveInfo);
  621. //_addMove(eventInfo, elementId, moveInfo, eventInfo.dragInfo);
  622. }
  623. }
  624. _dispatchAction(eventInfo, actions, index + 1);
  625. };
  626. //var _compoundChildrenShallow = function (id) {
  627. // var deep = [];
  628. // var children = $ax('#' + id).getChildren()[0].children;
  629. // var piecePrefix = id + 'p';
  630. // for (var i = 0; i < children.length; i++) {
  631. // if(children[i].substring(0, id.length + 1) == piecePrefix) {
  632. // deep.push(children[i]);
  633. // }
  634. // }
  635. // return deep;
  636. //};
  637. var _addMove = function (elementId, eventInfo, moveInfo, optionsOverride) {
  638. var eventInfoCopy = $ax.eventCopy(eventInfo);
  639. var idToResizeMoveState = _getIdToResizeMoveState(eventInfoCopy);
  640. eventInfoCopy.targetElement = elementId;
  641. var options = $ax.deepCopy(moveInfo.options);
  642. options.easing = optionsOverride.easing;
  643. options.duration = optionsOverride.duration;
  644. options.dragInfo = eventInfo.dragInfo;
  645. if($ax.public.fn.IsLayer($obj(elementId).type)) {
  646. var childrenIds = $ax.public.fn.getLayerChildrenDeep(elementId, true);
  647. if(childrenIds.length == 0) return;
  648. var animations = [];
  649. // Get move delta once, then apply to all children
  650. animations.push({
  651. id: elementId,
  652. type: queueTypes.move,
  653. func: function () {
  654. var layerInfo = $ax('#' + elementId).offsetBoundingRect();
  655. //var layerInfo = $ax.public.fn.getWidgetBoundingRect(elementId);
  656. var deltaLoc = _getMoveLoc(elementId, moveInfo, eventInfoCopy, optionsOverride.stop, idToResizeMoveState[elementId], options, layerInfo);
  657. // $ax.event.raiseSyntheticEvent(elementId, "onMove");
  658. $ax.visibility.pushContainer(elementId, false);
  659. options.onComplete = function () {
  660. _fireAnimationFromQueue(elementId, queueTypes.move);
  661. $ax.visibility.popContainer(elementId, false);
  662. };
  663. $ax('#' + elementId).moveBy(deltaLoc.x, deltaLoc.y, options);
  664. }
  665. });
  666. //for(var i = 0; i < childrenIds.length; i++) {
  667. // (function(childId) {
  668. // animations.push({
  669. // id: childId,
  670. // type: queueTypes.move,
  671. // func: function () {
  672. // // Nop, while trying to move as container
  673. // //$ax.event.raiseSyntheticEvent(childId, "onMove");
  674. // //if($ax.public.fn.IsLayer($obj(childId).type)) _fireAnimationFromQueue(childId, queueTypes.move);
  675. // //else $ax('#' + childId).moveBy(deltaLoc.x, deltaLoc.y, moveInfo.options);
  676. // }
  677. // });
  678. // })(childrenIds[i]);
  679. //}
  680. _addAnimations(animations);
  681. } else {
  682. _addAnimation(elementId, queueTypes.move, function() {
  683. var loc = _getMoveLoc(elementId, moveInfo, eventInfoCopy, optionsOverride.stop, idToResizeMoveState[elementId], options);
  684. // $ax.event.raiseSyntheticEvent(elementId, "onMove");
  685. if(loc.moveTo) $ax('#' + elementId).moveTo(loc.x, loc.y, options);
  686. else $ax('#' + elementId).moveBy(loc.x, loc.y, options);
  687. });
  688. }
  689. };
  690. var _moveSingleWidget = function (elementId, delta, options, onComplete) {
  691. if(!delta.x && !delta.y) {
  692. $ax.action.fireAnimationFromQueue(elementId, $ax.action.queueTypes.move);
  693. if (onComplete) onComplete();
  694. return;
  695. }
  696. var fixedInfo = $ax.dynamicPanelManager.getFixedInfo(elementId);
  697. var xProp = 'left';
  698. var xDiff = '+=';
  699. if(fixedInfo) {
  700. if(fixedInfo.horizontal == 'right') {
  701. xProp = 'right';
  702. xDiff = '-=';
  703. } else if(fixedInfo.horizontal == 'center') {
  704. xProp = 'margin-left';
  705. }
  706. }
  707. var yProp = 'top';
  708. var yDiff = '+=';
  709. if(fixedInfo) {
  710. if(fixedInfo.vertical == 'bottom') {
  711. yProp = 'bottom';
  712. yDiff = '-=';
  713. } else if(fixedInfo.vertical == 'middle') {
  714. yProp = 'margin-top';
  715. }
  716. }
  717. var css = {};
  718. css[xProp] = xDiff + delta.x;
  719. css[yProp] = yDiff + delta.y;
  720. $ax.visibility.moveMovedLocation(elementId, delta.x, delta.y);
  721. var moveInfo = $ax.move.PrepareForMove(elementId, delta.x, delta.y,false, options);
  722. $jobjAll(elementId).animate(css, {
  723. duration: options.duration,
  724. easing: options.easing,
  725. queue: false,
  726. complete: function () {
  727. if(onComplete) onComplete();
  728. if(moveInfo.rootLayer) $ax.visibility.popContainer(moveInfo.rootLayer, false);
  729. $ax.dynamicPanelManager.fitParentPanel(elementId);
  730. $ax.action.fireAnimationFromQueue(elementId, $ax.action.queueTypes.move);
  731. }
  732. });
  733. }
  734. var _getMoveLoc = function (elementId, moveInfo, eventInfoCopy, stopInfo, comboState, options, layerInfo) {
  735. var moveTo = false;
  736. var moveWithThis = false;
  737. var xValue = 0;
  738. var yValue = 0;
  739. var moveResult = comboState.moveResult;
  740. var widgetDragInfo = eventInfoCopy.dragInfo;
  741. var jobj = $jobj(elementId);
  742. var startX;
  743. var startY;
  744. var win = ((SAFARI && IOS) || SHARE_APP) ? $('#ios-safari-html') : $(window)
  745. switch(moveInfo.moveType) {
  746. case "location":
  747. // toRatio is ignoring anything before start since that has already taken effect we just know whe have from start to len to finish
  748. // getting to the location we want to get to.
  749. var toRatio = stopInfo.instant ? 1 : (stopInfo.end - stopInfo.start) / (stopInfo.len - stopInfo.start);
  750. // If result already caluculated, don't recalculate again, other calculate and save
  751. if (moveResult) {
  752. xValue = moveResult.x;
  753. yValue = moveResult.y;
  754. } else {
  755. comboState.moveResult = moveResult = { x: $ax.expr.evaluateExpr(moveInfo.xValue, eventInfoCopy), y: $ax.expr.evaluateExpr(moveInfo.yValue, eventInfoCopy) };
  756. xValue = moveResult.x;
  757. yValue = moveResult.y;
  758. }
  759. // If this is final stop for this move, then clear out the result so next move won't use it
  760. if(stopInfo.instant || stopInfo.end == stopInfo.len) comboState.moveResult = undefined;
  761. if (layerInfo) {
  762. startX = layerInfo.left;
  763. startY = layerInfo.top;
  764. //} else if ($ax.public.fn.isCompoundVectorHtml(jobj[0])) {
  765. // var dimensions = $ax.public.fn.compoundWidgetDimensions(jobj);
  766. // startX = dimensions.left;
  767. // startY = dimensions.top;
  768. } else {
  769. var offsetLocation = $ax('#' + elementId).offsetLocation();
  770. startX = offsetLocation.left;
  771. startY = offsetLocation.top;
  772. //startX = $ax('#' + elementId).locRelativeIgnoreLayer(false);
  773. //startY = $ax('#' + elementId).locRelativeIgnoreLayer(true);
  774. if(jobj.css('position') == 'fixed') {
  775. startX -= win.scrollLeft();
  776. startY -= win.scrollTop();
  777. }
  778. }
  779. xValue = xValue == '' ? 0 : (xValue - startX) * toRatio;
  780. yValue = yValue == '' ? 0 : (yValue - startY) * toRatio;
  781. break;
  782. case "delta":
  783. var ratio = stopInfo.instant ? 1 : (stopInfo.end - stopInfo.start) / stopInfo.len;
  784. // See case location above
  785. if(moveResult) {
  786. xValue = moveResult.x * ratio;
  787. yValue = moveResult.y * ratio;
  788. } else {
  789. comboState.moveResult = moveResult = { x: $ax.expr.evaluateExpr(moveInfo.xValue, eventInfoCopy), y: $ax.expr.evaluateExpr(moveInfo.yValue, eventInfoCopy) };
  790. xValue = moveResult.x * ratio;
  791. yValue = moveResult.y * ratio;
  792. }
  793. if (stopInfo.instant || stopInfo.end == stopInfo.len) comboState.moveResult = undefined;
  794. break;
  795. case "drag":
  796. xValue = widgetDragInfo.xDelta;
  797. yValue = widgetDragInfo.yDelta;
  798. break;
  799. case "dragX":
  800. xValue = widgetDragInfo.xDelta;
  801. yValue = 0;
  802. break;
  803. case "dragY":
  804. xValue = 0;
  805. yValue = widgetDragInfo.yDelta;
  806. break;
  807. case "locationBeforeDrag":
  808. var location = widgetDragInfo.movedWidgets[eventInfoCopy.targetElement];
  809. if (location) {
  810. var axObj = $ax('#' + eventInfoCopy.targetElement);
  811. //This may require using the css value
  812. var viewportLocation = axObj.viewportLocation();
  813. xValue = location.x - viewportLocation.left;
  814. yValue = location.y - viewportLocation.top;
  815. //xValue = location.x - axObj.left();
  816. //yValue = location.y - axObj.top();
  817. } else {
  818. _fireAnimationFromQueue(eventInfoCopy.srcElement, queueTypes.move);
  819. return { x: 0, y: 0 };
  820. }
  821. //moveTo = true;
  822. break;
  823. case "withThis":
  824. moveWithThis = true;
  825. var widgetMoveInfo = $ax.move.GetWidgetMoveInfo();
  826. var srcElementId = $ax.getElementIdsFromEventAndScriptId(eventInfoCopy, eventInfoCopy.srcElement)[0];
  827. var delta = widgetMoveInfo[srcElementId];
  828. options.easing = delta.options.easing;
  829. options.duration = delta.options.duration;
  830. xValue = delta.x;
  831. yValue = delta.y;
  832. break;
  833. //sizeDeltaX and sizeDeltaY do not pass through here
  834. }
  835. if (options && options.boundaryExpr) {
  836. //$ax.public.fn.removeCompound(jobj);
  837. //if(jobj.css('position') == 'fixed') {
  838. // //swap page coordinates with fixed coordinates
  839. // options.boundaryExpr.leftExpr.value = options.boundaryExpr.leftExpr.value.replace('.top', '.topfixed').replace('.left', '.leftfixed').replace('.bottom', '.bottomfixed').replace('.right', '.rightfixed');
  840. // options.boundaryExpr.leftExpr.stos[0].leftSTO.prop = options.boundaryExpr.leftExpr.stos[0].leftSTO.prop + 'fixed';
  841. // options.boundaryStos.boundaryScope.direcval0.value = options.boundaryStos.boundaryScope.direcval0.value.replace('.top', '.topfixed').replace('.left', '.leftfixed').replace('.bottom', '.bottomfixed').replace('.right', '.rightfixed');
  842. // options.boundaryStos.boundaryScope.direcval0.stos[0].leftSTO.prop = options.boundaryStos.boundaryScope.direcval0.stos[0].leftSTO.prop + 'fixed';
  843. //}
  844. if(moveWithThis && (xValue || yValue)) {
  845. _updateLeftExprVariable(options.boundaryExpr, xValue.toString(), yValue.toString());
  846. }
  847. if(!$ax.expr.evaluateExpr(options.boundaryExpr, eventInfoCopy)) {
  848. var boundaryStoInfo = options.boundaryStos;
  849. if(boundaryStoInfo) {
  850. if(moveWithThis) {
  851. var stoScopes = boundaryStoInfo.boundaryScope;
  852. if(stoScopes) {
  853. for(var s in stoScopes) {
  854. var boundaryScope = stoScopes[s];
  855. if(!boundaryScope.localVariables) continue;
  856. if(boundaryScope.localVariables.withx) boundaryScope.localVariables.withx.value = xValue.toString();
  857. if(boundaryScope.localVariables.withy) boundaryScope.localVariables.withy.value = yValue.toString();
  858. }
  859. }
  860. }
  861. if(layerInfo) {
  862. startX = layerInfo.left;
  863. startY = layerInfo.top;
  864. } else {
  865. offsetLocation = $ax('#' + elementId).offsetLocation();
  866. startX = offsetLocation.left;
  867. startY = offsetLocation.top;
  868. //startX = $ax('#' + elementId).locRelativeIgnoreLayer(false);
  869. //startY = $ax('#' + elementId).locRelativeIgnoreLayer(true);
  870. if(jobj.css('position') == 'fixed') {
  871. startX -= win.scrollLeft();
  872. startY -= win.scrollTop();
  873. }
  874. }
  875. if(boundaryStoInfo.ySto) {
  876. var currentTop = layerInfo ? layerInfo.top : startY;
  877. var newTop = $ax.evaluateSTO(boundaryStoInfo.ySto, boundaryStoInfo.boundaryScope, eventInfoCopy);
  878. if(moveTo) yValue = newTop;
  879. else yValue = newTop - currentTop;
  880. }
  881. if(boundaryStoInfo.xSto) {
  882. var currentLeft = layerInfo ? layerInfo.left : startX;
  883. var newLeft = $ax.evaluateSTO(boundaryStoInfo.xSto, boundaryStoInfo.boundaryScope, eventInfoCopy);
  884. if(moveTo) xValue = newLeft;
  885. else xValue = newLeft - currentLeft;
  886. }
  887. }
  888. }
  889. //$ax.public.fn.restoreCompound(jobj);
  890. }
  891. return { x: Number(xValue), y: Number(yValue), moveTo: moveTo };
  892. };
  893. //we will have something like [[Target.right + withX]] for leftExpr, and this function set the value of withX
  894. var _updateLeftExprVariable = function (exprTree, xValue, yValue) {
  895. if(exprTree.leftExpr && !exprTree.leftExpr.op) {
  896. var localVars = exprTree.leftExpr.localVariables;
  897. if(localVars) {
  898. if(localVars.withx) localVars.withx.value = xValue;
  899. if(localVars.withy) localVars.withy.value = yValue;
  900. }
  901. }
  902. //traversal
  903. if(exprTree.op) {
  904. if(exprTree.leftExpr) _updateLeftExprVariable(exprTree.leftExpr, xValue, yValue);
  905. if(exprTree.rightExpr) _updateLeftExprVariable(exprTree.rightExpr, xValue, yValue);
  906. }
  907. }
  908. var widgetRotationFilter = [
  909. $ax.constants.IMAGE_BOX_TYPE, $ax.constants.IMAGE_MAP_REGION_TYPE, $ax.constants.DYNAMIC_PANEL_TYPE,
  910. $ax.constants.VECTOR_SHAPE_TYPE, $ax.constants.VERTICAL_LINE_TYPE, $ax.constants.HORIZONTAL_LINE_TYPE
  911. //,$ax.constants.REFERENCE_DIAGRAM_OBJECT_TYPE
  912. ];
  913. _actionHandlers.rotateWidget = function(eventInfo, actions, index) {
  914. var action = actions[index];
  915. for(var i = 0; i < action.objectsToRotate.length; i++) {
  916. var rotateInfo = action.objectsToRotate[i].rotateInfo;
  917. var elementIds = $ax.getElementIdsFromPath(action.objectsToRotate[i].objectPath, eventInfo);
  918. for(var j = 0; j < elementIds.length; j++) {
  919. var elementId = elementIds[j];
  920. _queueResizeMove(elementId, queueTypes.rotate, eventInfo, rotateInfo);
  921. }
  922. }
  923. _dispatchAction(eventInfo, actions, index + 1);
  924. };
  925. var _addRotate = function (elementId, eventInfo, rotateInfo, options, moveInfo) {
  926. var idToResizeMoveState = _getIdToResizeMoveState(eventInfo);
  927. rotateInfo = $ax.deepCopy(rotateInfo);
  928. rotateInfo.options.easing = options.easing;
  929. rotateInfo.options.duration = options.duration;
  930. var eventInfoCopy = $ax.eventCopy(eventInfo);
  931. eventInfoCopy.targetElement = elementId;
  932. //calculate degree value at start of animation
  933. var rotateDegree;
  934. var offset = {};
  935. var eval = function(boundingRect) {
  936. rotateDegree = parseFloat($ax.expr.evaluateExpr(rotateInfo.degree, eventInfoCopy));
  937. offset.x = Number($ax.expr.evaluateExpr(rotateInfo.offsetX, eventInfoCopy));
  938. offset.y = Number($ax.expr.evaluateExpr(rotateInfo.offsetY, eventInfoCopy));
  939. if(!rotateInfo.options.clockwise) rotateDegree = -rotateDegree;
  940. _updateOffset(offset, rotateInfo.anchor, boundingRect);
  941. }
  942. if(moveInfo) {
  943. var moveOptions = { dragInfo: eventInfoCopy.dragInfo, duration: options.duration, easing: options.easing, boundaryExpr: moveInfo.options.boundaryExpr, boundaryStos: moveInfo.options.boundaryStos };
  944. }
  945. var obj = $obj(elementId);
  946. if($ax.public.fn.IsLayer(obj.type)) {
  947. var childrenIds = $ax.public.fn.getLayerChildrenDeep(elementId, true, true);
  948. if(childrenIds.length == 0) return;
  949. var animations = [];
  950. //get center point of the group, and degree delta
  951. var centerPoint, degreeDelta, moveDelta;
  952. animations.push({
  953. id: elementId,
  954. type: queueTypes.rotate,
  955. func: function () {
  956. var boundingRect = $ax('#' + elementId).offsetBoundingRect();
  957. //var boundingRect = $axure.fn.getWidgetBoundingRect(elementId);
  958. eval(boundingRect);
  959. centerPoint = boundingRect.centerPoint;
  960. centerPoint.x += offset.x;
  961. centerPoint.y += offset.y;
  962. degreeDelta = _initRotateLayer(elementId, rotateInfo, rotateDegree, options, options.stop);
  963. _fireAnimationFromQueue(elementId, queueTypes.rotate);
  964. moveDelta = { x: 0, y: 0 };
  965. if (moveInfo) {
  966. moveDelta = _getMoveLoc(elementId, moveInfo, eventInfoCopy, options.moveStop, idToResizeMoveState[elementId], moveOptions, boundingRect);
  967. if (moveDelta.moveTo) {
  968. moveDelta.x -= $ax.getNumFromPx($jobj(elementId).css('left'));
  969. moveDelta.y -= $ax.getNumFromPx($jobj(elementId).css('top'));
  970. }
  971. $ax.event.raiseSyntheticEvent(elementId, 'onMove');
  972. }
  973. }
  974. });
  975. for(var idIndex = 0; idIndex < childrenIds.length; idIndex++) {
  976. var childId = childrenIds[idIndex];
  977. (function(id) {
  978. var childObj = $obj(id);
  979. var rotate = $.inArray(childObj.type, widgetRotationFilter) != -1;
  980. var isLayer = $ax.public.fn.IsLayer(childObj.type);
  981. animations.push({
  982. id: id,
  983. type: queueTypes.rotate,
  984. func: function() {
  985. $ax.event.raiseSyntheticEvent(id, "onRotate");
  986. if(isLayer) _fireAnimationFromQueue(id, queueTypes.rotate);
  987. else $ax('#' + id).circularMoveAndRotate(degreeDelta, options, centerPoint.x, centerPoint.y, rotate, moveDelta);
  988. }
  989. });
  990. if(!isLayer) animations.push({ id: id, type: queueTypes.move, func: function() {} });
  991. })(childId);
  992. }
  993. _addAnimations(animations);
  994. } else {
  995. animations = [];
  996. animations.push({
  997. id: elementId,
  998. type: queueTypes.rotate,
  999. func: function () {
  1000. var jobj = $jobj(elementId);
  1001. var unrotatedDim = { width: $ax.getNumFromPx(jobj.css('width')), height: $ax.getNumFromPx(jobj.css('height')) };
  1002. eval(unrotatedDim);
  1003. var delta = { x: 0, y: 0 };
  1004. if(moveInfo) {
  1005. delta = _getMoveLoc(elementId, moveInfo, eventInfoCopy, options.moveStop, idToResizeMoveState[elementId], moveOptions);
  1006. if(delta.moveTo) {
  1007. delta.x -= $ax.getNumFromPx($jobj(elementId).css('left'));
  1008. delta.y -= $ax.getNumFromPx($jobj(elementId).css('top'));
  1009. }
  1010. }
  1011. $ax.event.raiseSyntheticEvent(elementId, 'onRotate');
  1012. if(offset.x == 0 && offset.y == 0) _rotateSingle(elementId, rotateDegree, rotateInfo.rotateType == 'location', delta, options, options.stop, true);
  1013. else _rotateSingleOffset(elementId, rotateDegree, rotateInfo.rotateType == 'location', delta, { x: offset.x, y: offset.y }, options, options.stop);
  1014. if(moveInfo) $ax.event.raiseSyntheticEvent(elementId, 'onMove');
  1015. }
  1016. });
  1017. animations.push({ id: elementId, type: queueTypes.move, func: function () { } });
  1018. _addAnimations(animations);
  1019. }
  1020. }
  1021. var _updateOffset = function(offset, anchor, boundingRect) {
  1022. if (anchor.indexOf('left') != -1) offset.x -= boundingRect.width / 2;
  1023. if (anchor.indexOf('right') != -1) offset.x += boundingRect.width / 2;
  1024. if (anchor.indexOf('top') != -1) offset.y -= boundingRect.height / 2;
  1025. if (anchor.indexOf('bottom') != -1) offset.y += boundingRect.height / 2;
  1026. }
  1027. var _rotateSingle = function(elementId, rotateDegree, rotateTo, delta, options, stop, handleMove) {
  1028. var degreeDelta = _applyRotateStop(rotateDegree, $ax.move.getRotationDegree(elementId), rotateTo, stop);
  1029. $ax('#' + elementId).rotate(degreeDelta, options.easing, options.duration, false, true);
  1030. if(handleMove) {
  1031. if (delta.x || delta.y) _moveSingleWidget(elementId, delta, options);
  1032. else $ax.action.fireAnimationFromQueue(elementId, $ax.action.queueTypes.move);
  1033. }
  1034. };
  1035. var _rotateSingleOffset = function (elementId, rotateDegree, rotateTo, delta, offset, options, stop, resizeOffset) {
  1036. var obj = $obj(elementId);
  1037. var currRotation = $ax.move.getRotationDegree(elementId);
  1038. // Need to fix offset. Want to to stay same place on widget after rotation, so need to take the offset and rotate it to where it should be.
  1039. if(currRotation) {
  1040. offset = $axure.fn.getPointAfterRotate(currRotation, offset, { x: 0, y: 0 });
  1041. }
  1042. var degreeDelta = _applyRotateStop(rotateDegree, currRotation, rotateTo, stop);
  1043. var widgetCenter = $ax('#' + elementId).offsetBoundingRect().centerPoint;
  1044. //var widgetCenter = $axure.fn.getWidgetBoundingRect(elementId).centerPoint;
  1045. var rotate = $.inArray(obj.type, widgetRotationFilter) != -1;
  1046. $ax('#' + elementId).circularMoveAndRotate(degreeDelta, options, widgetCenter.x + offset.x, widgetCenter.y + offset.y, rotate, delta, resizeOffset);
  1047. }
  1048. var _applyRotateStop = function(rotateDegree, currRotation, to, stop) {
  1049. var degreeDelta;
  1050. var ratio;
  1051. if(to) {
  1052. degreeDelta = rotateDegree - currRotation;
  1053. ratio = stop.instant ? 1 : (stop.end - stop.start) / (stop.len - stop.start);
  1054. } else {
  1055. degreeDelta = rotateDegree;
  1056. ratio = stop.instant ? 1 : (stop.end - stop.start) / stop.len;
  1057. }
  1058. return degreeDelta * ratio;
  1059. }
  1060. var _initRotateLayer = function(elementId, rotateInfo, rotateDegree, options, stop) {
  1061. var layerDegree = $jobj(elementId).data('layerDegree');
  1062. if (layerDegree === undefined) layerDegree = 0;
  1063. else layerDegree = parseFloat(layerDegree);
  1064. var to = rotateInfo.rotateType == 'location';
  1065. var newDegree = to ? rotateDegree : layerDegree + rotateDegree;
  1066. var degreeDelta = newDegree - layerDegree;
  1067. var ratio = stop.instant ? 1 : (stop.end - stop.start) / (stop.len - stop.start);
  1068. degreeDelta *= ratio;
  1069. $jobj(elementId).data('layerDegree', newDegree);
  1070. $ax.event.raiseSyntheticEvent(elementId, "onRotate");
  1071. return degreeDelta;
  1072. }
  1073. _actionHandlers.setWidgetSize = function(eventInfo, actions, index) {
  1074. var action = actions[index];
  1075. for(var i = 0; i < action.objectsToResize.length; i++) {
  1076. var resizeInfo = action.objectsToResize[i].sizeInfo;
  1077. var objPath = action.objectsToResize[i].objectPath;
  1078. if(objPath == 'thisItem') {
  1079. var thisId = eventInfo.srcElement;
  1080. var repeaterId = $ax.getParentRepeaterFromElementId(thisId);
  1081. var itemId = $ax.repeater.getItemIdFromElementId(thisId);
  1082. var currSize = $ax.repeater.getItemSize(repeaterId, itemId);
  1083. var newSize = _getSizeFromInfo(resizeInfo, eventInfo, currSize.width, currSize.height);
  1084. $ax.repeater.setItemSize(repeaterId, itemId, newSize.width, newSize.height);
  1085. continue;
  1086. }
  1087. var elementIds = $ax.getElementIdsFromPath(objPath, eventInfo);
  1088. for(var j = 0; j < elementIds.length; j++) {
  1089. var elementId = elementIds[j];
  1090. _queueResizeMove(elementId, queueTypes.resize, eventInfo, resizeInfo);
  1091. //_addResize(elementId, resizeInfo);
  1092. }
  1093. }
  1094. _dispatchAction(eventInfo, actions, index + 1);
  1095. };
  1096. // Move info undefined unless this move/resize actions are being merged
  1097. var _addResize = function(elementId, eventInfo, resizeInfo, options, moveInfo, rotateInfo) {
  1098. var axObject = $obj(elementId);
  1099. resizeInfo = $ax.deepCopy(resizeInfo);
  1100. resizeInfo.easing = options.easing;
  1101. resizeInfo.duration = options.duration;
  1102. var eventInfoCopy = $ax.eventCopy(eventInfo);
  1103. eventInfoCopy.targetElement = elementId;
  1104. var moves = moveInfo || resizeInfo.anchor != "top left" || ($ax.public.fn.IsDynamicPanel(axObject.type) &&
  1105. ((axObject.fixedHorizontal && axObject.fixedHorizontal == 'center') || (axObject.fixedVertical && axObject.fixedVertical == 'middle'))) ||
  1106. (rotateInfo && (rotateInfo.offsetX || rotateInfo.offsetY));
  1107. if(moveInfo) {
  1108. var moveOptions = { dragInfo: eventInfoCopy.dragInfo, duration: options.duration, easing: options.easing, boundaryExpr: moveInfo.options.boundaryExpr, boundaryStos: moveInfo.options.boundaryStos };
  1109. }
  1110. var idToResizeMoveState = _getIdToResizeMoveState(eventInfoCopy);
  1111. var animations = [];
  1112. // set fitToContent to false if resize the dynamic panel itself
  1113. if($ax.public.fn.IsDynamicPanel(axObject.type)) {
  1114. axObject.fitToContent = false;
  1115. $('#' + axObject.scriptIds[0]).css('overflow', 'hidden');
  1116. }
  1117. if($ax.public.fn.IsLayer(axObject.type)) {
  1118. moves = true; // Assume widgets will move will layer, even though not all widgets may move
  1119. var childrenIds = $ax.public.fn.getLayerChildrenDeep(elementId, true, true);
  1120. if(childrenIds.length === 0) return;
  1121. // Need to wait to calculate new size, until time to animate, but animates are in separate queues
  1122. // best option seems to be to calculate in a "animate" for the layer itself and all children will use that.
  1123. // May just have to be redundant if this doesn't work well.
  1124. var boundingRect, widthChangedPercent, heightChangedPercent, unchanged, deltaLoc, degreeDelta, resizeOffset;
  1125. animations.push({
  1126. id: elementId,
  1127. type: queueTypes.resize,
  1128. func: function () {
  1129. $ax.visibility.pushContainer(elementId, false);
  1130. boundingRect = $ax('#' + elementId).offsetBoundingRect();
  1131. //boundingRect = $ax.public.fn.getWidgetBoundingRect(elementId);
  1132. var size = _getSizeFromInfo(resizeInfo, eventInfoCopy, boundingRect.width, boundingRect.height, elementId);
  1133. deltaLoc = { x: 0, y: 0 };
  1134. var stop = options.stop;
  1135. var ratio = stop.instant ? 1 : (stop.end - stop.start) / (stop.len - stop.start);
  1136. widthChangedPercent = Math.round(size.width - boundingRect.width) / boundingRect.width * ratio;
  1137. heightChangedPercent = Math.round(size.height - boundingRect.height) / boundingRect.height * ratio;
  1138. resizeOffset = _applyAnchorToResizeOffset(widthChangedPercent * boundingRect.width, heightChangedPercent * boundingRect.height, resizeInfo.anchor);
  1139. if(stop.instant || stop.end == stop.len) idToResizeMoveState[elementId].resizeResult = undefined;
  1140. unchanged = widthChangedPercent === 0 && heightChangedPercent === 0;
  1141. $ax.event.raiseSyntheticEvent(elementId, 'onResize');
  1142. _fireAnimationFromQueue(elementId, queueTypes.resize);
  1143. }
  1144. });
  1145. if(moveInfo) animations.push({
  1146. id: elementId,
  1147. type: queueTypes.move,
  1148. func: function() {
  1149. deltaLoc = _getMoveLoc(elementId, moveInfo, eventInfoCopy, options.moveStop, idToResizeMoveState[elementId], moveOptions, boundingRect);
  1150. $ax.visibility.pushContainer(elementId, false);
  1151. _fireAnimationFromQueue(elementId, queueTypes.move);
  1152. $ax.event.raiseSyntheticEvent(elementId, 'onMove');
  1153. }
  1154. });
  1155. if (rotateInfo) animations.push({
  1156. id: elementId,
  1157. type: queueTypes.rotate,
  1158. func: function () {
  1159. resizeOffset = _applyAnchorToResizeOffset(widthChangedPercent * boundingRect.width, heightChangedPercent * boundingRect.height, resizeInfo.anchor);
  1160. var rotateDegree = parseFloat($ax.expr.evaluateExpr(rotateInfo.degree, eventInfoCopy));
  1161. degreeDelta = _initRotateLayer(elementId, rotateInfo, rotateDegree, options, options.rotateStop);
  1162. _fireAnimationFromQueue(elementId, queueTypes.rotate);
  1163. $ax.event.raiseSyntheticEvent(elementId, 'onRotate');
  1164. }
  1165. });
  1166. var completeCount = childrenIds.length*2; // Because there is a resize and move complete, it needs to be doubled
  1167. for(var idIndex = 0; idIndex < childrenIds.length; idIndex++) {
  1168. // Need to use scoping trick here to make sure childId doesn't change on next loop
  1169. (function(childId) {
  1170. //use ax obj to get width and height, jquery css give us the value without border
  1171. var isLayer = $ax.public.fn.IsLayer($obj(childId).type);
  1172. var rotate = $.inArray($obj(childId).type, widgetRotationFilter) != -1;
  1173. animations.push({
  1174. id: childId,
  1175. type: queueTypes.resize,
  1176. func: function() {
  1177. //$ax.event.raiseSyntheticEvent(childId, 'onResize');
  1178. if(isLayer) {
  1179. completeCount -= 2;
  1180. _fireAnimationFromQueue(childId, queueTypes.resize);
  1181. $ax.event.raiseSyntheticEvent(childId, 'onResize');
  1182. } else {
  1183. var currDeltaLoc = { x: deltaLoc.x, y: deltaLoc.y };
  1184. var resizeDeltaMove = { x: 0, y: 0 };
  1185. var css = _getCssForResizingLayerChild(childId, resizeInfo.anchor, boundingRect, widthChangedPercent, heightChangedPercent, resizeDeltaMove);
  1186. var onComplete = function() {
  1187. if(--completeCount == 0) $ax.visibility.popContainer(elementId, false);
  1188. };
  1189. $ax('#' + childId).resize(css, resizeInfo, true, moves, onComplete);
  1190. if(rotateInfo) {
  1191. var offset = { x: Number($ax.expr.evaluateExpr(rotateInfo.offsetX, eventInfoCopy)), y: Number($ax.expr.evaluateExpr(rotateInfo.offsetY, eventInfo)) };
  1192. _updateOffset(offset, resizeInfo.anchor, boundingRect);
  1193. var centerPoint = { x: boundingRect.centerPoint.x + offset.x, y: boundingRect.centerPoint.y + offset.y };
  1194. $ax('#' + childId).circularMoveAndRotate(degreeDelta, options, centerPoint.x, centerPoint.y, rotate, currDeltaLoc, resizeOffset, resizeDeltaMove, onComplete);
  1195. } else {
  1196. currDeltaLoc.x += resizeDeltaMove.x;
  1197. currDeltaLoc.y += resizeDeltaMove.y;
  1198. _moveSingleWidget(childId, currDeltaLoc, options, onComplete);
  1199. }
  1200. }
  1201. }
  1202. });
  1203. if(!isLayer) animations.push({ id: childId, type: queueTypes.move, func: function () {} });
  1204. if(!isLayer && rotateInfo) animations.push({ id: childId, type: queueTypes.rotate, func: function () {} });
  1205. })(childrenIds[idIndex]);
  1206. }
  1207. } else {
  1208. // Not func, obj with func
  1209. animations.push({
  1210. id: elementId,
  1211. type: queueTypes.resize,
  1212. func: function() {
  1213. //textarea can be resized manully by the user, but doesn't update div size yet, so doing this for now.
  1214. //alternatively axquery get for size can account for this
  1215. var sizeId = $ax.public.fn.IsTextArea(axObject.type) ? $jobj(elementId).children('textarea').attr('id') : elementId;
  1216. var oldSize = $ax('#' + sizeId).size();
  1217. var oldWidth = oldSize.width;
  1218. var oldHeight = oldSize.height;
  1219. var stop = options.stop;
  1220. var ratio = stop.instant ? 1 : (stop.end - stop.start) / (stop.len - stop.start);
  1221. var size = _getSizeFromInfo(resizeInfo, eventInfoCopy, oldWidth, oldHeight, elementId);
  1222. var newWidth = size.width;
  1223. var newHeight = size.height;
  1224. var deltaWidth = Math.round(newWidth - oldWidth) * ratio;
  1225. var deltaHeight = Math.round(newHeight - oldHeight) * ratio;
  1226. newWidth = oldWidth + deltaWidth;
  1227. newHeight = oldHeight + deltaHeight;
  1228. var delta = { x: 0, y: 0 };
  1229. if(moveInfo) {
  1230. delta = _getMoveLoc(elementId, moveInfo, eventInfoCopy, options.moveStop, idToResizeMoveState[elementId], moveOptions);
  1231. if (delta.moveTo) {
  1232. delta.x -= $ax.getNumFromPx($jobj(elementId).css('left'));
  1233. delta.y -= $ax.getNumFromPx($jobj(elementId).css('top'));
  1234. }
  1235. }
  1236. var rotateHandlesMove = false;
  1237. var offset = { x: 0, y: 0 };
  1238. if(rotateInfo) {
  1239. offset.x = Number($ax.expr.evaluateExpr(rotateInfo.offsetX, eventInfoCopy));
  1240. offset.y = Number($ax.expr.evaluateExpr(rotateInfo.offsetY, eventInfoCopy));
  1241. _updateOffset(offset, rotateInfo.anchor, $ax('#' + elementId).offsetBoundingRect());
  1242. //_updateOffset(offset, rotateInfo.anchor, $axure.fn.getWidgetBoundingRect(elementId));
  1243. rotateHandlesMove = Boolean(rotateInfo && (offset.x || offset.y || rotateInfo.anchor != 'center'));
  1244. $ax.event.raiseSyntheticEvent(elementId, 'onRotate');
  1245. }
  1246. var css = null;
  1247. var rootLayer = null;
  1248. if(deltaHeight != 0 || deltaWidth != 0) {
  1249. rootLayer = $ax.move.getRootLayer(elementId);
  1250. if(rootLayer) $ax.visibility.pushContainer(rootLayer, false);
  1251. css = _getCssForResizingWidget(elementId, eventInfoCopy, resizeInfo.anchor, newWidth, newHeight, oldWidth, oldHeight, delta, options.stop, !rotateHandlesMove);
  1252. idToResizeMoveState[elementId].resizeResult = undefined;
  1253. }
  1254. if(rotateInfo) {
  1255. var rotateDegree = parseFloat($ax.expr.evaluateExpr(rotateInfo.degree, eventInfoCopy));
  1256. if(rotateHandlesMove) {
  1257. var resizeOffset = _applyAnchorToResizeOffset(deltaWidth, deltaHeight, rotateInfo.anchor);
  1258. _rotateSingleOffset(elementId, rotateDegree, rotateInfo.rotateType == 'location', delta, offset, options, options.rotateStop, resizeOffset);
  1259. } else {
  1260. // Not handling move so pass in nop delta
  1261. _rotateSingle(elementId, rotateDegree, rotateInfo.rotateType == 'location', { x: 0, y: 0 }, options, options.rotateStop);
  1262. if (moves) _fireAnimationFromQueue(elementId, queueTypes.move);
  1263. }
  1264. } else if(!css && moves) _moveSingleWidget(elementId, delta, options);
  1265. // Have to do it down here to make sure move info is registered
  1266. if(moveInfo) $ax.event.raiseSyntheticEvent(elementId, 'onMove');
  1267. //$ax.event.raiseSyntheticEvent(elementId, 'onResize');
  1268. if (css) {
  1269. $ax('#' + elementId).resize(css, resizeInfo, true, moves, function () {
  1270. if(rootLayer) $ax.visibility.popContainer(rootLayer, false);
  1271. });
  1272. } else {
  1273. _fireAnimationFromQueue(elementId, queueTypes.resize);
  1274. $ax.event.raiseSyntheticEvent(elementId, 'onResize');
  1275. }
  1276. }
  1277. });
  1278. // Nop move (move handled by resize)
  1279. if(rotateInfo) animations.push({ id: elementId, type: queueTypes.rotate, func: function () { } });
  1280. if(moves) animations.push({ id: elementId, type: queueTypes.move, func: function () { } });
  1281. }
  1282. _addAnimations(animations);
  1283. };
  1284. var _applyAnchorToResizeOffset = function (deltaWidth, deltaHeight, anchor) {
  1285. var offset = {};
  1286. if (anchor.indexOf('left') != -1) offset.x = -deltaWidth / 2;
  1287. else if (anchor.indexOf('right') != -1) offset.x = deltaWidth / 2;
  1288. if (anchor.indexOf('top') != -1) offset.y = -deltaHeight / 2;
  1289. else if (anchor.indexOf('bottom') != -1) offset.y = deltaHeight / 2;
  1290. return offset;
  1291. }
  1292. //var _getOldAndNewSize = function (resizeInfo, eventInfo, targetElement) {
  1293. // var axObject = $obj(targetElement);
  1294. // var oldWidth, oldHeight;
  1295. // //textarea can be resized manully by the user, use the textarea child to get the current size
  1296. // //because this new size may not be reflected on its parents yet
  1297. // if ($ax.public.fn.IsTextArea(axObject.type)) {
  1298. // var jObject = $jobj(elementId);
  1299. // var textObj = $ax('#' + jObject.children('textarea').attr('id'));
  1300. // //maybe we shouldn't use ax obj to get width and height here anymore...
  1301. // oldWidth = textObj.width();
  1302. // oldHeight = textObj.height();
  1303. // } else {
  1304. // oldWidth = $ax('#' + elementId).width();
  1305. // oldHeight = $ax('#' + elementId).height();
  1306. // }
  1307. // var size = _getSizeFromInfo(resizeInfo, eventInfo, oldHeight, oldWidth, elementId);
  1308. // return { oldWidth: oldWidth, oldHeight: oldHeight, newWidth: size.width, newHeight: size.height, change: oldWidth != size.width || oldHeight != size.height };
  1309. //}
  1310. var _getSizeFromInfo = function(resizeInfo, eventInfo, oldWidth, oldHeight, targetElement) {
  1311. var oldTarget = eventInfo.targetElement;
  1312. eventInfo.targetElement = targetElement;
  1313. var state = _getIdToResizeMoveState(eventInfo)[targetElement];
  1314. if(state && state.resizeResult) return state.resizeResult;
  1315. var width = $ax.expr.evaluateExpr(resizeInfo.width, eventInfo);
  1316. var height = $ax.expr.evaluateExpr(resizeInfo.height, eventInfo);
  1317. eventInfo.targetElement = oldTarget;
  1318. // If either one is not a number, use the old value
  1319. width = width != "" ? Number(width) : oldWidth;
  1320. height = height != "" ? Number(height) : oldHeight;
  1321. width = isNaN(width) ? oldWidth : width;
  1322. height = isNaN(height) ? oldHeight : height;
  1323. // can't be negative
  1324. var result = { width: Math.max(width, 0), height: Math.max(height, 0) };
  1325. if(state) state.resizeResult = result;
  1326. return result;
  1327. }
  1328. //var _queueResize = function (elementId, css, resizeInfo) {
  1329. // var resizeFunc = function() {
  1330. // $ax('#' + elementId).resize(css, resizeInfo, true);
  1331. // //$ax.public.fn.resize(elementId, css, resizeInfo, true);
  1332. // };
  1333. // var obj = $obj(elementId);
  1334. // var moves = resizeInfo.anchor != "top left" || ($ax.public.fn.IsDynamicPanel(obj.type) && ((obj.fixedHorizontal && obj.fixedHorizontal == 'center') || (obj.fixedVertical && obj.fixedVertical == 'middle')))
  1335. // if(!moves) {
  1336. // _addAnimation(elementId, queueTypes.resize, resizeFunc);
  1337. // } else {
  1338. // var animations = [];
  1339. // animations[0] = { id: elementId, type: queueTypes.resize, func: resizeFunc };
  1340. // animations[1] = { id: elementId, type: queueTypes.move, func: function() {}}; // Nop func - resize handles move and firing from queue
  1341. // _addAnimations(animations);
  1342. // }
  1343. //};
  1344. //should clean this function and
  1345. var _getCssForResizingWidget = function (elementId, eventInfo, anchor, newWidth, newHeight, oldWidth, oldHeight, delta, stop, handleMove) {
  1346. var ratio = stop.instant ? 1 : (stop.end - stop.start) / (stop.len - stop.start);
  1347. var deltaWidth = (newWidth - oldWidth) * ratio;
  1348. var deltaHeight = (newHeight - oldHeight) * ratio;
  1349. if(stop.instant || stop.end == stop.len) {
  1350. var idToResizeMoveState = _getIdToResizeMoveState(eventInfo);
  1351. if(idToResizeMoveState[elementId]) idToResizeMoveState[elementId].resizeResult = undefined;
  1352. }
  1353. var css = {};
  1354. css.height = oldHeight + deltaHeight;
  1355. var obj = $obj(elementId);
  1356. //if it's 100% width, don't change its width
  1357. if($ax.dynamicPanelManager.isPercentWidthPanel(obj)) var is100Dp = true;
  1358. else css.width = oldWidth + deltaWidth;
  1359. var jobj = $jobj(elementId);
  1360. //if this is pinned dp, we will mantain the pin, no matter how you resize it; so no need changes left or top
  1361. //NOTE: currently only pinned DP has position == fixed
  1362. if(jobj.css('position') == 'fixed') {
  1363. if(obj.fixedHorizontal && obj.fixedHorizontal == 'center') css['margin-left'] = '+=' + delta.x;
  1364. if(obj.fixedVertical && obj.fixedVertical == 'middle') css['margin-top'] = '+=' + delta.y;
  1365. return css;
  1366. }
  1367. // If it is pinned, but temporarily not fixed because it is wrappen in a container, then just make sure to anchor it correctly
  1368. if(obj.fixedVertical) {
  1369. if(obj.fixedVertical == 'middle') anchor = obj.fixedHorizontal;
  1370. else anchor = obj.fixedVertical + (obj.fixedHorizontal == 'center' ? '' : ' ' + obj.fixedHorizontal);
  1371. }
  1372. //use position relative to parents
  1373. //var position = obj.generateCompound ? $ax.public.fn.getWidgetBoundingRect(elementId) : $ax.public.fn.getPositionRelativeToParent(elementId);
  1374. var locationShift;
  1375. switch(anchor) {
  1376. case "top left":
  1377. locationShift = { x: 0, y: 0 }; break;
  1378. case "top":
  1379. locationShift = { x: -deltaWidth / 2.0, y: 0.0 }; break;
  1380. case "top right":
  1381. locationShift = { x: -deltaWidth, y: 0.0 }; break;
  1382. case "left":
  1383. locationShift = { x: 0.0, y: -deltaHeight / 2.0 }; break;
  1384. case "center":
  1385. locationShift = { x: -deltaWidth / 2.0, y: -deltaHeight / 2.0 }; break;
  1386. case "right":
  1387. locationShift = { x: -deltaWidth, y: -deltaHeight / 2.0 }; break;
  1388. case "bottom left":
  1389. locationShift = { x: 0.0, y: -deltaHeight }; break;
  1390. case "bottom":
  1391. locationShift = { x: -deltaWidth/2.0, y: -deltaHeight }; break;
  1392. case "bottom right":
  1393. locationShift = { x: -deltaWidth, y: -deltaHeight }; break;
  1394. }
  1395. if(handleMove) {
  1396. if(jobj.css('position') === 'absolute') {
  1397. css.left = $ax.getNumFromPx(jobj.css('left')) + locationShift.x + delta.x;
  1398. css.top = $ax.getNumFromPx(jobj.css('top')) + locationShift.y + delta.y;
  1399. } else {
  1400. var axQuery = $ax('#' + elementId);
  1401. var offsetLocation = axQuery.offsetLocation();
  1402. css.left = offsetLocation.left + locationShift.x + delta.x;
  1403. css.top = offsetLocation.top + locationShift.y + delta.y;
  1404. //css.left = axQuery.left(true) + locationShift.x + delta.x;
  1405. //css.top = axQuery.top(true) + locationShift.y + delta.y;
  1406. }
  1407. } else {
  1408. delta.x += locationShift.x;
  1409. delta.y += locationShift.y;
  1410. }
  1411. css.deltaX = locationShift.x + delta.x;
  1412. css.deltaY = locationShift.y + delta.y;
  1413. return css;
  1414. };
  1415. var _getCssForResizingLayerChild = function (elementId, anchor, layerBoundingRect, widthChangedPercent, heightChangedPercent, deltaLoc) {
  1416. var boundingRect = $ax('#' + elementId).offsetBoundingRect();
  1417. //var boundingRect = $ax.public.fn.getWidgetBoundingRect(elementId);
  1418. var childCenterPoint = boundingRect.centerPoint;
  1419. var currentSize = $ax('#' + elementId).size();
  1420. var newWidth = currentSize.width + currentSize.width * widthChangedPercent;
  1421. var newHeight = currentSize.height + currentSize.height * heightChangedPercent;
  1422. var css = {};
  1423. css.height = newHeight;
  1424. var obj = $obj(elementId);
  1425. //if it's 100% width, don't change its width and left
  1426. var changeLeft = true;
  1427. if($ax.dynamicPanelManager.isPercentWidthPanel(obj)) changeLeft = false;
  1428. else css.width = newWidth;
  1429. var jobj = $jobj(elementId);
  1430. //if this is pinned dp, we will mantain the pin, no matter how you resize it; so no need changes left or top
  1431. //NOTE: currently only pinned DP has position == fixed
  1432. if(jobj.css('position') == 'fixed') return css;
  1433. //use bounding rect position relative to parents to calculate delta
  1434. //var axObj = $ax('#' + elementId);
  1435. // This will be absolute world coordinates, but we want body coordinates.
  1436. var offsetLocation = $ax('#' + elementId).offsetLocation();
  1437. var currentLeft = offsetLocation.left;
  1438. var currentTop = offsetLocation.top;
  1439. //var currentLeft = axObj.locRelativeIgnoreLayer(false);
  1440. //var currentTop = axObj.locRelativeIgnoreLayer(true);
  1441. var resizable = $ax.public.fn.IsResizable(obj.type);
  1442. if(anchor.indexOf("top") > -1) {
  1443. var topDelta = (currentTop - layerBoundingRect.top) * heightChangedPercent;
  1444. if(!resizable && Math.round(topDelta)) topDelta += currentSize.height * heightChangedPercent;
  1445. } else if(anchor.indexOf("bottom") > -1) {
  1446. if(resizable) topDelta = (currentTop - layerBoundingRect.bottom) * heightChangedPercent;
  1447. else {
  1448. var bottomDelta = Math.round(currentTop + currentSize.height - layerBoundingRect.bottom) * heightChangedPercent;
  1449. if(bottomDelta) topDelta = bottomDelta - currentSize.height * heightChangedPercent;
  1450. else topDelta = 0;
  1451. }
  1452. } else { //center vertical
  1453. if(resizable) topDelta = (childCenterPoint.y - layerBoundingRect.centerPoint.y)*heightChangedPercent - currentSize.height*heightChangedPercent/2;
  1454. else {
  1455. var centerTopChange = Math.round(childCenterPoint.y - layerBoundingRect.centerPoint.y)*heightChangedPercent;
  1456. if(centerTopChange > 0) topDelta = centerTopChange + Math.abs(currentSize.height * heightChangedPercent / 2);
  1457. else if(centerTopChange < 0) topDelta = centerTopChange - Math.abs(currentSize.height * heightChangedPercent / 2);
  1458. else topDelta = 0;
  1459. }
  1460. }
  1461. if(changeLeft) {
  1462. if(anchor.indexOf("left") > -1) {
  1463. var leftDelta = (currentLeft - layerBoundingRect.left) * widthChangedPercent;
  1464. if(!resizable && Math.round(leftDelta)) leftDelta += currentSize.width * widthChangedPercent;
  1465. } else if(anchor.indexOf("right") > -1) {
  1466. if(resizable) leftDelta = (currentLeft - layerBoundingRect.right) * widthChangedPercent;
  1467. else {
  1468. var rightDelta = Math.round(currentLeft + currentSize.width - layerBoundingRect.right) * widthChangedPercent;
  1469. if(rightDelta) leftDelta = rightDelta - currentSize.width * widthChangedPercent;
  1470. else leftDelta = 0;
  1471. }
  1472. } else { //center horizontal
  1473. if(resizable) leftDelta = (childCenterPoint.x - layerBoundingRect.centerPoint.x)*widthChangedPercent - currentSize.width*widthChangedPercent/2;
  1474. else {
  1475. var centerLeftChange = Math.round(childCenterPoint.x - layerBoundingRect.centerPoint.x) * widthChangedPercent;
  1476. if(centerLeftChange > 0) leftDelta = centerLeftChange + Math.abs(currentSize.width * widthChangedPercent / 2);
  1477. else if(centerLeftChange < 0) leftDelta = centerLeftChange - Math.abs(currentSize.width * widthChangedPercent / 2);
  1478. else leftDelta = 0;
  1479. }
  1480. }
  1481. }
  1482. if(topDelta) deltaLoc.y += topDelta;
  1483. if(leftDelta && changeLeft) deltaLoc.x += leftDelta;
  1484. return css;
  1485. };
  1486. _actionHandlers.setPanelOrder = function(eventInfo, actions, index) {
  1487. var action = actions[index];
  1488. for(var i = 0; i < action.panelPaths.length; i++) {
  1489. var func = action.panelPaths[i].setOrderInfo.bringToFront ? 'bringToFront' : 'sendToBack';
  1490. var elementIds = $ax.getElementIdsFromPath(action.panelPaths[i].panelPath, eventInfo);
  1491. for(var j = 0; j < elementIds.length; j++) $ax('#' + elementIds[j])[func]();
  1492. }
  1493. _dispatchAction(eventInfo, actions, index + 1);
  1494. };
  1495. _actionHandlers.modifyDataSetEditItems = function(eventInfo, actions, index) {
  1496. var action = actions[index];
  1497. var add = action.repeatersToAddTo;
  1498. var repeaters = add || action.repeatersToRemoveFrom;
  1499. var itemId;
  1500. for(var i = 0; i < repeaters.length; i++) {
  1501. var data = repeaters[i];
  1502. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  1503. // or none if unplaced
  1504. var id = $ax.getElementIdsFromPath(data.path, eventInfo)[0];
  1505. if(!id) continue;
  1506. if(data.type == 'this') {
  1507. var scriptId = $ax.repeater.getScriptIdFromElementId(eventInfo.srcElement);
  1508. itemId = $ax.repeater.getItemIdFromElementId(eventInfo.srcElement);
  1509. var repeaterId = $ax.getParentRepeaterFromScriptId(scriptId);
  1510. if(add) $ax.repeater.addEditItems(repeaterId, [itemId]);
  1511. else $ax.repeater.removeEditItems(repeaterId, [itemId]);
  1512. } else if(data.type == 'all') {
  1513. var allItems = $ax.repeater.getAllItemIds(id);
  1514. if(add) $ax.repeater.addEditItems(id, allItems);
  1515. else $ax.repeater.removeEditItems(id, allItems);
  1516. } else {
  1517. var oldTarget = eventInfo.targetElement;
  1518. var itemIds = $ax.repeater.getAllItemIds(id);
  1519. var itemIdsToAdd = [];
  1520. for(var j = 0; j < itemIds.length; j++) {
  1521. itemId = itemIds[j];
  1522. eventInfo.targetElement = $ax.repeater.createElementId(id, itemId);
  1523. if($ax.expr.evaluateExpr(data.rule, eventInfo) == "true") {
  1524. itemIdsToAdd[itemIdsToAdd.length] = String(itemId);
  1525. }
  1526. eventInfo.targetElement = oldTarget;
  1527. }
  1528. if(add) $ax.repeater.addEditItems(id, itemIdsToAdd);
  1529. else $ax.repeater.removeEditItems(id, itemIdsToAdd);
  1530. }
  1531. }
  1532. _dispatchAction(eventInfo, actions, index + 1);
  1533. };
  1534. _action.repeaterInfoNames = { addItemsToDataSet: 'dataSetsToAddTo', deleteItemsFromDataSet: 'dataSetItemsToRemove', updateItemsInDataSet: 'dataSetsToUpdate',
  1535. addFilterToRepeater: 'repeatersToAddFilter', removeFilterFromRepeater: 'repeatersToRemoveFilter',
  1536. addSortToRepeater: 'repeaterToAddSort', removeSortFromRepeater: 'repeaterToRemoveSort',
  1537. setRepeaterToPage: 'repeatersToSetPage', setItemsPerRepeaterPage: 'repeatersToSetItemCount'
  1538. };
  1539. _actionHandlers.addItemsToDataSet = function(eventInfo, actions, index) {
  1540. var action = actions[index];
  1541. for(var i = 0; i < action.dataSetsToAddTo.length; i++) {
  1542. var datasetInfo = action.dataSetsToAddTo[i];
  1543. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  1544. // or none if unplaced
  1545. var id = $ax.getElementIdsFromPath(datasetInfo.path, eventInfo)[0];
  1546. if(!id || _ignoreAction(id)) continue;
  1547. var dataset = datasetInfo.data;
  1548. for(var j = 0; j < dataset.length; j++) $ax.repeater.addItem(id, $ax.deepCopy(dataset[j]), eventInfo);
  1549. if(dataset.length) _addRefresh(id);
  1550. }
  1551. _dispatchAction(eventInfo, actions, index + 1);
  1552. };
  1553. _actionHandlers.deleteItemsFromDataSet = function(eventInfo, actions, index) {
  1554. var action = actions[index];
  1555. for(var i = 0; i < action.dataSetItemsToRemove.length; i++) {
  1556. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  1557. // or none if unplaced
  1558. var deleteInfo = action.dataSetItemsToRemove[i];
  1559. var id = $ax.getElementIdsFromPath(deleteInfo.path, eventInfo)[0];
  1560. if(!id || _ignoreAction(id)) continue;
  1561. $ax.repeater.deleteItems(id, eventInfo, deleteInfo.type, deleteInfo.rule);
  1562. _addRefresh(id);
  1563. }
  1564. _dispatchAction(eventInfo, actions, index + 1);
  1565. };
  1566. _actionHandlers.updateItemsInDataSet = function(eventInfo, actions, index) {
  1567. var action = actions[index];
  1568. for(var i = 0; i < action.dataSetsToUpdate.length; i++) {
  1569. var dataSet = action.dataSetsToUpdate[i];
  1570. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  1571. // or none if unplaced
  1572. var id = $ax.getElementIdsFromPath(dataSet.path, eventInfo)[0];
  1573. if(!id || _ignoreAction(id)) continue;
  1574. $ax.repeater.updateEditItems(id, dataSet.props, eventInfo, dataSet.type, dataSet.rule);
  1575. _addRefresh(id);
  1576. }
  1577. _dispatchAction(eventInfo, actions, index + 1);
  1578. };
  1579. _actionHandlers.setRepeaterToDataSet = function(eventInfo, actions, index) {
  1580. var action = actions[index];
  1581. for(var i = 0; i < action.repeatersToSet.length; i++) {
  1582. var setRepeaterInfo = action.repeatersToSet[i];
  1583. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  1584. // or none if unplaced
  1585. var id = $ax.getElementIdsFromPath(setRepeaterInfo.path, eventInfo)[0];
  1586. if(!id) continue;
  1587. $ax.repeater.setDataSet(id, setRepeaterInfo.localDataSetId);
  1588. }
  1589. _dispatchAction(eventInfo, actions, index + 1);
  1590. };
  1591. _actionHandlers.addFilterToRepeater = function(eventInfo, actions, index) {
  1592. var action = actions[index];
  1593. for(var i = 0; i < action.repeatersToAddFilter.length; i++) {
  1594. var addFilterInfo = action.repeatersToAddFilter[i];
  1595. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  1596. // or none if unplaced
  1597. var id = $ax.getElementIdsFromPath(addFilterInfo.path, eventInfo)[0];
  1598. if(!id || _ignoreAction(id)) continue;
  1599. $ax.repeater.addFilter(
  1600. id,
  1601. addFilterInfo.removeOtherFilters,
  1602. addFilterInfo.label,
  1603. addFilterInfo.filter,
  1604. addFilterInfo.condition,
  1605. addFilterInfo.columnName,
  1606. addFilterInfo.comboType,
  1607. eventInfo.srcElement);
  1608. _addRefresh(id);
  1609. }
  1610. _dispatchAction(eventInfo, actions, index + 1);
  1611. };
  1612. _actionHandlers.removeFilterFromRepeater = function(eventInfo, actions, index) {
  1613. var action = actions[index];
  1614. for(var i = 0; i < action.repeatersToRemoveFilter.length; i++) {
  1615. var removeFilterInfo = action.repeatersToRemoveFilter[i];
  1616. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  1617. // or none if unplaced
  1618. var id = $ax.getElementIdsFromPath(removeFilterInfo.path, eventInfo)[0];
  1619. if(!id || _ignoreAction(id)) continue;
  1620. if(removeFilterInfo.removeAll) $ax.repeater.removeFilter(id);
  1621. else if(removeFilterInfo.filterName != '') {
  1622. $ax.repeater.removeFilter(id, removeFilterInfo.filterName);
  1623. }
  1624. _addRefresh(id);
  1625. }
  1626. _dispatchAction(eventInfo, actions, index + 1);
  1627. };
  1628. _actionHandlers.addSortToRepeater = function(eventInfo, actions, index) {
  1629. var action = actions[index];
  1630. for(var i = 0; i < action.repeatersToAddSort.length; i++) {
  1631. var addSortInfo = action.repeatersToAddSort[i];
  1632. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  1633. // or none if unplaced
  1634. var id = $ax.getElementIdsFromPath(addSortInfo.path, eventInfo)[0];
  1635. if(!id || _ignoreAction(id)) continue;
  1636. $ax.repeater.addSort(id, addSortInfo.label, addSortInfo.columnName, addSortInfo.ascending, addSortInfo.toggle, addSortInfo.sortType, addSortInfo.removeAllSorts);
  1637. _addRefresh(id);
  1638. }
  1639. _dispatchAction(eventInfo, actions, index + 1);
  1640. };
  1641. _actionHandlers.removeSortFromRepeater = function(eventInfo, actions, index) {
  1642. var action = actions[index];
  1643. for(var i = 0; i < action.repeatersToRemoveSort.length; i++) {
  1644. var removeSortInfo = action.repeatersToRemoveSort[i];
  1645. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  1646. // or none if unplaced
  1647. var id = $ax.getElementIdsFromPath(removeSortInfo.path, eventInfo)[0];
  1648. if(!id || _ignoreAction(id)) continue;
  1649. if(removeSortInfo.removeAll) $ax.repeater.removeSort(id);
  1650. else if(removeSortInfo.sortName != '') $ax.repeater.removeSort(id, removeSortInfo.sortName);
  1651. _addRefresh(id);
  1652. }
  1653. _dispatchAction(eventInfo, actions, index + 1);
  1654. };
  1655. _actionHandlers.setRepeaterToPage = function(eventInfo, actions, index) {
  1656. var action = actions[index];
  1657. for(var i = 0; i < action.repeatersToSetPage.length; i++) {
  1658. var setPageInfo = action.repeatersToSetPage[i];
  1659. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  1660. // or none if unplaced
  1661. var id = $ax.getElementIdsFromPath(setPageInfo.path, eventInfo)[0];
  1662. if(!id || _ignoreAction(id)) continue;
  1663. var oldTarget = eventInfo.targetElement;
  1664. eventInfo.targetElement = id;
  1665. $ax.repeater.setRepeaterToPage(id, setPageInfo.pageType, setPageInfo.pageValue, eventInfo);
  1666. eventInfo.targetElement = oldTarget;
  1667. _addRefresh(id);
  1668. }
  1669. _dispatchAction(eventInfo, actions, index + 1);
  1670. };
  1671. _actionHandlers.setItemsPerRepeaterPage = function(eventInfo, actions, index) {
  1672. var action = actions[index];
  1673. for(var i = 0; i < action.repeatersToSetItemCount.length; i++) {
  1674. var setItemCountInfo = action.repeatersToSetItemCount[i];
  1675. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  1676. // or none if unplaced
  1677. var id = $ax.getElementIdsFromPath(setItemCountInfo.path, eventInfo)[0];
  1678. if(!id || _ignoreAction(id)) continue;
  1679. if(setItemCountInfo.noLimit) $ax.repeater.setNoItemLimit(id);
  1680. else $ax.repeater.setItemLimit(id, setItemCountInfo.itemCountValue, eventInfo);
  1681. _addRefresh(id);
  1682. }
  1683. _dispatchAction(eventInfo, actions, index + 1);
  1684. };
  1685. _actionHandlers.refreshRepeater = function(eventInfo, actions, index) {
  1686. // We use this as a psudo action now.
  1687. var action = actions[index];
  1688. for (var i = 0; i < action.repeatersToRefresh.length; i++) {
  1689. // Grab the first one because repeaters must have only element id, as they cannot be inside repeaters
  1690. // or none if unplaced
  1691. var id = $ax.getElementIdsFromPath(action.repeatersToRefresh[i], eventInfo)[0];
  1692. if(id) _tryRefreshRepeater(id, eventInfo);
  1693. }
  1694. _dispatchAction(eventInfo, actions, index + 1);
  1695. };
  1696. var _tryRefreshRepeater = function(id, eventInfo) {
  1697. var idIndex = _repeatersToRefresh.indexOf(id);
  1698. if(idIndex == -1) return;
  1699. $ax.splice(_repeatersToRefresh, idIndex, 1);
  1700. $ax.repeater.refreshRepeater(id, eventInfo);
  1701. };
  1702. _action.tryRefreshRepeaters = function(ids, eventInfo) {
  1703. for(var i = 0; i < ids.length; i++) _tryRefreshRepeater(ids[i], eventInfo);
  1704. };
  1705. _actionHandlers.scrollToWidget = function(eventInfo, actions, index) {
  1706. var action = actions[index];
  1707. var elementIds = $ax.getElementIdsFromPath(action.objectPath, eventInfo);
  1708. if(elementIds.length > 0) $ax('#' + elementIds[0]).scroll(action.options);
  1709. _dispatchAction(eventInfo, actions, index + 1);
  1710. };
  1711. _actionHandlers.enableDisableWidgets = function (eventInfo, actions, index) {
  1712. let action = actions[index];
  1713. for(let i = 0; i < action.pathToInfo.length; i++) {
  1714. const elementIds = $ax.getElementIdsFromPath(action.pathToInfo[i].objectPath, eventInfo);
  1715. const enableAction = action.pathToInfo[i].enableDisableInfo.enableAction;
  1716. const isToggle = enableAction === 'Toggle';
  1717. const isEnabled = enableAction === 'Enable';
  1718. for(let j = 0; j < elementIds.length; j++) {
  1719. const elementId = elementIds[j];
  1720. const toggleValue = $ax.style.IsWidgetDisabled(elementId);
  1721. $ax('#' + elementId).enabled(isToggle ? toggleValue : isEnabled);
  1722. }
  1723. }
  1724. _dispatchAction(eventInfo, actions, index + 1);
  1725. };
  1726. _actionHandlers.setImage = function(eventInfo, actions, index) {
  1727. var oldTarget = eventInfo.targetElement;
  1728. var action = actions[index];
  1729. var view = $ax.adaptive.currentViewId;
  1730. eventInfo.image = true;
  1731. for(var i = 0; i < action.imagesToSet.length; i++) {
  1732. var imgInfo = action.imagesToSet[i];
  1733. if (view && imgInfo.adaptive[view]) imgInfo = imgInfo.adaptive[view];
  1734. else imgInfo = imgInfo.base;
  1735. var elementIds = $ax.getElementIdsFromPath(action.imagesToSet[i].objectPath, eventInfo);
  1736. for(var j = 0; j < elementIds.length; j++) {
  1737. var elementId = elementIds[j];
  1738. eventInfo.targetElement = elementId;
  1739. var evaluatedImgs = _evaluateImages(imgInfo, eventInfo);
  1740. //Set up overrides
  1741. $ax.style.mapElementIdToImageOverrides(elementId, evaluatedImgs);
  1742. $ax.style.updateImage(elementId);
  1743. if(evaluatedImgs.mouseOver || evaluatedImgs.mouseDown) $ax.event.updateIxStyleEvents(elementId);
  1744. }
  1745. }
  1746. eventInfo.targetElement = oldTarget;
  1747. eventInfo.image = false;
  1748. _dispatchAction(eventInfo, actions, index + 1);
  1749. };
  1750. var _evaluateImages = function(imgInfo, eventInfo) {
  1751. var retVal = {};
  1752. for(var state in imgInfo) {
  1753. if(!imgInfo.hasOwnProperty(state)) continue;
  1754. var img = imgInfo[state][$ax.adaptive.getSketchKey()] || $ax.expr.evaluateExpr(imgInfo[state].literal, eventInfo);
  1755. if(!img) img = $axure.utils.getTransparentGifPath();
  1756. retVal[state] = img;
  1757. }
  1758. return retVal;
  1759. };
  1760. $ax.clearRepeaterImageOverrides = function(repeaterId) {
  1761. var childIds = $ax.getChildElementIdsForRepeater(repeaterId);
  1762. for(var i = childIds; i < childIds.length; i++) $ax.style.deleteElementIdToImageOverride(childIds[i]);
  1763. };
  1764. _actionHandlers.setFocusOnWidget = function(eventInfo, actions, index) {
  1765. var action = actions[index];
  1766. if(action.objectPaths.length > 0) {
  1767. var elementIds = $ax.getElementIdsFromPath(action.objectPaths[0], eventInfo);
  1768. if(elementIds.length > 0) {
  1769. $ax('#' + elementIds[0]).focus();
  1770. //if select text and not in placeholder mode, then select all text
  1771. if(action.selectText && !$ax.placeholderManager.isActive(elementIds[0])) {
  1772. var elementChildren = document.getElementById(elementIds[0]).children;
  1773. //find the input or textarea element
  1774. for(var i = 0; i < elementChildren.length; i++) {
  1775. if (elementChildren[i].id.indexOf('_input') == -1) continue;
  1776. var elementTagName = elementChildren[i].tagName;
  1777. if(elementTagName && (elementTagName.toLowerCase() == "input" || elementTagName.toLowerCase() == "textarea")) {
  1778. elementChildren[i].select();
  1779. }
  1780. }
  1781. }
  1782. }
  1783. }
  1784. _dispatchAction(eventInfo, actions, index + 1);
  1785. };
  1786. _actionHandlers.expandCollapseTree = function(eventInfo, actions, index) {
  1787. var action = actions[index];
  1788. for(var i = 0; i < action.pathToInfo.length; i++) {
  1789. var pair = action.pathToInfo[i];
  1790. var elementIds = $ax.getElementIdsFromPath(pair.treeNodePath, eventInfo);
  1791. for(var j = 0; j < elementIds.length; j++) $ax('#' + elementIds[j]).expanded(pair.expandCollapseInfo.expand);
  1792. }
  1793. _dispatchAction(eventInfo, actions, index + 1);
  1794. };
  1795. _actionHandlers.other = function(eventInfo, actions, index) {
  1796. var action = actions[index];
  1797. $ax.navigate({
  1798. url: $axure.utils.getOtherPath() + "#other=" + encodeURI(action.otherDescription),
  1799. target: "popup",
  1800. includeVariables: false,
  1801. popupOptions: action.popup
  1802. });
  1803. _dispatchAction(eventInfo, actions, index + 1);
  1804. };
  1805. _actionHandlers.fireEvents = function(eventInfo, actions, index) {
  1806. var action = actions[index];
  1807. //look for the nearest element id
  1808. var objId = eventInfo.srcElement;
  1809. var thisWidget = eventInfo.thiswidget;
  1810. var obj = $ax.getObjectFromElementId(objId);
  1811. var rdoId = obj ? $ax.getRdoParentFromElementId(objId) : "";
  1812. var rdo = $ax.getObjectFromElementId(rdoId);
  1813. var page = rdo ? $ax.pageData.masters[rdo.masterId] : $ax.pageData.page;
  1814. // Check if rdo should be this
  1815. var oldIsMasterEvent = eventInfo.isMasterEvent;
  1816. if (obj && $ax.public.fn.IsReferenceDiagramObject(obj.type) && eventInfo.isMasterEvent) {
  1817. rdoId = objId;
  1818. rdo = obj;
  1819. page = $ax.pageData.masters[rdo.masterId];
  1820. }
  1821. for(var i = 0; i < action.firedEvents.length; i++) {
  1822. var firedEvent = action.firedEvents[i];
  1823. var isPage = firedEvent.objectPath.length == 0;
  1824. var targetObjIds = isPage ? [rdoId] : $ax.getElementIdsFromPath(firedEvent.objectPath, eventInfo);
  1825. for (var j = 0; j < targetObjIds.length; j++) {
  1826. var targetObjId = targetObjIds[j];
  1827. var targetObj = isPage ? rdo : $ax.getObjectFromElementId(targetObjId);
  1828. eventInfo.srcElement = targetObjId || '';
  1829. eventInfo.thiswidget = $ax.getWidgetInfo(eventInfo.srcElement);
  1830. eventInfo.isMasterEvent = false;
  1831. var raisedEvents = firedEvent.raisedEventIds;
  1832. if(raisedEvents) {
  1833. for(var k = 0; k < raisedEvents.length; k++) {
  1834. var event = targetObj.interactionMap && targetObj.interactionMap.raised && targetObj.interactionMap.raised[raisedEvents[k]];
  1835. if(event) $ax.event.handleEvent(targetObjId, eventInfo, event, false, true);
  1836. }
  1837. }
  1838. if(isPage) {
  1839. eventInfo.isMasterEvent = true;
  1840. eventInfo.label = $ax.pageData.page.name;
  1841. eventInfo.friendlyType = 'Page';
  1842. }
  1843. var firedTarget = isPage ? page : targetObj;
  1844. var firedEventNames = firedEvent.firedEventNames;
  1845. if(firedEventNames) {
  1846. for(k = 0; k < firedEventNames.length; k++) {
  1847. event = firedTarget.interactionMap && firedTarget.interactionMap[firedEventNames[k]];
  1848. if(event) $ax.event.handleEvent(isPage ? '' : targetObjId, eventInfo, event, false, true);
  1849. }
  1850. }
  1851. if(isPage) eventInfo.isMasterEvent = oldIsMasterEvent;
  1852. }
  1853. eventInfo.srcElement = objId;
  1854. eventInfo.thiswidget = thisWidget;
  1855. eventInfo.isMasterEvent = oldIsMasterEvent;
  1856. }
  1857. _dispatchAction(eventInfo, actions, index + 1);
  1858. };
  1859. });