axQuery.std.js 57 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. // ******* AxQuery Plugins ******** //
  2. $axure.internal(function($ax) {
  3. $ax.constants = {};
  4. $ax.constants.TABLE_TYPE = 'table';
  5. $ax.constants.MENU_OBJECT_TYPE = 'menuObject';
  6. $ax.constants.MASTER_TYPE = 'master';
  7. $ax.constants.PAGE_TYPE = 'page';
  8. $ax.constants.REFERENCE_DIAGRAM_OBJECT_TYPE = 'referenceDiagramObject';
  9. $ax.constants.REPEATER_TYPE = 'repeater';
  10. $ax.constants.DYNAMIC_PANEL_TYPE = 'dynamicPanel';
  11. $ax.constants.LAYER_TYPE = 'layer';
  12. $ax.constants.TEXT_BOX_TYPE = 'textBox';
  13. $ax.constants.TEXT_AREA_TYPE = 'textArea';
  14. $ax.constants.LIST_BOX_TYPE = 'listBox';
  15. $ax.constants.COMBO_BOX_TYPE = 'comboBox';
  16. $ax.constants.CHECK_BOX_TYPE = 'checkbox';
  17. $ax.constants.RADIO_BUTTON_TYPE = 'radioButton';
  18. $ax.constants.BUTTON_TYPE = 'button'; //html button
  19. $ax.constants.IMAGE_MAP_REGION_TYPE = 'imageMapRegion';
  20. $ax.constants.IMAGE_BOX_TYPE = 'imageBox';
  21. $ax.constants.VECTOR_SHAPE_TYPE = 'vectorShape';
  22. $ax.constants.SNAPSHOT_TYPE = 'screenshot';
  23. $ax.constants.TREE_NODE_OBJECT_TYPE = 'treeNodeObject';
  24. $ax.constants.TABLE_CELL_TYPE = 'tableCell';
  25. $ax.constants.VERTICAL_LINE_TYPE = 'verticalLine';
  26. $ax.constants.HORIZONTAL_LINE_TYPE = 'horizontalLine';
  27. $ax.constants.INLINE_FRAME_TYPE = 'inlineFrame';
  28. $ax.constants.CONNECTOR_TYPE = 'connector';
  29. $ax.constants.ALL_TYPE = '*';
  30. $ax.public.fn.IsTable = function (type) { return type == $ax.constants.TABLE_TYPE; }
  31. $ax.public.fn.IsMenuObject = function (type) { return type == $ax.constants.MENU_OBJECT_TYPE; }
  32. $ax.public.fn.IsMaster = function (type) { return type == $ax.constants.MASTER_TYPE; }
  33. $ax.public.fn.IsPage = function (type) { return type == $ax.constants.PAGE_TYPE; }
  34. $ax.public.fn.IsReferenceDiagramObject = function (type) { return type == $ax.constants.REFERENCE_DIAGRAM_OBJECT_TYPE; }
  35. $ax.public.fn.IsRepeater = function (type) { return type == $ax.constants.REPEATER_TYPE; }
  36. $ax.public.fn.IsDynamicPanel = function (type) { return type == $ax.constants.DYNAMIC_PANEL_TYPE; }
  37. $ax.public.fn.IsLayer = function (type) { return type == $ax.constants.LAYER_TYPE; }
  38. $ax.public.fn.IsTextBox = function (type) { return type == $ax.constants.TEXT_BOX_TYPE; }
  39. $ax.public.fn.IsTextArea = function (type) { return type == $ax.constants.TEXT_AREA_TYPE; }
  40. $ax.public.fn.IsListBox = function (type) { return type == $ax.constants.LIST_BOX_TYPE; }
  41. $ax.public.fn.IsComboBox = function (type) { return type == $ax.constants.COMBO_BOX_TYPE; }
  42. $ax.public.fn.IsCheckBox = function (type) { return type == $ax.constants.CHECK_BOX_TYPE; }
  43. $ax.public.fn.IsRadioButton = function (type) { return type == $ax.constants.RADIO_BUTTON_TYPE; }
  44. $ax.public.fn.IsButton = function (type) { return type == $ax.constants.BUTTON_TYPE; }
  45. $ax.public.fn.IsIamgeMapRegion = function (type) { return type == $ax.constants.IMAGE_MAP_REGION_TYPE; }
  46. $ax.public.fn.IsImageBox = function (type) { return type == $ax.constants.IMAGE_BOX_TYPE; }
  47. $ax.public.fn.IsVector = function (type) { return type == $ax.constants.VECTOR_SHAPE_TYPE; }
  48. $ax.public.fn.IsSnapshot = function (type) { return type == $ax.constants.SNAPSHOT_TYPE; }
  49. $ax.public.fn.IsTreeNodeObject = function (type) { return type == $ax.constants.TREE_NODE_OBJECT_TYPE; }
  50. $ax.public.fn.IsTableCell = function (type) { return type == $ax.constants.TABLE_CELL_TYPE; }
  51. $ax.public.fn.IsInlineFrame = function (type) { return type == $ax.constants.INLINE_FRAME_TYPE; }
  52. $ax.public.fn.IsConnector = function (type) { return type == $ax.constants.CONNECTOR_TYPE; }
  53. var PLAIN_TEXT_TYPES = [$ax.constants.TEXT_BOX_TYPE, $ax.constants.TEXT_AREA_TYPE, $ax.constants.LIST_BOX_TYPE,
  54. $ax.constants.COMBO_BOX_TYPE, $ax.constants.CHECK_BOX_TYPE, $ax.constants.RADIO_BUTTON_TYPE, $ax.constants.BUTTON_TYPE];
  55. var _addJQueryFunction = function(name) {
  56. $ax.public.fn[name] = function() {
  57. var val = $.fn[name].apply(this.jQuery(), arguments);
  58. return arguments[0] ? this : val;
  59. };
  60. };
  61. var _jQueryFunctionsToAdd = ['text', 'val', 'css'];
  62. for (var jqueryFunctionIndex = 0; jqueryFunctionIndex < _jQueryFunctionsToAdd.length; jqueryFunctionIndex++) _addJQueryFunction(_jQueryFunctionsToAdd[jqueryFunctionIndex]);
  63. // var _addJQueryEventFunction = function(name) {
  64. // $ax.public.fn[name] = function() {
  65. // $.fn[name].apply(this.jQuery(), arguments);
  66. // return this;
  67. // };
  68. // };
  69. // var _addJQueryEventFunction = function(name) {
  70. // $ax.public.fn[name] = (function(nn) {
  71. // return function() {
  72. // $.fn[nn].apply(this.jQuery(), arguments);
  73. // return this;
  74. // };
  75. // })(name);
  76. // };
  77. var _addJQueryEventFunction = function(name) {
  78. $ax.public.fn[name] = function() {
  79. //With Martin - No idea why this is necessary. We tried encapsulating the function thinking it was related to closure (above),
  80. //but that didn't fix the problem. If we don't add this Repeaters will give "Uncaught TypeError: Object #<Object> has no method 'apply'"
  81. //here (but Indeterminately, often on larger/slower Repeaters) because it is Undefined. However it seems the catch is never hit
  82. //if we surround the statement with the try/catch. Perhaps the try/catch block creates a scope or closure.
  83. try {
  84. $.fn[name].apply(this.jQuery(), arguments);
  85. } catch(e) {
  86. console.log("Couldn't find the event: " + name);
  87. }
  88. return this;
  89. };
  90. };
  91. var _jQueryEventFunctionsToAdd = ['click', 'mouseenter', 'mouseleave', 'bind'];
  92. for(var jqueryEventIndex = 0; jqueryEventIndex < _jQueryEventFunctionsToAdd.length; jqueryEventIndex++) _addJQueryEventFunction(_jQueryEventFunctionsToAdd[jqueryEventIndex]);
  93. $ax.public.fn.openLink = function(url, includeVariables) {
  94. this.jQuery().each(function() {
  95. if(!($(this).is('iframe'))) {
  96. return;
  97. }
  98. var objIframe = $(this).get(0);
  99. $ax.navigate({
  100. url: url,
  101. target: "frame",
  102. includeVariables: includeVariables,
  103. frame: objIframe
  104. });
  105. });
  106. return this;
  107. };
  108. $ax.public.fn.SetPanelState = function(stateNumber, options, showWhenSet) {
  109. var animateInInfo = _getAnimateInfo(options && options.animateIn, 500);
  110. var animateOutInfo = _getAnimateInfo(options && options.animateOut, 500);
  111. var elementIds = this.getElementIds();
  112. for(var index = 0; index < elementIds.length; index++) {
  113. var elementId = elementIds[index];
  114. if ($ax.public.fn.IsDynamicPanel($ax.getTypeFromElementId(elementId))) {
  115. var stateName = $ax.visibility.GetPanelStateId(elementId, Number(stateNumber) - 1);
  116. var wasVisible = $ax.visibility.IsIdVisible(elementId);
  117. // If compressing because you are fit to content and the change of state may change size, must be before the change.
  118. if(options.compress && $ax.dynamicPanelManager.isIdFitToContent(elementId) && wasVisible) {
  119. $ax.dynamicPanelManager.compressDelta(elementId, $ax.visibility.GetPanelState(elementId), stateName, options.vertical, options.compressEasing, options.compressDuration);
  120. }
  121. $ax.visibility.SetPanelState(elementId, stateName, animateOutInfo.easingType, animateOutInfo.direction, animateOutInfo.duration,
  122. animateInInfo.easingType, animateInInfo.direction, animateInInfo.duration, showWhenSet);
  123. // If compressing because of a show, must be after state is set.
  124. if(options.compress && !wasVisible && showWhenSet) {
  125. $ax.dynamicPanelManager.compressToggle(elementId, options.vertical, true, options.compressEasing, options.compressDuration);
  126. }
  127. }
  128. }
  129. return this;
  130. };
  131. $ax.public.fn.show = function(options, eventInfo) {
  132. var elementIds = this.getElementIds();
  133. for(var index = 0; index < elementIds.length; index++) {
  134. var elementId = elementIds[index];
  135. var lightboxId = $ax.repeater.applySuffixToElementId(elementId, '_lightbox');
  136. var lightbox = $jobj(lightboxId);
  137. if(options && options.showType == 'lightbox') {
  138. $ax.flyoutManager.unregisterPanel(elementId, true);
  139. // Add lightbox if there isn't one
  140. if(lightbox.length == 0) {
  141. lightbox = $('<div></div>');
  142. lightbox.attr('id', lightboxId);
  143. var color = 'rgb(' + options.lightbox.r + ',' + options.lightbox.g + ',' + options.lightbox.b + ')';
  144. lightbox.css({
  145. position: 'fixed',
  146. left: '0px',
  147. top: '0px',
  148. width: '10000px',
  149. height: '10000px',
  150. 'background-color': color,
  151. opacity: options.lightbox.a / 255
  152. });
  153. var parents = $ax('#' + elementId).getParents(true, ['dynamicPanel'])[0];
  154. var fixedParentPanelId = undefined;
  155. for(var j = 0; j < parents.length; j++) {
  156. var parentId = parents[j];
  157. if($jobj(parentId).css('z-index') != 'auto' || $ax.features.supports.mobile) {
  158. fixedParentPanelId = parents[j];
  159. break;
  160. }
  161. }
  162. if(!fixedParentPanelId) $('#base').append(lightbox);
  163. else $jobj(fixedParentPanelId).append(lightbox);
  164. var wasVisible = $ax.visibility.IsIdVisible(elementId);
  165. (function(lightbox, query) {
  166. $ax.event.attachClick(lightbox, function() {
  167. $ax.action.addAnimation(elementId, $ax.action.queueTypes.fade, function() {
  168. if(!wasVisible) query.hide();
  169. else $ax.action.fireAnimationFromQueue(elementId, $ax.action.queueTypes.fade);
  170. lightbox.remove();
  171. });
  172. });
  173. })(lightbox, this);
  174. }
  175. $ax.legacy.BringToFront(lightboxId, true);
  176. $ax.legacy.BringToFront(elementId, true);
  177. } else if(options && options.showType == 'flyout') {
  178. // Remove lightbox if there is one
  179. lightbox.remove();
  180. var src = eventInfo.thiswidget;
  181. var target = $ax.getWidgetInfo(elementId);
  182. var rects = {};
  183. if(src.valid) rects.src = $ax.geometry.genRect(src, true);
  184. if(target.valid) rects.target = $ax.geometry.genRect(target, true);
  185. $ax.flyoutManager.registerFlyout(rects, elementId, eventInfo.srcElement);
  186. //$ax.style.AddRolloverOverride(elementId);
  187. $ax.legacy.BringToFront(elementId);
  188. } else {
  189. // Remove lightbox, unregister flyout
  190. lightbox.remove();
  191. $ax.flyoutManager.unregisterPanel(elementId, true);
  192. }
  193. _setVisibility(elementId, true, options);
  194. }
  195. return this;
  196. };
  197. var _getAnimateInfo = function (options, defaultDuration, useHide) {
  198. var animateInfo = {
  199. duration: options && (useHide ? options.durationHide : options.duration) || defaultDuration
  200. };
  201. var easing = options && (useHide ? options.easingHide : options.easing) || 'none';
  202. switch (easing) {
  203. case 'fade':
  204. animateInfo.easingType = 'fade';
  205. animateInfo.direction = '';
  206. break;
  207. case 'slideLeft':
  208. animateInfo.easingType = 'swing';
  209. animateInfo.direction = 'left';
  210. break;
  211. case 'slideRight':
  212. animateInfo.easingType = 'swing';
  213. animateInfo.direction = 'right';
  214. break;
  215. case 'slideUp':
  216. animateInfo.easingType = 'swing';
  217. animateInfo.direction = 'up';
  218. break;
  219. case 'slideDown':
  220. ;
  221. animateInfo.easingType = 'swing';
  222. animateInfo.direction = 'down';
  223. break;
  224. case 'flipLeft':
  225. animateInfo.easingType = 'flip';
  226. animateInfo.direction = 'left';
  227. break;
  228. case 'flipRight':
  229. animateInfo.easingType = 'flip';
  230. animateInfo.direction = 'right';
  231. break;
  232. case 'flipUp':
  233. animateInfo.easingType = 'flip';
  234. animateInfo.direction = 'up';
  235. break;
  236. case 'flipDown':
  237. animateInfo.easingType = 'flip';
  238. animateInfo.direction = 'down';
  239. break;
  240. default:
  241. animateInfo.easingType = 'none';
  242. animateInfo.direction = '';
  243. }
  244. return animateInfo;
  245. };
  246. $ax.public.fn.hide = function(options) {
  247. var elementIds = this.getElementIds();
  248. for(var index = 0; index < elementIds.length; index++) {
  249. var elementId = elementIds[index];
  250. // var wasShown = $ax.visibility.IsIdVisible(elementId);
  251. _setVisibility(elementId, false, options);
  252. }
  253. return this;
  254. };
  255. $ax.public.fn.toggleVisibility = function(options) {
  256. var elementIds = this.getElementIds();
  257. for (var index = 0; index < elementIds.length; index++) {
  258. var elementId = elementIds[index];
  259. var show = !$ax.visibility.IsIdVisible(elementId);
  260. _setVisibility(elementId, show, options, !show);
  261. }
  262. return this;
  263. };
  264. var _setVisibility = function (elementId, value, options, useHide) {
  265. var animateInfo = _getAnimateInfo(options, 0, useHide);
  266. var wasShown = $ax.visibility.IsIdVisible(elementId);
  267. var compress = options && options.showType == 'compress' && wasShown != value;
  268. var compressed = false;
  269. var onComplete = function() {
  270. if(compress && !compressed) $ax.dynamicPanelManager.compressToggle(elementId, options.vertical, value, options.compressEasing, options.compressDuration);
  271. compressed = true;
  272. $ax.dynamicPanelManager.fitParentPanel(elementId);
  273. };
  274. $ax.visibility.SetWidgetVisibility(elementId, {
  275. value: value,
  276. easing: animateInfo.easingType,
  277. direction: animateInfo.direction,
  278. duration: animateInfo.duration,
  279. fire: true,
  280. onComplete: onComplete
  281. });
  282. if(compress && !compressed) $ax.dynamicPanelManager.compressToggle(elementId, options.vertical, value, options.compressEasing, options.compressDuration);
  283. compressed = true;
  284. if(options && options.bringToFront) $ax.legacy.BringToFront(elementId);
  285. };
  286. $ax.public.fn.setOpacity = function(opacity, easing, duration) {
  287. if(!easing || ! duration) {
  288. easing = 'none';
  289. duration = 0;
  290. }
  291. var elementIds = this.getElementIds();
  292. for(var index = 0; index < elementIds.length; index++) {
  293. var elementId = elementIds[index];
  294. var onComplete = function() {
  295. $ax.action.fireAnimationFromQueue(elementId, $ax.action.queueTypes.fade);
  296. };
  297. var query = $jobj(elementId);
  298. if(duration == 0 || easing == 'none') {
  299. query.css('opacity', opacity);
  300. onComplete();
  301. } else query.animate({ opacity: opacity }, { duration: duration, easing: easing, queue: false, complete: onComplete });
  302. }
  303. }
  304. //move one widget. I didn't combine moveto and moveby, since this is in .public, and separate them maybe more clear for the user
  305. var _move = function (elementId, x, y, options, moveTo) {
  306. if(!options.easing) options.easing = 'none';
  307. if(!options.duration) options.duration = 500;
  308. var obj = $obj(elementId);
  309. // Layer move using container now.
  310. if($ax.public.fn.IsLayer(obj.type)) {
  311. var moveInfo = $ax.move.RegisterMoveInfo(elementId, x, y, moveTo, options);
  312. //$ax.event.raiseSyntheticEvent(elementId, "onMove");
  313. //var childrenIds = $ax.public.fn.getLayerChildrenDeep(elementId, true);
  314. //for(var i = 0; i < childrenIds.length; i++) $ax.event.raiseSyntheticEvent(childrenIds[i], 'onMove');
  315. $ax.move.MoveWidget(elementId, x, y, options, moveTo,
  316. function () {
  317. if(options.onComplete) options.onComplete();
  318. $ax.dynamicPanelManager.fitParentPanel(elementId);
  319. }, false, undefined, moveInfo);
  320. //var childrenIds = $ax.public.fn.getLayerChildrenDeep(elementId);
  321. //if(childrenIds.length == 0) return;
  322. //for(var i = 0; i < childrenIds.length - 1; i++) {
  323. // $ax.move.MoveWidget(childrenIds[i], x, y, easing, duration, moveTo,
  324. // function() { $ax.dynamicPanelManager.fitParentPanel(childrenIds[i]); }, false);
  325. //}
  326. //$ax.move.MoveWidget(childrenIds[i], x, y, easing, duration, moveTo,
  327. // function () { $ax.dynamicPanelManager.fitParentPanel(childrenIds[i]); }, true, null, elementId);
  328. } else {
  329. var xDelta = x;
  330. var yDelta = y;
  331. if (moveTo) {
  332. var jobj = $jobj(elementId);
  333. var left = Number(jobj.css('left').replace('px', ''));
  334. var top = Number(jobj.css('top').replace('px', ''));
  335. xDelta = x - left;
  336. yDelta = y - top;
  337. }
  338. moveInfo = $ax.move.RegisterMoveInfo(elementId, xDelta, yDelta, false, options);
  339. //$ax.event.raiseSyntheticEvent(elementId, "onMove");
  340. $ax.move.MoveWidget(elementId, xDelta, yDelta, options, false,
  341. function () { $ax.dynamicPanelManager.fitParentPanel(elementId); }, true, undefined, moveInfo);
  342. }
  343. };
  344. $ax.public.fn.moveTo = function (x, y, options) {
  345. var elementIds = this.getElementIds();
  346. for(var index = 0; index < elementIds.length; index++) {
  347. _move(elementIds[index], x, y, options, true);
  348. }
  349. return this;
  350. };
  351. $ax.public.fn.moveBy = function (x, y, options) {
  352. var elementIds = this.getElementIds();
  353. if(x == 0 && y == 0) {
  354. for(var i = 0; i < elementIds.length; i++) {
  355. var elementId = elementIds[i];
  356. $ax.move.nopMove(elementId, options);
  357. //$ax.event.raiseSyntheticEvent(elementId, "onMove");
  358. $ax.action.fireAnimationFromQueue(elementId, $ax.action.queueTypes.move);
  359. //if($axure.fn.IsLayer($obj(elementId).type)) {
  360. // var childrenIds = $ax.public.fn.getLayerChildrenDeep(elementId, true);
  361. // for(var j = 0; j < childrenIds.length; j++) $ax.event.raiseSyntheticEvent(childrenIds[j], 'onMove');
  362. //}
  363. }
  364. return this;
  365. }
  366. for(var index = 0; index < elementIds.length; index++) {
  367. _move(elementIds[index], x, y, options, false);
  368. }
  369. return this;
  370. };
  371. $ax.public.fn.circularMoveAndRotate = function(degreeChange, options, centerPointLeft, centerPointTop, doRotation, moveDelta, resizeOffset, rotatableMove, moveComplete) {
  372. if(!rotatableMove) rotatableMove = { x: 0, y: 0 };
  373. var elementIds = this.getElementIds();
  374. for(var index = 0; index < elementIds.length; index++) {
  375. var elementId = elementIds[index];
  376. var onComplete = function () {
  377. if (doRotation) $ax.dynamicPanelManager.fitParentPanel(elementId);
  378. if (moveComplete) moveComplete();
  379. }
  380. $ax.move.circularMove(elementId, degreeChange, { x: centerPointLeft, y: centerPointTop }, moveDelta, rotatableMove, resizeOffset, options, true, onComplete);
  381. if(doRotation) $ax.move.rotate(elementId, degreeChange, options.easing, options.duration, false, true, function () { $ax.dynamicPanelManager.fitParentPanel(elementId); });
  382. else $ax.action.fireAnimationFromQueue(elementId, $ax.action.queueTypes.rotate);
  383. }
  384. };
  385. $ax.public.fn.rotate = function (degree, easing, duration, to, axShouldFire) {
  386. var elementIds = this.getElementIds();
  387. // this function will no longer handle compound vectors.
  388. for(var index = 0; index < elementIds.length; index++) {
  389. var elementId = elementIds[index];
  390. degree = parseFloat(degree);
  391. $ax.move.rotate(elementId, degree, easing, duration, to, axShouldFire, function () { $ax.dynamicPanelManager.fitParentPanel(elementId); });
  392. }
  393. };
  394. $ax.public.fn.resize = function(newLocationAndSizeCss, resizeInfo, axShouldFire, moves, onCompletedFunc) {
  395. var elementIds = this.getElementIds();
  396. if(!elementIds) return;
  397. for(var index = 0; index < elementIds.length; index++) {
  398. var elementId = elementIds[index];
  399. var oldSize = $ax('#' + elementId).size();
  400. var oldWidth = oldSize.width;
  401. var oldHeight = oldSize.height;
  402. var query = $jobj(elementId);
  403. var obj = $obj(elementId);
  404. var isDynamicPanel = $ax.public.fn.IsDynamicPanel(obj.type);
  405. if(isDynamicPanel) {
  406. // No longer fitToContent, calculate additional styling that needs to be done.
  407. $ax.dynamicPanelManager.setFitToContentCss(elementId, false, oldWidth, oldHeight);
  408. if((obj.fixedHorizontal && obj.fixedHorizontal == 'center') || (obj.fixedVertical && obj.fixedVertical == 'middle')) {
  409. moves = true;
  410. var loc = $ax.dynamicPanelManager.getFixedPosition(elementId, oldWidth, oldHeight, newLocationAndSizeCss.width, newLocationAndSizeCss.height);
  411. if(loc) {
  412. if(loc[0] != 0 && !$ax.dynamicPanelManager.isPercentWidthPanel(obj)) newLocationAndSizeCss['margin-left'] = '+=' + loc[0];
  413. if(loc[1] != 0) newLocationAndSizeCss['margin-top'] = '+=' + loc[1];
  414. }
  415. }
  416. var onComplete = function() {
  417. $ax.flyoutManager.updateFlyout(elementId);
  418. $ax.dynamicPanelManager.fitParentPanel(elementId);
  419. $ax.dynamicPanelManager.updatePanelPercentWidth(elementId);
  420. $ax.dynamicPanelManager.updatePanelContentPercentWidth(elementId);
  421. if(axShouldFire) $ax.action.fireAnimationFromQueue(elementId, $ax.action.queueTypes.resize);
  422. if(moves) {
  423. if(axShouldFire) $ax.action.fireAnimationFromQueue(elementId, $ax.action.queueTypes.move);
  424. }
  425. if(onCompletedFunc) onCompletedFunc();
  426. $ax.event.raiseSyntheticEvent(elementId, 'onResize');
  427. };
  428. } else {
  429. //if contains text
  430. var textChildren = query.children('div.text');
  431. if(textChildren && textChildren.length != 0) {
  432. var textDivId = textChildren.attr('id');
  433. var textObj = $ax('#' + textDivId);
  434. var leftPadding = textObj.left();
  435. var rightPadding = oldWidth - leftPadding - textObj.width();
  436. //greater or equal to 1px
  437. var newTextWidth = Math.max(newLocationAndSizeCss.width - leftPadding - rightPadding, 1);
  438. var textChildCss = { width: newTextWidth };
  439. var textStepFunction = function() {
  440. //change the width of the text div may effect the height
  441. //var currentTextHeight = Number($(textChildren.children('p')[0]).css('height').replace('px', ''));
  442. //textChildren.css('height', currentTextHeight);
  443. var display = $ax.public.fn.displayHackStart(document.getElementById(textDivId));
  444. $ax.style.updateTextAlignmentForVisibility(textDivId, true);
  445. $ax.public.fn.displayHackEnd(display);
  446. };
  447. }
  448. //get all the other children that matters
  449. onComplete = function() {
  450. $ax.dynamicPanelManager.fitParentPanel(elementId);
  451. if(axShouldFire) {
  452. $ax.action.fireAnimationFromQueue(elementId, $ax.action.queueTypes.resize);
  453. if(moves) $ax.action.fireAnimationFromQueue(elementId, $ax.action.queueTypes.move);
  454. }
  455. if(onCompletedFunc) onCompletedFunc();
  456. $ax.event.raiseSyntheticEvent(elementId, 'onResize');
  457. };
  458. }
  459. var children = query.children().not('div.text');
  460. while(children && children.length && $(children[0]).attr('id').indexOf('container') != -1) {
  461. children = children.children().not('div.text');
  462. }
  463. if(children && children.length !== 0) {
  464. var childAnimationArray = [];
  465. var isConnector = $ax.public.fn.IsConnector($obj(elementId).type);
  466. children.each(function (i, child) {
  467. var childCss = {
  468. width: newLocationAndSizeCss.width,
  469. height: newLocationAndSizeCss.height
  470. };
  471. //$ax.size() use outerWidth/Height(false), which include padding and borders(no margins)
  472. var childSizingObj = $ax('#' + child.id).size();
  473. var differentSizedImage = childSizingObj.width - oldWidth != 0 || childSizingObj.height - oldHeight != 0;
  474. if ((differentSizedImage || isConnector) && child.tagName == 'IMG') {
  475. //oldwidth is zero for connectors
  476. var widthOffset = oldWidth ? (childSizingObj.width - oldWidth) * newLocationAndSizeCss.width / oldWidth : childSizingObj.width;
  477. var heightOffset = oldHeight ? (childSizingObj.height - oldHeight) * newLocationAndSizeCss.height / oldHeight : childSizingObj.height;
  478. childCss.width += widthOffset;
  479. childCss.height += heightOffset;
  480. }
  481. //there are elements like inputs, come with a padding and border, so need to use outerwidth for starting point, due to jquery 1.7 css() on width/height bugs
  482. if($(child).css('position') === 'absolute') {
  483. if(child.offsetLeft) {
  484. childSizingObj.left = child.offsetLeft;
  485. childCss.left = oldWidth ? child.offsetLeft * newLocationAndSizeCss.width / oldWidth : child.offsetLeft; //- transformedShift.x;
  486. }
  487. if(child.offsetTop) {
  488. childSizingObj.top = child.offsetTop;
  489. childCss.top = oldHeight ? child.offsetTop * newLocationAndSizeCss.height / oldHeight : child.offsetTop; //- transformedShift.y;
  490. }
  491. }
  492. childAnimationArray.push({ obj: child, sizingObj: childSizingObj, sizingCss: childCss });
  493. });
  494. }
  495. if(!resizeInfo.easing || resizeInfo.easing == 'none') {
  496. query.animate(newLocationAndSizeCss, 0);
  497. if(childAnimationArray) {
  498. $(childAnimationArray).each(function (i, animationObj) {
  499. if(animationObj.resizeMatrixFunction) {
  500. $(animationObj.obj).css($ax.public.fn.setTransformHowever(animationObj.resizeMatrixFunction(animationObj.width, animationObj.height)));
  501. } else {
  502. $(animationObj.obj).animate(animationObj.sizingCss, 0);
  503. }
  504. });
  505. }
  506. //if(childCss) children.animate(childCss, 0);
  507. //if(sketchyImage && sketchyImageCss) $(sketchyImage).animate(sketchyImageCss, 0);
  508. if(textChildCss) {
  509. textChildren.animate(textChildCss, {
  510. duration: 0,
  511. step: textStepFunction
  512. });
  513. }
  514. onComplete();
  515. } else {
  516. if(childAnimationArray) {
  517. $(childAnimationArray).each(function (i, animationObj) {
  518. if(animationObj.resizeMatrixFunction) {
  519. $(animationObj.sizingObj).animate(animationObj.sizingCss, {
  520. queue: false,
  521. duration: resizeInfo.duration,
  522. easing: resizeInfo.easing,
  523. step: function (now) {
  524. var widthRatio = (animationObj.width - 1.0) * now + 1.0;
  525. var heightRatio = (animationObj.height - 1.0) * now + 1.0;
  526. $(animationObj.obj).css($ax.public.fn.setTransformHowever(animationObj.resizeMatrixFunction(widthRatio, heightRatio)));
  527. }
  528. });
  529. } else {
  530. $(animationObj.sizingObj).animate(animationObj.sizingCss, {
  531. queue: false,
  532. duration: resizeInfo.duration,
  533. easing: resizeInfo.easing,
  534. step: function (now, tween) {
  535. $(animationObj.obj).css(tween.prop, now);
  536. }
  537. });
  538. }
  539. });
  540. }
  541. if(textChildCss) {
  542. textChildren.animate(textChildCss, {
  543. queue: false,
  544. duration: resizeInfo.duration,
  545. easing: resizeInfo.easing,
  546. step: textStepFunction
  547. });
  548. }
  549. if (isDynamicPanel) query.animate(newLocationAndSizeCss, { queue: false, duration: resizeInfo.duration, easing: resizeInfo.easing, complete: onComplete });
  550. var locObj = {
  551. left: $ax.public.fn.GetFieldFromStyle(query, 'left'), top: $ax.public.fn.GetFieldFromStyle(query, 'top'),
  552. width: $ax.public.fn.GetFieldFromStyle(query, 'width'), height: $ax.public.fn.GetFieldFromStyle(query, 'height'),
  553. };
  554. $(locObj).animate(newLocationAndSizeCss, {
  555. queue: false,
  556. duration: resizeInfo.duration,
  557. easing: resizeInfo.easing,
  558. step: function(now, tween) {
  559. query.css(tween.prop, now);
  560. },
  561. complete: onComplete
  562. });
  563. }
  564. }
  565. };
  566. $ax.public.fn.bringToFront = function() {
  567. var elementIds = this.getElementIds();
  568. for(var index = 0; index < elementIds.length; index++) { $ax.legacy.BringToFront(elementIds[index]); }
  569. return this;
  570. };
  571. $ax.public.fn.sendToBack = function() {
  572. var elementIds = this.getElementIds();
  573. for(var index = 0; index < elementIds.length; index++) { $ax.legacy.SendToBack(elementIds[index]); }
  574. return this;
  575. };
  576. $ax.public.fn.text = function() {
  577. if(arguments[0] == undefined) {
  578. var firstId = this.getElementIds()[0];
  579. if(!firstId) { return undefined; }
  580. return getWidgetText(firstId);
  581. } else {
  582. var elementIds = this.getElementIds();
  583. for(var index = 0; index < elementIds.length; index++) {
  584. var currentItem = elementIds[index];
  585. var widgetType = $ax.getTypeFromElementId(currentItem);
  586. if($ax.public.fn.IsTextBox(widgetType) || $ax.public.fn.IsTextArea(widgetType)) { //For non rtf
  587. SetWidgetFormText(currentItem, arguments[0]);
  588. } else {
  589. var idRtf = '#' + currentItem;
  590. if($(idRtf).length == 0) idRtf = '#u' + (Number(currentItem.substring(1)) + 1);
  591. if($(idRtf).length != 0) {
  592. //If the richtext div already has some text in it,
  593. //preserve only the first style and get rid of the rest
  594. //If no pre-existing p-span tags, don't do anything
  595. if($(idRtf).find('p').find('span').length > 0) {
  596. $(idRtf).find('p:not(:first)').remove();
  597. $(idRtf).find('p').find('span:not(:first)').remove();
  598. //Replace new-lines with NEWLINE token, then html encode the string,
  599. //finally replace NEWLINE token with linebreak
  600. var textWithLineBreaks = arguments[0].replace(/\n/g, '--NEWLINE--');
  601. var textHtml = $('<div/>').text(textWithLineBreaks).html();
  602. $(idRtf).find('span').html(textHtml.replace(/--NEWLINE--/g, '<br>'));
  603. }
  604. }
  605. }
  606. }
  607. return this;
  608. }
  609. };
  610. var getWidgetText = function(id) {
  611. var idQuery = $jobj(id);
  612. var inputQuery = $jobj($ax.INPUT(id));
  613. if(inputQuery.length) idQuery = inputQuery;
  614. if (idQuery.is('input') && ($ax.public.fn.IsCheckBox(idQuery.attr('type')) || idQuery.attr('type') == 'radio')) {
  615. idQuery = idQuery.parent().find('label').find('div');
  616. }
  617. if(idQuery.is('div')) {
  618. var $rtfObj = idQuery.hasClass('text') ? idQuery : idQuery.find('.text');
  619. if($rtfObj.length == 0) return undefined;
  620. var textOut = '';
  621. $rtfObj.children('p').each(function(index) {
  622. if(index != 0) textOut += '\n';
  623. //Replace line breaks (set in SetWidgetRichText) with newlines and nbsp's with regular spaces.
  624. var htmlContent = $(this).html().replace(/<br[^>]*>/ig, '\n').replace(/&nbsp;/ig, ' ');
  625. textOut += $(htmlContent).text();
  626. });
  627. return textOut;
  628. } else {
  629. var val = idQuery.val();
  630. return val == undefined ? '' : val;
  631. }
  632. };
  633. $ax.public.fn.setRichTextHtml = function() {
  634. if(arguments[0] == undefined) {
  635. //No getter function, so just return undefined
  636. return undefined;
  637. } else {
  638. var elementIds = this.getElementIds();
  639. for(var index = 0; index < elementIds.length; index++) {
  640. var currentItem = elementIds[index];
  641. var widgetType = $ax.getTypeFromElementId(currentItem);
  642. if ($ax.public.fn.IsTextBox(widgetType) || $ax.public.fn.IsTextArea(widgetType)) { //Do nothing for non rtf
  643. continue;
  644. } else {
  645. //TODO -- [mas] fix this!
  646. var idRtf = '#' + currentItem;
  647. if($(idRtf).length == 0) idRtf = '#u' + (parseInt(currentItem.substring(1)) + 1);
  648. if($(idRtf).length != 0) SetWidgetRichText(idRtf, arguments[0]);
  649. }
  650. }
  651. return this;
  652. }
  653. };
  654. $ax.public.fn.value = function() {
  655. if(arguments[0] == undefined) {
  656. var firstId = this.getElementIds()[0];
  657. if(!firstId) {
  658. return undefined;
  659. }
  660. var widgetType = $ax.getTypeFromElementId(firstId);
  661. if ($ax.public.fn.IsComboBox(widgetType) || $ax.public.fn.IsListBox(widgetType)) { //for select lists and drop lists
  662. return $('#' + firstId + ' :selected').text();
  663. } else if ($ax.public.fn.IsCheckBox(widgetType) || $ax.public.fn.IsRadioButton(widgetType)) { //for radio/checkboxes
  664. return $('#' + firstId + '_input').is(':checked');
  665. } else if ($ax.public.fn.IsTextBox(widgetType)) { //for text box
  666. return $('#' + firstId + '_input').val();
  667. } else { //for text based form elements
  668. return this.jQuery().first().val();
  669. }
  670. } else {
  671. var elementIds = this.getElementIds();
  672. for(var index = 0; index < elementIds.length; index++) {
  673. var widgetType = $ax.getTypeFromElementId(elementIds[index]);
  674. var elementIdQuery = $('#' + elementIds[index]);
  675. if ($ax.public.fn.IsCheckBox(widgetType) || $ax.public.fn.IsRadioButton(widgetType)) { //for radio/checkboxes
  676. if(arguments[0] == true) {
  677. elementIdQuery.attr('checked', true);
  678. } else if(arguments[0] == false) {
  679. elementIdQuery.removeAttr('checked');
  680. }
  681. } else { //For select lists, drop lists, text based form elements
  682. elementIdQuery.val(arguments[0]);
  683. }
  684. }
  685. return this;
  686. }
  687. };
  688. $ax.public.fn.checked = function() {
  689. if(arguments[0] == undefined) {
  690. return this.selected();
  691. } else {
  692. this.selected(arguments[0]);
  693. return this;
  694. }
  695. };
  696. var _getRelativeLeft = function (id, parent) {
  697. var currentNode = window.document.getElementById(id).offsetParent;
  698. var left = $ax('#' + id).left(true);
  699. while (currentNode != null && currentNode.tagName != "BODY" && currentNode != parent) {
  700. left += currentNode.offsetLeft;
  701. currentNode = currentNode.offsetParent;
  702. }
  703. return left;
  704. };
  705. var _getRelativeTop = function(id, parent) {
  706. var currentNode = window.document.getElementById(id).offsetParent;
  707. var top = $ax('#' + id).top(true);
  708. while(currentNode != null && currentNode.tagName != "BODY" && currentNode != parent) {
  709. top += currentNode.offsetTop;
  710. currentNode = currentNode.offsetParent;
  711. }
  712. return top;
  713. };
  714. var _scrollHelper = function(id, scrollX, scrollY, easing, duration) {
  715. var target = window.document.getElementById(id);
  716. var scrollable = $ax.legacy.GetScrollable(target);
  717. var targetLeft = _getRelativeLeft(id, scrollable);
  718. var targetTop = _getRelativeTop(id, scrollable);
  719. if(!scrollX) targetLeft = scrollable.scrollLeft;
  720. if(!scrollY) targetTop = scrollable.scrollTop;
  721. var $scrollable = $(scrollable);
  722. if($scrollable.is('body')) {
  723. $scrollable = $('html,body');
  724. }
  725. if(easing == 'none') {
  726. if(scrollY) $scrollable.scrollTop(targetTop);
  727. if(scrollX) $scrollable.scrollLeft(targetLeft);
  728. } else {
  729. if(!scrollX) {
  730. $scrollable.animate({ scrollTop: targetTop }, duration, easing);
  731. } else if(!scrollY) {
  732. $scrollable.animate({ scrollLeft: targetLeft }, duration, easing);
  733. } else {
  734. $scrollable.animate({ scrollTop: targetTop, scrollLeft: targetLeft }, duration, easing);
  735. }
  736. }
  737. };
  738. $ax.public.fn.scroll = function(scrollOption) {
  739. var easing = 'none';
  740. var duration = 500;
  741. if(scrollOption && scrollOption.easing) {
  742. easing = scrollOption.easing;
  743. if(scrollOption.duration) {
  744. duration = scrollOption.duration;
  745. }
  746. }
  747. var scrollX = true;
  748. var scrollY = true;
  749. if(scrollOption.direction == 'vertical') {
  750. scrollX = false;
  751. } else if(scrollOption.direction == 'horizontal') {
  752. scrollY = false;
  753. }
  754. var elementIds = this.getElementIds();
  755. for(var index = 0; index < elementIds.length; index++) {
  756. // if($ax.getTypeFromElementId(elementIds[index]) == IMAGE_MAP_REGION_TYPE) {
  757. _scrollHelper(elementIds[index], scrollX, scrollY, easing, duration);
  758. // }
  759. }
  760. return this;
  761. };
  762. $ax.public.fn.enabled = function() {
  763. if(arguments[0] == undefined) {
  764. var firstId = this.getElementIds()[0];
  765. if(!firstId) return undefined;
  766. var widgetType = $ax.getTypeFromElementId(firstId);
  767. if ($ax.public.fn.IsImageBox(widgetType) || $ax.public.fn.IsVector(widgetType)) return !$ax.style.IsWidgetDisabled(firstId);
  768. else return this.jQuery().first().not(':disabled').length > 0;
  769. } else {
  770. var elementIds = this.getElementIds();
  771. for(var index = 0; index < elementIds.length; index++) {
  772. var elementId = elementIds[index];
  773. var widgetType = $ax.getTypeFromElementId(elementId);
  774. var enabled = arguments[0];
  775. if ($ax.public.fn.IsImageBox(widgetType) || $ax.public.fn.IsVector(widgetType)) $ax.style.SetWidgetEnabled(elementId, enabled);
  776. if ($ax.public.fn.IsDynamicPanel(widgetType) || $ax.public.fn.IsLayer(widgetType)) {
  777. $ax.style.SetWidgetEnabled(elementId, enabled);
  778. var children = this.getChildren()[index].children;
  779. for(var i = 0; i < children.length; i++) {
  780. $axure('#' + children[i]).enabled(enabled);
  781. }
  782. }
  783. var obj = $obj(elementId);
  784. var images = obj.images;
  785. if(PLAIN_TEXT_TYPES.indexOf(widgetType) != -1 && images) {
  786. var img = $jobj($ax.repeater.applySuffixToElementId(elementId, '_image_sketch'));
  787. var key = (enabled ? 'normal~' : 'disabled~') + ($ax.adaptive.currentViewId || '');
  788. img.attr('src', images[key]);
  789. }
  790. var jobj = $jobj(elementId);
  791. var input = $jobj($ax.INPUT(elementId));
  792. if(input.length) jobj = input;
  793. if (OS_MAC && WEBKIT && $ax.public.fn.IsComboBox(widgetType)) jobj.css('color', enabled ? '' : 'grayText');
  794. if(enabled) jobj.removeAttr('disabled');
  795. else jobj.attr('disabled', 'disabled');
  796. }
  797. return this;
  798. }
  799. };
  800. $ax.public.fn.visible = function() {
  801. var ids = this.getElementIds();
  802. for(var index = 0; index < ids.length; index++) $ax.visibility.SetIdVisible(ids[index], arguments[0]);
  803. return this;
  804. };
  805. $ax.public.fn.selected = function() {
  806. if(arguments[0] == undefined) {
  807. var firstId = this.getElementIds()[0];
  808. if(!firstId) return undefined;
  809. var widgetType = $ax.getTypeFromElementId(firstId);
  810. if ($ax.public.fn.IsTreeNodeObject(widgetType)) {
  811. var treeNodeButtonShapeId = '';
  812. var allElementIds = $ax.getAllElementIds();
  813. for(var i = 0; i < allElementIds.length; i++) {
  814. var elementId = allElementIds[i];
  815. var currObj = $ax.getObjectFromElementId(elementId);
  816. if ($ax.public.fn.IsVector(currObj.type) && currObj.parent && currObj.parent.scriptIds && currObj.parent.scriptIds[0] == firstId) {
  817. treeNodeButtonShapeId = elementId;
  818. break;
  819. }
  820. }
  821. if(treeNodeButtonShapeId == '') return undefined;
  822. return $ax.style.IsWidgetSelected(treeNodeButtonShapeId);
  823. } else if ($ax.public.fn.IsImageBox(widgetType) || $ax.public.fn.IsVector(widgetType) || $ax.public.fn.IsTableCell(widgetType) || $ax.public.fn.IsDynamicPanel(widgetType) || $ax.public.fn.IsLayer(widgetType)) {
  824. return $ax.style.IsWidgetSelected(firstId);
  825. } else if ($ax.public.fn.IsCheckBox(widgetType) || $ax.public.fn.IsRadioButton(widgetType)) {
  826. return $jobj($ax.INPUT(firstId)).prop('checked');
  827. }
  828. return this;
  829. }
  830. var elementIds = this.getElementIds();
  831. var func = typeof (arguments[0]) === 'function' ? arguments[0] : null;
  832. var enabled = arguments[0]; // If this is a function it will be overridden with the return value;
  833. for(var index = 0; index < elementIds.length; index++) {
  834. var elementId = elementIds[index];
  835. if(func) {
  836. enabled = func($axure('#' + elementId));
  837. }
  838. var widgetType = $ax.getTypeFromElementId(elementId);
  839. if ($ax.public.fn.IsTreeNodeObject(widgetType)) { //for tree node
  840. var treeRootId = $('#' + elementIds[index]).parents('.treeroot').attr('id');
  841. var treeNodeButtonShapeId = '';
  842. var childElementIds = $jobj(elementId).children();
  843. for(var i = 0; i < childElementIds.length; i++) {
  844. var elementId = childElementIds[i].id;
  845. var currObj = $ax.getObjectFromElementId(elementId);
  846. if (currObj && currObj.type == $ax.constants.VECTOR_SHAPE_TYPE && currObj.parent &&
  847. currObj.parent.scriptIds && currObj.parent.scriptIds[0] == elementIds[index]) {
  848. treeNodeButtonShapeId = elementId;
  849. break;
  850. }
  851. }
  852. if(treeNodeButtonShapeId == '') continue;
  853. $ax.tree.SelectTreeNode(elementId, enabled);
  854. } else if ($ax.public.fn.IsImageBox(widgetType) || $ax.public.fn.IsVector(widgetType) || $ax.public.fn.IsVector(widgetType) || $ax.public.fn.IsTableCell(widgetType) || $ax.public.fn.IsDynamicPanel(widgetType) || $ax.public.fn.IsLayer(widgetType)) {
  855. $ax.style.SetWidgetSelected(elementIds[index], enabled);
  856. } else if ($ax.public.fn.IsCheckBox(widgetType) || $ax.public.fn.IsRadioButton(widgetType)) {
  857. var query = $jobj($ax.INPUT(elementId));
  858. var curr = query.prop('checked');
  859. //NOTE: won't fire onselect nore onunselect event if states didn't changes
  860. if(curr != enabled) {
  861. query.prop('checked', enabled);
  862. $ax.event.TryFireCheckChanged(elementId, enabled);
  863. }
  864. }
  865. }
  866. return this;
  867. };
  868. $ax.public.fn.focus = function() {
  869. var firstId = this.getElementIds()[0];
  870. var focusableId = $ax.event.getFocusableWidgetOrChildId(firstId);
  871. $('#' + focusableId).focus();
  872. return this;
  873. };
  874. $ax.public.fn.expanded = function() {
  875. if(arguments[0] == undefined) {
  876. var firstId = this.getElementIds()[0];
  877. return firstId && !$ax.public.fn.IsTreeNodeObject($ax.getTypeFromElementId(firstId)) && $ax.visibility.IsIdVisible(firstId + '_children');
  878. } else {
  879. var elementIds = this.getElementIds();
  880. for(var index = 0; index < elementIds.length; index++) {
  881. if ($ax.public.fn.IsTreeNodeObject($ax.getTypeFromElementId(elementIds[index]))) {
  882. var treeNodeId = elementIds[index];
  883. var childContainerId = treeNodeId + '_children';
  884. var scriptId = $ax.repeater.getScriptIdFromElementId(treeNodeId);
  885. var itemId = $ax.repeater.getItemIdFromElementId(treeNodeId);
  886. var plusMinusId = 'u' + (parseInt(scriptId.substring(1)) + 1);
  887. if(itemId) plusMinusId = $ax.repeater.createElementId(plusMinusId, itemId);
  888. if($('#' + childContainerId).length == 0 || !$jobj(plusMinusId).children().first().is('img'))
  889. plusMinusId = '';
  890. if(arguments[0] == true) {
  891. $ax.tree.ExpandNode(treeNodeId, childContainerId, plusMinusId);
  892. } else if(arguments[0] == false) {
  893. $ax.tree.CollapseNode(treeNodeId, childContainerId, plusMinusId);
  894. }
  895. }
  896. }
  897. return this;
  898. }
  899. };
  900. $ax.public.fn.size = function () {
  901. var firstId = this.getElementIds()[0];
  902. if(!firstId) return undefined;
  903. var object = $ax.getObjectFromElementIdDisregardHex(firstId);
  904. if(object && (object.type == 'layer' || object.generateCompound)) {
  905. var boundingRect = $ax.public.fn.getWidgetBoundingRect(firstId);
  906. return { width: boundingRect.width, height: boundingRect.height };
  907. }
  908. var firstIdObject = $jobj(firstId);
  909. return { width: firstIdObject.outerWidth(), height: firstIdObject.outerHeight() };
  910. };
  911. $ax.public.fn.width = function() {
  912. var firstId = this.getElementIds()[0];
  913. if(!firstId) return undefined;
  914. var object = $ax.getObjectFromElementIdDisregardHex(firstId);
  915. if (object && (object.type == 'layer' || object.generateCompound)) {
  916. var boundingRect = $ax.public.fn.getWidgetBoundingRect(firstId);
  917. return boundingRect.width;
  918. }
  919. var firstIdObject = $jobj(firstId);
  920. return firstIdObject.outerWidth();
  921. };
  922. $ax.public.fn.height = function() {
  923. var firstId = this.getElementIds()[0];
  924. if(!firstId) return undefined;
  925. var object = $ax.getObjectFromElementIdDisregardHex(firstId);
  926. if (object && (object.type == 'layer' || object.generateCompound)) {
  927. var boundingRect = $ax.public.fn.getWidgetBoundingRect(firstId);
  928. return boundingRect.height;
  929. }
  930. var firstIdObject = $jobj(firstId);
  931. return firstIdObject.outerHeight();
  932. };
  933. $ax.public.fn.readAttribute = function(object, attribute) {
  934. if(object && object.hasAttribute(attribute)) {
  935. return object.getAttribute(attribute);
  936. }
  937. return null;
  938. };
  939. $ax.public.fn.locRelativeIgnoreLayer = function (vert) {
  940. var elementId = this.getElementIds()[0];
  941. if(!elementId) return undefined;
  942. var parents = this.getParents(true, '*')[0];
  943. for(var i = 0; i < parents.length; i++) {
  944. var type = $ax.getTypeFromElementId(parents[i]);
  945. if(!$axure.fn.IsLayer(type) && !$axure.fn.IsReferenceDiagramObject(type)) {
  946. var func = vert ? _getRelativeTop : _getRelativeLeft;
  947. return func(elementId, $jobj(parents[i])[0]);
  948. }
  949. }
  950. var axThis = $ax('#' + elementId);
  951. return vert ? axThis.top() : _bodyToWorld(axThis.left(), true);
  952. };
  953. var _bodyToWorld = $axure.fn.bodyToWorld = function(x, from) {
  954. var body = $('body');
  955. if (body.css('position') != 'relative') return x;
  956. var offset = (Number(body.css('left').replace('px', '')) + Math.max(0, ($(window).width() - body.width()) / 2));
  957. if(from) offset *= -1;
  958. return x + offset;
  959. }
  960. $ax.public.fn.left = function (relative) {
  961. var firstId = this.getElementIds()[0];
  962. if(!firstId) return undefined;
  963. var left = _getLoc(firstId, false, false, relative);
  964. // If you are absolute, unless your are a pinned panel...
  965. if(relative || $obj(firstId).fixedVertical) return left;
  966. // ... or you are in one...
  967. var parentPanels = $ax('#' + firstId).getParents(true, 'dynamicPanel')[0];
  968. for(var i = 0; i < parentPanels.length; i++) if ($obj(parentPanels[i]).fixedVertical) return left;
  969. // ... you must convert from body to world coordinates
  970. return _bodyToWorld(left);
  971. };
  972. $ax.public.fn.top = function(relative) {
  973. var firstId = this.getElementIds()[0];
  974. return firstId && _getLoc(firstId, true, false, relative);
  975. };
  976. var _getLoc = function(id, vert, high, relative) {
  977. var mathFunc = high ? 'max' : 'min';
  978. var prop = vert ? 'top' : 'left';
  979. var dim = vert ? 'height' : 'width';
  980. var obj = $jobj(id);
  981. var oldDisplay = obj.css('display');
  982. var displaySet = false;
  983. if(oldDisplay == 'none') {
  984. obj.css('display', '');
  985. displaySet = true;
  986. }
  987. var loc = Math.NaN;
  988. var rdo = $ax.getTypeFromElementId(id) == $ax.constants.REFERENCE_DIAGRAM_OBJECT_TYPE;
  989. if (!rdo) loc = $ax.getNumFromPx(obj.css(prop));
  990. var fixed = _fixedOffset(id, vert);
  991. if(fixed.valid) loc = fixed.offset;
  992. else if (!relative) {
  993. var parents = $ax('#' + id).getParents(true, ['item', 'repeater', 'dynamicPanel', 'layer'])[0];
  994. for(var i = 0; i < parents.length; i++) {
  995. var parentId = $ax.visibility.getWidgetFromContainer(parents[i]);
  996. var parent = $ax.visibility.applyWidgetContainer(parentId, true);
  997. // Layer may not have container, and will be at 0,0 otherwise.
  998. if (!parent.length) continue;
  999. fixed = _fixedOffset(parentId, vert);
  1000. if(fixed.valid) {
  1001. loc += fixed.offset;
  1002. break; // If fixed ignore any parents if there are any, they don't matter.
  1003. } else loc += $ax.getNumFromPx(parent.css(prop));
  1004. }
  1005. }
  1006. //if (high) loc += isCompound ? dimension[dim] : obj[dim]();
  1007. if (high) loc += obj[dim]();
  1008. // Special Layer code
  1009. if ($ax.getTypeFromElementId(id) == 'layer') {
  1010. // If layer has a container, then use that. Otherwise must deal with children
  1011. var container = $ax.visibility.applyWidgetContainer(id, true, true);
  1012. if(container.length) loc = $ax.getNumFromPx(container.css(prop));
  1013. else {
  1014. var first = true;
  1015. var children = $obj(id).objs;
  1016. for(var i = 0; i < children.length; i++) {
  1017. var childId = $ax.getElementIdFromPath([children[i].id], { relativeTo: id });
  1018. if(!childId) continue;
  1019. var childProp = _getLoc(childId, vert, high, relative);
  1020. if(first) loc = childProp;
  1021. else loc = Math[mathFunc](loc, childProp);
  1022. first = false;
  1023. }
  1024. }
  1025. }
  1026. if(displaySet) obj.css('display', oldDisplay);
  1027. // var body = $('body');
  1028. // if (body.css('position') == 'relative') loc -= (Number(body.css(loc).replace('px', '')) + Math.max(0, ($(window).width() - body.width()) / 2));
  1029. return loc;
  1030. };
  1031. var _fixedOffset = function (id, vert) {
  1032. var axObj = $obj(id);
  1033. var dim = vert ? 'height' : 'width';
  1034. var vertKey = (vert ? 'Vertical' : 'Horizontal');
  1035. var key = 'fixed' + vertKey;
  1036. var alignment = axObj[key];
  1037. if(!alignment) return { valid: false };
  1038. var loc = 0;
  1039. // TODO: This returns 0 for width/height it or any parent is display none. Similar issue when using axquery width/height
  1040. // TODO: Look into replacing this with axquery width/height and fixing that to use this hack. Potentially want to make js generic trapper.
  1041. var trap = _displayWidget(id);
  1042. var query = $jobj(id);
  1043. var objSize = query[dim]();
  1044. trap();
  1045. if(alignment == 'center' || alignment == 'middle') {
  1046. loc = $ax.getNumFromPx(query.css('margin-' + (vert ? 'top' : 'left')));
  1047. loc += ($(window)[dim]()) / 2;
  1048. } else if(alignment == 'bottom' || alignment == 'right') {
  1049. loc = $ax.getNumFromPx(query.css(vert ? 'bottom' : 'right'));
  1050. loc = $(window)[dim]() - objSize - loc; // subract loc because margin here moves farther left/up as it gets bigger.
  1051. } else {
  1052. loc = $ax.getNumFromPx(query.css(vert ? 'top' : 'left'));
  1053. }
  1054. var scrollKey = 'scroll' + (vert ? 'Y' : 'X');
  1055. return { offset: window[scrollKey] + loc, valid: true };
  1056. };
  1057. var _displayWidget = function(id) {
  1058. var parents = $ax('#' + id).getParents(true, '*')[0];
  1059. parents.push(id); // also need to show self
  1060. var displayed = [];
  1061. for(var i = 0; i < parents.length; i++) {
  1062. var currId = parents[i];
  1063. var currObj = $jobj(currId);
  1064. if(currObj.css('display') == 'none') {
  1065. currObj.css('display', 'block');
  1066. displayed.push(currId);
  1067. }
  1068. }
  1069. return function() {
  1070. for(var i = 0; i < displayed.length; i++) {
  1071. $jobj(displayed[i]).css('display', 'none');
  1072. }
  1073. };
  1074. }
  1075. });