You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2115 lines
102 KiB

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