doc.js.orig 27 KB

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