doc.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. $axure.internal(function($ax) {
  2. var _pageData;
  3. var _initializePageFragment = function(pageFragment, objIdToObject) {
  4. var objectArrayHelper = function(objects, parent) {
  5. for(var i = 0; i < objects.length; i++) {
  6. diagramObjectHelper(objects[i], parent);
  7. }
  8. };
  9. var diagramObjectHelper = function(diagramObject, parent) {
  10. $ax.initializeObject('diagramObject', diagramObject);
  11. objIdToObject[pageFragment.packageId + '~' + diagramObject.id] = diagramObject;
  12. diagramObject.parent = parent;
  13. diagramObject.owner = pageFragment;
  14. diagramObject.scriptIds = [];
  15. if(diagramObject.diagrams) { //dynamic panel
  16. for(var i = 0; i < diagramObject.diagrams.length; i++) {
  17. var diagram = diagramObject.diagrams[i];
  18. objectArrayHelper(diagram.objects, diagram);
  19. }
  20. }
  21. if(diagramObject.objects) objectArrayHelper(diagramObject.objects, diagramObject);
  22. };
  23. objectArrayHelper(pageFragment.diagram.objects, pageFragment.diagram);
  24. };
  25. var _initalizeStylesheet = function(stylesheet) {
  26. var stylesById = {};
  27. var customStyles = stylesheet.customStyles;
  28. for(var key in customStyles) {
  29. var style = customStyles[key];
  30. stylesById[style.id] = style;
  31. }
  32. var duplicateStyles = stylesheet.duplicateStyles;
  33. for(var duplicateKey in duplicateStyles) {
  34. stylesById[duplicateKey] = stylesById[duplicateStyles[duplicateKey]];
  35. }
  36. stylesheet.stylesById = stylesById;
  37. };
  38. var _initializeDocumentData = function() {
  39. _initalizeStylesheet($ax.document.stylesheet);
  40. };
  41. var _initializePageData;
  42. // ******* Dictionaries ******** //
  43. (function () {
  44. var scriptIdToParentLayer = {};
  45. var elementIdToObject = {};
  46. var scriptIdToObject = {};
  47. var scriptIdToRepeaterId = {};
  48. var repeaterIdToScriptIds = {};
  49. var repeaterIdToItemIds = {};
  50. var scriptIdToPath = {};
  51. var _scriptIds = [];
  52. var elementIdToText = {};
  53. var radioGroupToSelectedElementId = {};
  54. _initializePageData = function() {
  55. if(!_pageData || !_pageData.page || !_pageData.page.diagram) return;
  56. var objIdToObject = {};
  57. _initializePageFragment(_pageData.page, objIdToObject);
  58. for(var masterId in _pageData.masters) {
  59. var master = _pageData.masters[masterId];
  60. _initializePageFragment(master, objIdToObject);
  61. }
  62. var _pathsToScriptIds = [];
  63. _pathToScriptIdHelper(_pageData.objectPaths, [], _pathsToScriptIds, scriptIdToPath);
  64. for(var i = 0; i < _pathsToScriptIds.length; i++) {
  65. var path = _pathsToScriptIds[i].idPath;
  66. var scriptId = _pathsToScriptIds[i].scriptId;
  67. var packageId = _pageData.page.packageId;
  68. if(path.length > 1) {
  69. for(var j = 0; j < path.length - 1; j++) {
  70. var rdoId = path[j];
  71. var rdo = objIdToObject[packageId + '~' + rdoId];
  72. packageId = rdo.masterId;
  73. }
  74. }
  75. var diagramObject = objIdToObject[packageId + '~' + path[path.length - 1]];
  76. diagramObject.scriptIds[diagramObject.scriptIds.length] = scriptId;
  77. scriptIdToObject[scriptId] = diagramObject;
  78. _scriptIds[_scriptIds.length] = scriptId;
  79. }
  80. // Now map scriptIds to repeaters and layers
  81. var mapScriptIdToRepeaterId = function(scriptId, repeaterId) {
  82. scriptIdToRepeaterId[scriptId] = repeaterId;
  83. var scriptIds = repeaterIdToScriptIds[repeaterId];
  84. if(scriptIds) scriptIds[scriptIds.length] = scriptId;
  85. else repeaterIdToScriptIds[repeaterId] = [scriptId];
  86. };
  87. var mapScriptIdToLayerId = function (obj, layerId, path) {
  88. var pathCopy = $ax.deepCopy(path);
  89. pathCopy[path.length] = obj.id;
  90. var scriptId = $ax.getScriptIdFromPath(pathCopy);
  91. if ($ax.public.fn.IsLayer(obj.type)) {
  92. for(var i = 0; i < obj.objs.length; i++) mapScriptIdToLayerId(obj.objs[i], scriptId, path);
  93. }
  94. scriptIdToParentLayer[scriptId] = layerId;
  95. }
  96. var mapIdsToRepeaterAndLayer = function(path, objs, repeaterId) {
  97. var pathCopy = $ax.deepCopy(path);
  98. for(var i = 0; i < objs.length; i++) {
  99. var obj = objs[i];
  100. pathCopy[path.length] = obj.id;
  101. var scriptId = $ax.getScriptIdFromPath(pathCopy);
  102. // Rdo have no element on page and are not mapped to the repeater
  103. if(repeaterId) mapScriptIdToRepeaterId(scriptId, repeaterId);
  104. if ($ax.public.fn.IsDynamicPanel(obj.type)) {
  105. for(var j = 0; j < obj.diagrams.length; j++) mapIdsToRepeaterAndLayer(path, obj.diagrams[j].objects, repeaterId);
  106. } else if ($ax.public.fn.IsReferenceDiagramObject(obj.type)) {
  107. mapIdsToRepeaterAndLayer(pathCopy, $ax.pageData.masters[obj.masterId].diagram.objects, repeaterId);
  108. } else if ($ax.public.fn.IsRepeater(obj.type)) {
  109. mapScriptIdToRepeaterId(scriptId, scriptId);
  110. mapIdsToRepeaterAndLayer(path, obj.objects, scriptId);
  111. } else if ($ax.public.fn.IsLayer(obj.type)) {
  112. var layerObjs = obj.objs;
  113. for(var j = 0; j < layerObjs.length; j++) {
  114. mapScriptIdToLayerId(layerObjs[j], scriptId, path);
  115. }
  116. } else if(obj.objects && obj.objects.length) {
  117. if(repeaterId) {
  118. for(var j = 0; j < obj.objects.length; j++) {
  119. mapIdsToRepeaterAndLayer(path, obj.objects, repeaterId);
  120. }
  121. }
  122. }
  123. }
  124. };
  125. mapIdsToRepeaterAndLayer([], $ax.pageData.page.diagram.objects);
  126. };
  127. $ax.getPathFromScriptId = function(scriptId) {
  128. var reversedPath = [];
  129. var path = scriptIdToPath[scriptId];
  130. while(path && path.uniqueId) {
  131. reversedPath[reversedPath.length] = path.uniqueId;
  132. path = path.parent;
  133. }
  134. return reversedPath.reverse();
  135. };
  136. var _getScriptIdFromFullPath = function(path) {
  137. var current = $ax.pageData.objectPaths;
  138. for(var i = 0; i < path.length; i++) {
  139. current = current[path[i]];
  140. if(!current) return current;
  141. }
  142. return current && current.scriptId;
  143. };
  144. var _getScriptIdFromPath = function(path, relativeTo) {
  145. var relativePath = [];
  146. var includeMasterInPath = false;
  147. if(relativeTo) {
  148. var relativeToScriptId;
  149. if(relativeTo.srcElement) { //this is eventInfo
  150. relativeToScriptId = $ax.repeater.getScriptIdFromElementId(relativeTo.srcElement);
  151. includeMasterInPath = relativeTo.isMasterEvent;
  152. } else if(typeof relativeTo === 'string') { //this is an element id
  153. relativeToScriptId = relativeTo;
  154. }
  155. if(relativeToScriptId) {
  156. relativePath = $ax.getPathFromScriptId(relativeToScriptId);
  157. if(!includeMasterInPath) relativePath = relativePath.slice(0, relativePath.length - 1);
  158. } else if(relativeTo instanceof Array) { //this is a path
  159. relativePath = relativeTo;
  160. }
  161. }
  162. var fullPath = relativePath.concat(path);
  163. var scriptId = _getScriptIdFromFullPath(fullPath);
  164. return !$ax.visibility.isScriptIdLimbo(scriptId) && scriptId;
  165. };
  166. $ax.getScriptIdFromPath = _getScriptIdFromPath;
  167. var _getElementIdsFromPath = function(path, eventInfo) {
  168. var scriptId = _getScriptIdFromPath(path, eventInfo);
  169. if (!scriptId) return [];
  170. // Don't need placed check hear. If unplaced, scriptId will be undefined and exit out before here.
  171. return $ax.getElementIdsFromEventAndScriptId(eventInfo, scriptId);
  172. };
  173. $ax.getElementIdsFromPath = _getElementIdsFromPath;
  174. var _getElementIdFromPath = function (path, params) {
  175. var scriptId = _getScriptIdFromPath(path, params.relativeTo);
  176. if (!scriptId) return scriptId;
  177. var itemNum = params.itemNum;
  178. if(params.relativeTo && typeof params.relativeTo === 'string') {
  179. if($jobj(params.relativeTo)) itemNum = $ax.repeater.getItemIdFromElementId(params.relativeTo);
  180. }
  181. return $ax.repeater.createElementId(scriptId, itemNum);
  182. };
  183. $ax.getElementIdFromPath = _getElementIdFromPath;
  184. var _getElementsIdFromEventAndScriptId = function(eventInfo, scriptId) {
  185. var itemId = eventInfo && $ax.repeater.getItemIdFromElementId(eventInfo.srcElement);
  186. var target = false;
  187. // Try to get itemId from target if you can't get it from source.
  188. if(!itemId) {
  189. itemId = eventInfo && eventInfo.targetElement && $ax.repeater.getItemIdFromElementId(eventInfo.targetElement);
  190. if(itemId) target = true;
  191. }
  192. var parentRepeater = $ax.getParentRepeaterFromScriptId(scriptId);
  193. if(parentRepeater && scriptId != parentRepeater) {
  194. if(itemId && (!eventInfo || parentRepeater == $ax.getParentRepeaterFromScriptId($ax.repeater.getScriptIdFromElementId(target ? eventInfo.targetElement : eventInfo.srcElement)))) {
  195. return [$ax.repeater.createElementId(scriptId, itemId)];
  196. }
  197. var elementIds = [];
  198. var itemIds = $ax.getItemIdsForRepeater(parentRepeater);
  199. if(!itemIds) return [];
  200. for(var i = 0; i < itemIds.length; i++) elementIds[i] = $ax.repeater.createElementId(scriptId, itemIds[i]);
  201. return elementIds;
  202. }
  203. return [scriptId];
  204. };
  205. $ax.getElementIdsFromEventAndScriptId = _getElementsIdFromEventAndScriptId;
  206. var _getSrcElementIdFromEvent = function(event) {
  207. var currentQuery = $(event.srcElement || event.target);
  208. while(currentQuery && currentQuery.length && (!$obj(currentQuery.attr('id')) || $jobj(currentQuery.attr('id')).hasClass('text'))) {
  209. currentQuery = currentQuery.parent();
  210. };
  211. return currentQuery.attr('id');
  212. };
  213. $ax.getSrcElementIdFromEvent = _getSrcElementIdFromEvent;
  214. var _getEventInfoFromEvent = function(event, skipShowDescriptions, elementId) {
  215. var eventInfo = {};
  216. eventInfo.srcElement = elementId;
  217. eventInfo.now = new Date();
  218. if(event != null) {
  219. //elementId can be empty string, so can't simple use "or" assignment here.
  220. eventInfo.srcElement = elementId || elementId == '' ? elementId : _getSrcElementIdFromEvent(event);
  221. eventInfo.which = event.which;
  222. // When getting locations in mobile, need to extract the touch object to get the mouse location attributes
  223. var mouseEvent = (event.originalEvent && event.originalEvent.changedTouches && event.originalEvent.changedTouches[0]) || event.originalEvent;
  224. if(mouseEvent && !mouseEvent.type) mouseEvent.type = event.type;
  225. if(skipShowDescriptions) eventInfo.skipShowDescriptions = true;
  226. // Always update mouse location if possible
  227. $ax.event.updateMouseLocation(mouseEvent);
  228. }
  229. // Always set event info about cursor
  230. var _cursor = eventInfo.cursor = {};
  231. _cursor.x = $ax.mouseLocation.x;
  232. _cursor.y = $ax.mouseLocation.y;
  233. eventInfo.pageX = _cursor.x + 'px';
  234. eventInfo.pageY = _cursor.y + 'px';
  235. // Do Keyboard Info
  236. eventInfo.keyInfo = $ax.event.keyState();
  237. eventInfo.window = _getWindowInfo();
  238. eventInfo.thiswidget = _getWidgetInfo(eventInfo.srcElement);
  239. eventInfo.item = _getItemInfo(eventInfo.srcElement);
  240. eventInfo.dragInfo = $ax.drag.GetWidgetDragInfo();
  241. return eventInfo;
  242. };
  243. $ax.getEventInfoFromEvent = _getEventInfoFromEvent;
  244. var _getWindowInfo = function() {
  245. var win = {};
  246. win.width = $(window).width();
  247. win.height = $(window).height();
  248. win.scrollx = $(window).scrollLeft();
  249. win.scrolly = $(window).scrollTop();
  250. return win;
  251. };
  252. $ax.getWindowInfo = _getWindowInfo;
  253. var _getItemInfo = function(elementId) {
  254. if(!elementId) return { valid: false };
  255. elementId = _getParentElement(elementId);
  256. var index = $ax.repeater.getItemIdFromElementId(elementId);
  257. if(!index) return { valid: false };
  258. var item = { valid: true };
  259. var scriptId = $ax.repeater.getScriptIdFromElementId(elementId);
  260. var repeaterId = $ax.getParentRepeaterFromScriptId(scriptId);
  261. item.repeater = _getWidgetInfo(repeaterId);
  262. $ax.repeater.setDisplayProps(item, repeaterId, index);
  263. item.ismarked = $ax.repeater.isEditItem(repeaterId, index);
  264. item.isvisible = Boolean($jobj(elementId).length);
  265. return item;
  266. };
  267. $ax.getItemInfo = _getItemInfo;
  268. var _getWidgetInfo = function(elementId) {
  269. if(!elementId) return { valid: false };
  270. elementId = _getParentElement(elementId);
  271. var elementAxQuery = $ax('#' + elementId);
  272. var elementQuery = $jobj(elementId);
  273. var obj = $obj(elementId);
  274. var widget = { valid: true, isWidget: true };
  275. widget.elementId = elementId;
  276. widget.name = widget.label = (elementQuery.data('label') ? elementQuery.data('label') : '');
  277. widget.text = $ax('#' + elementId).text();
  278. widget.opacity = Number(elementQuery.css('opacity')) * 100;
  279. widget.rotation = $ax.move.getRotationDegree(widget.elementId);
  280. var scriptId = $ax.repeater.getScriptIdFromElementId(elementId);
  281. var repeaterId = $ax.getParentRepeaterFromScriptId(scriptId);
  282. if (repeaterId) widget.repeater = $ax.public.fn.IsRepeater(obj.type) ? widget : _getWidgetInfo(repeaterId);
  283. if($ax.public.fn.IsLayer(obj.type)) {
  284. var boundingRect = $ax.public.fn.getWidgetBoundingRect(elementId);
  285. widget.x = boundingRect.left;
  286. widget.y = boundingRect.top;
  287. widget.width = boundingRect.width;
  288. widget.height = boundingRect.height;
  289. if(elementQuery.length != 0) {
  290. widget.pagex = elementAxQuery.left();
  291. widget.pagey = elementAxQuery.top();
  292. }
  293. } else {
  294. var elementExists = elementQuery.length > 0;
  295. var x = elementExists ? elementAxQuery.locRelativeIgnoreLayer(false) : 0;
  296. var y = elementExists ? elementAxQuery.locRelativeIgnoreLayer(true) : 0;
  297. widget.x = x;
  298. widget.y = y;
  299. if(elementExists) {
  300. widget.pagex = elementAxQuery.left();
  301. widget.pagey = elementAxQuery.top();
  302. widget.width = elementAxQuery.width();
  303. widget.height = elementAxQuery.height();
  304. }
  305. //if (obj.generateCompound) {
  306. // // assume this means that this is a compound vector.
  307. // widget.x = boundingRect.left;
  308. // widget.y = boundingRect.top;
  309. // //widget.pagex += boundingRect.left;
  310. // //widget.pagey += boundingRect.top;
  311. //}
  312. }
  313. // Right now only dynamic panel can scroll
  314. if ($ax.public.fn.IsDynamicPanel(obj.type)) {
  315. var stateQuery = $('#' + $ax.visibility.GetPanelState(elementId));
  316. widget.scrollx = stateQuery.scrollLeft();
  317. widget.scrolly = stateQuery.scrollTop();
  318. if($ax.dynamicPanelManager.isIdFitToContent(elementId)) {
  319. widget.width = stateQuery.width();
  320. widget.height = stateQuery.height();
  321. }
  322. } else {
  323. widget.scrollx = 0;
  324. widget.scrolly = 0;
  325. }
  326. // repeater only props
  327. if ($ax.public.fn.IsRepeater(obj.type)) {
  328. widget.visibleitemcount = repeaterIdToItemIds[scriptId] ? repeaterIdToItemIds[scriptId].length : $ax.repeater.getVisibleDataCount(scriptId);
  329. widget.itemcount = $ax.repeater.getFilteredDataCount(scriptId);
  330. widget.datacount = $ax.repeater.getDataCount(scriptId);
  331. widget.pagecount = $ax.repeater.getPageCount(scriptId);
  332. widget.pageindex = $ax.repeater.getPageIndex(scriptId);
  333. }
  334. widget.left = widget.leftfixed = widget.x;
  335. widget.top = widget.topfixed = widget.y;
  336. widget.right = widget.rightfixed = widget.x + widget.width;
  337. widget.bottom = widget.bottomfixed = widget.y + widget.height;
  338. if(elementQuery.css('position') == 'fixed') {
  339. var windowScrollLeft = $(window).scrollLeft();
  340. var windowScrollTop = $(window).scrollTop();
  341. widget.leftfixed = widget.left - windowScrollLeft;
  342. widget.topfixed = widget.top - windowScrollTop;
  343. widget.rightfixed = widget.right - windowScrollLeft;
  344. widget.bottomfixed = widget.bottom - windowScrollTop;
  345. }
  346. return widget;
  347. };
  348. $ax.getWidgetInfo = _getWidgetInfo;
  349. var _getParentElement = $ax.getParentElement = function(elementId) {
  350. var obj = $obj(elementId);
  351. while(obj.isContained) {
  352. var path = $ax.getPathFromScriptId($ax.repeater.getScriptIdFromElementId(elementId));
  353. var itemId = $ax.repeater.getItemIdFromElementId(elementId);
  354. path[path.length - 1] = obj.parent.id;
  355. elementId = $ax.getElementIdFromPath(path, { itemNum: itemId });
  356. obj = $obj(elementId);
  357. }
  358. return elementId;
  359. };
  360. $ax.addItemIdToRepeater = function(itemId, repeaterId) {
  361. var itemIds = repeaterIdToItemIds[repeaterId];
  362. if(itemIds) itemIds[itemIds.length] = itemId;
  363. else repeaterIdToItemIds[repeaterId] = [itemId];
  364. var scriptIds = repeaterIdToScriptIds[repeaterId];
  365. for(var i = 0; i < scriptIds.length; i++) elementIdToObject[$ax.repeater.createElementId(scriptIds[i], itemId)] = $ax.getObjectFromScriptId(scriptIds[i]);
  366. };
  367. $ax.getAllElementIds = function() {
  368. var elementIds = [];
  369. for(var i = 0; i < _scriptIds.length; i++) {
  370. var scriptId = _scriptIds[i];
  371. var repeaterId = scriptIdToRepeaterId[scriptId];
  372. if(repeaterId && repeaterId != scriptId) {
  373. var itemIds = repeaterIdToItemIds[repeaterId] || [];
  374. for(var j = 0; j < itemIds.length; j++) elementIds[elementIds.length] = $ax.repeater.createElementId(scriptId, itemIds[j]);
  375. } else elementIds[elementIds.length] = scriptId;
  376. }
  377. return elementIds;
  378. };
  379. $ax.getAllScriptIds = function() {
  380. return _scriptIds;
  381. };
  382. $ax.getObjectFromElementId = function(elementId) {
  383. return $ax.getObjectFromScriptId($ax.repeater.getScriptIdFromElementId(elementId));
  384. };
  385. $ax.getObjectFromScriptId = function(scriptId) {
  386. return scriptIdToObject[scriptId];
  387. };
  388. $ax.getParentRepeaterFromElementId = function(elementId) {
  389. return $ax.getParentRepeaterFromScriptId($ax.repeater.getScriptIdFromElementId(elementId));
  390. };
  391. $ax.getParentRepeaterFromScriptId = function(scriptId) {
  392. return scriptIdToRepeaterId[scriptId];
  393. };
  394. var _getChildScriptIdsForRepeater = function(repeaterId) {
  395. return repeaterIdToScriptIds[repeaterId];
  396. };
  397. var _getItemIdsForRepeater = function(repeaterId) {
  398. return repeaterIdToItemIds[repeaterId] || [];
  399. };
  400. $ax.getItemIdsForRepeater = _getItemIdsForRepeater;
  401. var _clearItemIdsForRepeater = function(repeaterId) {
  402. repeaterIdToItemIds[repeaterId] = [];
  403. };
  404. $ax.clearItemsForRepeater = _clearItemIdsForRepeater;
  405. $ax.getChildElementIdsForRepeater = function(repeaterId) {
  406. var scriptIds = _getChildScriptIdsForRepeater(repeaterId);
  407. var itemIds = _getItemIdsForRepeater(repeaterId);
  408. var retVal = [];
  409. if(!itemIds || !scriptIds) return retVal;
  410. for(var i = 0; i < scriptIds.length; i++) {
  411. for(var j = 0; j < itemIds.length; j++) {
  412. retVal[retVal.length] = $ax.repeater.createElementId(scriptIds[i], itemIds[j]);
  413. }
  414. }
  415. return retVal;
  416. };
  417. $ax.getRdoParentFromElementId = function(elementId) {
  418. var scriptId = $ax.repeater.getScriptIdFromElementId(elementId);
  419. var rdoId = scriptIdToPath[scriptId].parent.scriptId;
  420. if($ax.getParentRepeaterFromScriptId(rdoId)) rdoId = $ax.repeater.createElementId(rdoId, $ax.repeater.getItemIdFromElementId(elementId));
  421. return rdoId;
  422. };
  423. $ax.getLayerParentFromElementId = function (elementId) {
  424. var itemId = $ax.repeater.getItemIdFromElementId(elementId);
  425. var scriptId = scriptIdToParentLayer[$ax.repeater.getScriptIdFromElementId(elementId)];
  426. return $ax.getParentRepeaterFromElementId(scriptId) ? $ax.repeater.createElementId(scriptId, itemId) : scriptId;
  427. }
  428. $ax.updateElementText = function(elementId, text) {
  429. elementIdToText[elementId] = text;
  430. };
  431. $ax.hasElementTextChanged = function(elementId, text) {
  432. return elementIdToText[elementId] != text;
  433. };
  434. $ax.updateRadioButtonSelected = function(group, elementId) {
  435. var old = radioGroupToSelectedElementId[group];
  436. radioGroupToSelectedElementId[group] = elementId;
  437. return old;
  438. };
  439. $ax.hasRadioButtonSelectedChanged = function(group, elementId) {
  440. return radioGroupToSelectedElementId[group] != elementId;
  441. };
  442. })();
  443. //Recursively populates fullPathArray with:
  444. // [ { idPath, scriptId }, ... ]
  445. //for every scriptId in the object
  446. //also populates an object of scriptId -> path
  447. var _pathToScriptIdHelper = function(currentPath, currentChain, fullPathArray, scriptIdToPath) {
  448. for(var key in currentPath) {
  449. if(key != "scriptId") {
  450. var nextPath = currentPath[key];
  451. _pathToScriptIdHelper(nextPath, currentChain.concat(key), fullPathArray, scriptIdToPath);
  452. nextPath.parent = currentPath;
  453. nextPath.uniqueId = key;
  454. } else {
  455. fullPathArray[fullPathArray.length] = { idPath: currentChain, scriptId: currentPath.scriptId };
  456. scriptIdToPath[currentPath.scriptId] = currentPath;
  457. }
  458. }
  459. };
  460. $ax.public.loadCurrentPage = $ax.loadCurrentPage = function(pageData) {
  461. $ax.pageData = _pageData = pageData;
  462. _initializePageData();
  463. };
  464. $ax.public.loadDocument = $ax.loadDocument = function(document) {
  465. $ax.document = document;
  466. _initializeDocumentData();
  467. };
  468. /**
  469. Navigates to a page
  470. */
  471. $ax.public.navigate = $ax.navigate = function(to) { //url, includeVariables, type) {
  472. var targetUrl;
  473. if(typeof (to) === 'object') {
  474. includeVariables = to.includeVariables;
  475. targetUrl = !includeVariables ? to.url : $ax.globalVariableProvider.getLinkUrl(to.url);
  476. if(to.target == "new") {
  477. window.open(targetUrl, to.name);
  478. } else if(to.target == "popup") {
  479. var features = _getPopupFeatures(to.popupOptions);
  480. window.open(targetUrl, to.name, features);
  481. } else {
  482. var targetLocation = window.location;
  483. if(to.target == "current") {
  484. } else if(to.target == "parent") {
  485. targetLocation = top.opener.window.location;
  486. } else if(to.target == "parentFrame") {
  487. targetLocation = parent.location;
  488. } else if(to.target == "frame") {
  489. // targetLocation = to.frame.contentWindow.location;
  490. $(to.frame).attr('src', targetUrl || 'about:blank');
  491. return;
  492. }
  493. if (!_needsReload(targetLocation, to.url)) {
  494. targetLocation.href = targetUrl || 'about:blank';
  495. } else {
  496. targetLocation.href = $axure.utils.getReloadPath() + "#" + encodeURI(targetUrl);
  497. }
  498. }
  499. } else {
  500. $ax.navigate({
  501. url: to,
  502. target: "current",
  503. includeVariables: arguments[1]
  504. });
  505. }
  506. };
  507. var _needsReload = function(oldLocation, newBaseUrl) {
  508. var reload = false;
  509. try {
  510. var oldUrl = oldLocation.href;
  511. var oldBaseUrl = oldUrl.split("#")[0];
  512. var lastslash = oldBaseUrl.lastIndexOf("/");
  513. if(lastslash > 0) {
  514. oldBaseUrl = oldBaseUrl.substring(lastslash + 1, oldBaseUrl.length);
  515. if(oldBaseUrl == encodeURI(newBaseUrl)) {
  516. reload = true;
  517. }
  518. }
  519. } catch(e) {
  520. }
  521. return reload;
  522. };
  523. var _getPopupFeatures = function(options) {
  524. var defaultOptions = {
  525. toolbar: true,
  526. scrollbars: true,
  527. location: true,
  528. status: true,
  529. menubar: true,
  530. directories: true,
  531. resizable: true,
  532. centerwindow: true,
  533. left: -1,
  534. top: -1,
  535. height: -1,
  536. width: -1
  537. };
  538. var selectedOptions = $.extend({}, defaultOptions, options);
  539. var optionsList = [];
  540. optionsList.push('toolbar=' + (selectedOptions.toolbar ? 'yes' : 'no'));
  541. optionsList.push('scrollbars=' + (selectedOptions.scrollbars ? 'yes' : 'no'));
  542. optionsList.push('location=' + (selectedOptions.location ? 'yes' : 'no'));
  543. optionsList.push('status=' + (selectedOptions.status ? 'yes' : 'no'));
  544. optionsList.push('menubar=' + (selectedOptions.menubar ? 'yes' : 'no'));
  545. optionsList.push('directories=' + (selectedOptions.directories ? 'yes' : 'no'));
  546. optionsList.push('resizable=' + (selectedOptions.resizable ? 'yes' : 'no'));
  547. if(selectedOptions.centerwindow == false) {
  548. if(selectedOptions.left > -1) {
  549. optionsList.push('left=' + selectedOptions.left);
  550. }
  551. if(selectedOptions.top > -1) {
  552. optionsList.push('top=' + selectedOptions.top);
  553. }
  554. }
  555. var height = 0;
  556. var width = 0;
  557. if(selectedOptions.height > 0) {
  558. optionsList.push('height=' + selectedOptions.height);
  559. height = selectedOptions.height;
  560. }
  561. if(selectedOptions.width > 0) {
  562. optionsList.push('width=' + selectedOptions.width);
  563. width = selectedOptions.width;
  564. }
  565. var features = optionsList.join(',');
  566. if(selectedOptions.centerwindow) {
  567. var winl = (window.screen.width - width) / 2;
  568. var wint = (window.screen.height - height) / 2;
  569. features = features + ',left=' + winl + ',top=' + wint;
  570. }
  571. return features;
  572. };
  573. /**
  574. Closes a window
  575. */
  576. $ax.public.closeWindow = $ax.closeWindow = function() {
  577. parent.window.close();
  578. };
  579. /**
  580. Goes back
  581. */
  582. $ax.public.back = $ax.back = function() {
  583. window.history.go(-1);
  584. };
  585. /**
  586. Reloads the current page.
  587. # includeVariables: true if it should re-include the variables when the page is reloaded
  588. */
  589. $ax.public.reload = $ax.reload = function(includeVariables) {
  590. var targetUrl = (includeVariables === false)
  591. ? $axure.utils.getReloadPath() + "#" + encodeURI($ax.pageData.url)
  592. : $axure.utils.getReloadPath() + "#" + encodeURI($ax.globalVariableProvider.getLinkUrl($ax.pageData.url));
  593. window.location.href = targetUrl;
  594. };
  595. /**
  596. Sets a variable.
  597. # name: The name of the global variable to set
  598. # value: The value that should be set
  599. */
  600. $ax.public.setGlobalVariable = $ax.setGlobalVariable = function(name, value) {
  601. if(!name || !value) {
  602. return;
  603. }
  604. $ax.globalVariableProvider.setVariableValue(name, value);
  605. };
  606. /**
  607. Gets the value of a global variable
  608. # name: The name of the global variable value to get
  609. */
  610. $ax.public.getGlobalVariable = $ax.getGlobalVariable = function(name) {
  611. $ax.globalVariableProvider.getVariableValue(name);
  612. };
  613. $ax.getObjectFromElementIdDisregardHex = function (elementId) {
  614. var elementIdInput = elementId.charAt(0) == '#' ? elementId.substring(1) : elementId;
  615. return this.getObjectFromElementId(elementIdInput);
  616. }
  617. $ax.getTypeFromElementId = function(elementId) {
  618. var obj = this.getObjectFromElementIdDisregardHex(elementId);
  619. return obj && obj.type;
  620. };
  621. $ax.getNumFromPx = function(pxNum) {
  622. return Number(pxNum.replace('px', ''));
  623. }
  624. });