action.js 103 KB

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