sitemap.js.orig 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643
  1. // use this to isolate the scope
  2. (function() {
  3. var SHOW_HIDE_ANIMATION_DURATION = 0;
  4. var HIGHLIGHT_INTERACTIVE_VAR_NAME = 'hi';
  5. var FOOTNOTES_VAR_NAME = 'fn';
  6. var SITEMAP_COLLAPSE_VAR_NAME = 'c';
  7. var ADAPTIVE_VIEW_VAR_NAME = 'view';
  8. var currentPageLoc = '';
  9. var currentPlayerLoc = '';
  10. var currentPageHashString = '';
  11. $(window.document).ready(function() {
  12. $axure.player.createPluginHost({
  13. id: 'sitemapHost',
  14. context: 'interface',
  15. title: 'Sitemap'
  16. });
  17. generateSitemap();
  18. $('.sitemapPlusMinusLink').toggle(collapse_click, expand_click);
  19. $('.sitemapPageLink').click(node_click);
  20. $('#sitemapLinksAndOptionsContainer').hide();
  21. $('#searchDiv').hide();
  22. $('#linksButton').click(links_click);
  23. $('#adaptiveButton').click(adaptive_click);
  24. $('#footnotesButton').click(footnotes_click).addClass('sitemapToolbarButtonSelected');
  25. $('#highlightInteractiveButton').click(highlight_interactive);
  26. $('#variablesButton').click(showvars_click);
  27. $('#variablesClearLink').click(clearvars_click);
  28. $('#searchButton').click(search_click);
  29. $('#searchBox').keyup(search_input_keyup);
  30. $('.sitemapLinkField').click(function() { this.select(); });
  31. $('input[value="withoutmap"]').click(withoutSitemapRadio_click);
  32. $('input[value="withmap"]').click(withSitemapRadio_click);
  33. $('#minimizeBox, #footnotesBox, #highlightBox').change(sitemapUrlOptions_change);
  34. $('#viewSelect').change(sitemapUrlViewSelect_change);
  35. // $('#sitemapHost').parent().resize(function () {
  36. // $('#sitemapHost').height($(this).height());
  37. // });
  38. // bind to the page load
  39. $axure.page.bind('load.sitemap', function() {
  40. currentPageLoc = $axure.page.location.split("#")[0];
  41. var decodedPageLoc = decodeURI(currentPageLoc);
  42. var nodeUrl = decodedPageLoc.substr(decodedPageLoc.lastIndexOf('/') ? decodedPageLoc.lastIndexOf('/') + 1 : 0);
  43. var nextPlayerLoc = $(location).attr('href').split("#")[0].split("?")[0];
  44. var nextPageHashString = '#p=' + nodeUrl.substr(0, nodeUrl.lastIndexOf('.'));
  45. if(nextPlayerLoc == currentPlayerLoc && nextPageHashString == currentPageHashString) return;
  46. currentPlayerLoc = nextPlayerLoc;
  47. currentPageHashString = nextPageHashString;
  48. setVarInCurrentUrlHash('p', nodeUrl.substring(0, nodeUrl.lastIndexOf('.html')));
  49. $('.sitemapPageLink').parent().parent().removeClass('sitemapHighlight');
  50. $('.sitemapPageLink[nodeUrl="' + nodeUrl + '"]').parent().parent().addClass('sitemapHighlight');
  51. $('#sitemapLinksPageName').html($('.sitemapHighlight > .sitemapPageLinkContainer > .sitemapPageLink > .sitemapPageName').html());
  52. //Click the "With sitemap" radio button so that it's selected by default
  53. $('input[value="withmap"]').click();
  54. //Update variable div with latest global variable values after page has loaded
  55. $axure.messageCenter.postMessage('getGlobalVariables', '');
  56. //If footnotes enabled for this prototype...
  57. if($axure.document.configuration.showAnnotations == true) {
  58. //If the fn var is defined and set to 0, hide footnotes
  59. //else if hide-footnotes button selected, hide them
  60. var fnVal = getHashStringVar(FOOTNOTES_VAR_NAME);
  61. if(fnVal.length > 0 && fnVal == 0) {
  62. $('#footnotesButton').removeClass('sitemapToolbarButtonSelected');
  63. $axure.messageCenter.postMessage('annotationToggle', false);
  64. } else if(!$('#footnotesButton').is('.sitemapToolbarButtonSelected')) {
  65. //If the footnotes button isn't selected, hide them on this loaded page
  66. $axure.messageCenter.postMessage('annotationToggle', false);
  67. }
  68. }
  69. //If highlight var is present and set to 1 or else if
  70. //sitemap highlight button is selected then highlight interactive elements
  71. var hiVal = getHashStringVar(HIGHLIGHT_INTERACTIVE_VAR_NAME);
  72. if(hiVal.length > 0 && hiVal == 1) {
  73. $('#highlightInteractiveButton').addClass('sitemapToolbarButtonSelected');
  74. $axure.messageCenter.postMessage('highlightInteractive', true);
  75. } else if($('#highlightInteractiveButton').is('.sitemapToolbarButtonSelected')) {
  76. $axure.messageCenter.postMessage('highlightInteractive', true);
  77. }
  78. //Set the current view if it is defined in the hash string
  79. //If the view is invalid, set it to 'auto' in the string
  80. //ELSE set the view based on the currently selected view in the toolbar menu
  81. var viewStr = getHashStringVar(ADAPTIVE_VIEW_VAR_NAME);
  82. if(viewStr.length > 0) {
  83. var $view = $('.adaptiveViewOption[val="' + viewStr + '"]');
  84. if($view.length > 0) {
  85. $view.click();
  86. } else {
  87. setVarInCurrentUrlHash(ADAPTIVE_VIEW_VAR_NAME, 'auto');
  88. }
  89. } else if($('.checkedAdaptive').length > 0) {
  90. var $viewOption = $('.checkedAdaptive').parents('.adaptiveViewOption');
  91. if($viewOption.attr('val') != 'auto') {
  92. $viewOption.click();
  93. }
  94. }
  95. var main = $('#mainFrame');
  96. if(document.activeElement != main[0]) main.focus();
  97. return false;
  98. });
  99. var $adaptiveViewsContainer = $('#adaptiveViewsContainer');
  100. var $viewSelect = $('#viewSelect');
  101. //Fill out adaptive view container with prototype's defined adaptive views, as well as the default, and Auto
  102. $adaptiveViewsContainer.append('<div class="adaptiveViewOption" val="auto"><div class="adaptiveCheckboxDiv checkedAdaptive"></div>Auto</div>');
  103. $viewSelect.append('<option value="auto">Auto</option>');
  104. if(typeof $axure.document.defaultAdaptiveView.name != 'undefined') {
  105. //If the name is a blank string, make the view name the width if non-zero, else 'any'
  106. var defaultViewName = $axure.document.defaultAdaptiveView.name;
  107. if(defaultViewName == '') {
  108. defaultViewName = $axure.document.defaultAdaptiveView.size.width != 0 ? $axure.document.defaultAdaptiveView.size.width : 'Base';
  109. }
  110. $adaptiveViewsContainer.append('<div class="adaptiveViewOption currentAdaptiveView" val="default"><div class="adaptiveCheckboxDiv"></div>' + defaultViewName + '</div>');
  111. $viewSelect.append('<option value="default">' + defaultViewName + '</option>');
  112. }
  113. var enabledViewIds = $axure.document.configuration.enabledViewIds;
  114. for(var viewIndex = 0; viewIndex < $axure.document.adaptiveViews.length; viewIndex++) {
  115. var currView = $axure.document.adaptiveViews[viewIndex];
  116. if(enabledViewIds.indexOf(currView.id) < 0) continue;
  117. var widthString = currView.size.width == 0 ? 'any' : currView.size.width;
  118. var heightString = currView.size.height == 0 ? 'any' : currView.size.height;
  119. var conditionString = '';
  120. if(currView.condition == '>' || currView.condition == '>=') {
  121. conditionString = ' and above';
  122. } else if(currView.condition == '<' || currView.condition == '<=') {
  123. conditionString = ' and below';
  124. }
  125. var viewString = currView.name + ' (' + widthString + ' x ' + heightString + conditionString + ')';
  126. $adaptiveViewsContainer.append('<div class="adaptiveViewOption" val="' + currView.id + '"><div class="adaptiveCheckboxDiv"></div>' + viewString + '</div>');
  127. $viewSelect.append('<option value="' + currView.id + '">' + viewString + '</option>');
  128. }
  129. $('.adaptiveViewOption').click(adaptiveViewOption_click);
  130. $('#leftPanel').mouseup(function() {
  131. $('.sitemapPopupContainer').hide();
  132. $('#variablesButton').removeClass('sitemapToolbarButtonSelected');
  133. $('#adaptiveButton').removeClass('sitemapToolbarButtonSelected');
  134. $('#linksButton').removeClass('sitemapToolbarButtonSelected');
  135. });
  136. $('#variablesContainer,#sitemapLinksContainer').mouseup(function(event) {
  137. event.stopPropagation();
  138. });
  139. $('#variablesButton').mouseup(function(event) {
  140. hideAllContainersExcept(2);
  141. event.stopPropagation();
  142. });
  143. $('#adaptiveButton').mouseup(function(event) {
  144. hideAllContainersExcept(1);
  145. event.stopPropagation();
  146. });
  147. $('.adaptiveViewOption').mouseup(function(event) {
  148. event.stopPropagation();
  149. });
  150. $('#linksButton').mouseup(function(event) {
  151. hideAllContainersExcept(3);
  152. event.stopPropagation();
  153. });
  154. $('#searchBox').focusin(function() {
  155. if($(this).is('.searchBoxHint')) {
  156. $(this).val('');
  157. $(this).removeClass('searchBoxHint');
  158. }
  159. }).focusout(function() {
  160. if($(this).val() == '') {
  161. $(this).addClass('searchBoxHint');
  162. $(this).val('Search');
  163. }
  164. });
  165. var $varContainer = $('#variablesContainer');
  166. $(window).resize(function() {
  167. if($varContainer.is(":visible")) {
  168. var newHeight = $(this).height() - 120;
  169. if(newHeight < 100) newHeight = 100;
  170. $varContainer.css('max-height', newHeight);
  171. }
  172. });
  173. });
  174. function hideAllContainersExcept(exceptContainer) {
  175. //1 - adaptive container, 2 - vars container, 3 - links container
  176. if(exceptContainer != 1) {
  177. $('#adaptiveViewsContainer').hide();
  178. $('#adaptiveButton').removeClass('sitemapToolbarButtonSelected');
  179. }
  180. if(exceptContainer != 2) {
  181. $('#variablesContainer').hide();
  182. $('#variablesButton').removeClass('sitemapToolbarButtonSelected');
  183. }
  184. if(exceptContainer != 3) {
  185. $('#sitemapLinksContainer').hide();
  186. $('#linksButton').removeClass('sitemapToolbarButtonSelected');
  187. }
  188. }
  189. function collapse_click(event) {
  190. $(this)
  191. .children('.sitemapMinus').removeClass('sitemapMinus').addClass('sitemapPlus').end()
  192. .closest('li').children('ul').hide(SHOW_HIDE_ANIMATION_DURATION);
  193. $(this).next('.sitemapFolderOpenIcon').removeClass('sitemapFolderOpenIcon').addClass('sitemapFolderIcon');
  194. }
  195. function expand_click(event) {
  196. $(this)
  197. .children('.sitemapPlus').removeClass('sitemapPlus').addClass('sitemapMinus').end()
  198. .closest('li').children('ul').show(SHOW_HIDE_ANIMATION_DURATION);
  199. $(this).next('.sitemapFolderIcon').removeClass('sitemapFolderIcon').addClass('sitemapFolderOpenIcon');
  200. }
  201. function node_click(event) {
  202. navigate(this.getAttribute('nodeUrl'), getHashStringVar(ADAPTIVE_VIEW_VAR_NAME));
  203. }
  204. function navigate(url, viewId) {
  205. $axure.page.navigate(url, true, viewId);
  206. }
  207. function links_click(event) {
  208. $('#sitemapLinksContainer').toggle();
  209. if($('#sitemapLinksContainer').is(":visible")) {
  210. $('#linksButton').addClass('sitemapToolbarButtonSelected');
  211. var linksButtonBottom = $('#linksButton').position().top + $('#linksButton').height();
  212. $('#sitemapLinksContainer').css('top', linksButtonBottom + 'px');
  213. } else {
  214. $('#linksButton').removeClass('sitemapToolbarButtonSelected');
  215. }
  216. }
  217. $axure.messageCenter.addMessageListener(function(message, data) {
  218. if(message == 'globalVariableValues') {
  219. //If variables container isn't visible, then ignore
  220. if(!$('#variablesContainer').is(":visible")) {
  221. return;
  222. }
  223. $('#variablesDiv').empty();
  224. for(var key in data) {
  225. var value = data[key] == '' ? '(blank)' : data[key];
  226. $('#variablesDiv').append('<div class="variableDiv"><span class="variableName">' + key + '</span><br/>' + value + '</div>');
  227. }
  228. } else if(message == 'adaptiveViewChange') {
  229. $('.adaptiveViewOption').removeClass('currentAdaptiveView');
  230. if(data) $('div[val="' + data + '"]').addClass('currentAdaptiveView');
  231. else $('div[val="default"]').addClass('currentAdaptiveView');
  232. }
  233. });
  234. function showvars_click(event) {
  235. $('#variablesContainer').toggle();
  236. if(!$('#variablesContainer').is(":visible")) {
  237. $('#variablesButton').removeClass('sitemapToolbarButtonSelected');
  238. } else {
  239. $(window).resize();
  240. $('#variablesButton').addClass('sitemapToolbarButtonSelected');
  241. var variablesButtonBottom = $('#variablesButton').position().top + $('#variablesButton').height();
  242. $('#variablesContainer').css('top', variablesButtonBottom + 'px');
  243. $('#variablesContainer').css('left', '30px');
  244. $('#variablesContainer').css('right', '30px');
  245. $axure.messageCenter.postMessage('getGlobalVariables', '');
  246. }
  247. }
  248. function clearvars_click(event) {
  249. $axure.messageCenter.postMessage('resetGlobalVariables', '');
  250. }
  251. function footnotes_click(event) {
  252. if($('#footnotesButton').is('.sitemapToolbarButtonSelected')) {
  253. $('#footnotesButton').removeClass('sitemapToolbarButtonSelected');
  254. $axure.messageCenter.postMessage('annotationToggle', false);
  255. //Add 'fn' hash string var so that footnotes stay hidden across reloads
  256. setVarInCurrentUrlHash(FOOTNOTES_VAR_NAME, 0);
  257. } else {
  258. $('#footnotesButton').addClass('sitemapToolbarButtonSelected');
  259. $axure.messageCenter.postMessage('annotationToggle', true);
  260. //Delete 'fn' hash string var if it exists since default is visible
  261. deleteVarFromCurrentUrlHash(FOOTNOTES_VAR_NAME);
  262. }
  263. }
  264. function highlight_interactive(event) {
  265. if($('#highlightInteractiveButton').is('.sitemapToolbarButtonSelected')) {
  266. $('#highlightInteractiveButton').removeClass('sitemapToolbarButtonSelected');
  267. $axure.messageCenter.postMessage('highlightInteractive', false);
  268. //Delete 'hi' hash string var if it exists since default is unselected
  269. deleteVarFromCurrentUrlHash(HIGHLIGHT_INTERACTIVE_VAR_NAME);
  270. } else {
  271. $('#highlightInteractiveButton').addClass('sitemapToolbarButtonSelected');
  272. $axure.messageCenter.postMessage('highlightInteractive', true);
  273. //Add 'hi' hash string var so that stay highlighted across reloads
  274. setVarInCurrentUrlHash(HIGHLIGHT_INTERACTIVE_VAR_NAME, 1);
  275. }
  276. }
  277. function adaptive_click(event) {
  278. $('#adaptiveViewsContainer').toggle();
  279. if(!$('#adaptiveViewsContainer').is(":visible")) {
  280. $('#adaptiveButton').removeClass('sitemapToolbarButtonSelected');
  281. } else {
  282. $('#adaptiveButton').addClass('sitemapToolbarButtonSelected');
  283. var adaptiveButtonBottom = $('#adaptiveButton').position().top + $('#adaptiveButton').height();
  284. $('#adaptiveViewsContainer').css('top', adaptiveButtonBottom + 'px');
  285. $('#adaptiveViewsContainer').css('left', $('#adaptiveButton').position().left);
  286. }
  287. }
  288. function adaptiveViewOption_click(event) {
  289. var currVal = $(this).attr('val');
  290. $('.checkedAdaptive').removeClass('checkedAdaptive');
  291. $(this).find('.adaptiveCheckboxDiv').addClass('checkedAdaptive');
  292. navigate($axure.page.location.split('#')[0], currVal != 'auto' ? currVal : undefined);
  293. if(currVal == 'auto') {
  294. //Remove view in hash string if one is set
  295. deleteVarFromCurrentUrlHash(ADAPTIVE_VIEW_VAR_NAME);
  296. } else {
  297. //Set current view in hash string so that it can be maintained across reloads
  298. setVarInCurrentUrlHash(ADAPTIVE_VIEW_VAR_NAME, currVal);
  299. }
  300. }
  301. function search_click(event) {
  302. $('#searchDiv').toggle();
  303. if(!$('#searchDiv').is(":visible")) {
  304. $('#searchButton').removeClass('sitemapToolbarButtonSelected');
  305. $('#searchBox').val('');
  306. $('#searchBox').keyup();
  307. $('#sitemapToolbar').css('height', '22px');
  308. $('#sitemapTreeContainer').css('top', '31px');
  309. } else {
  310. $('#searchButton').addClass('sitemapToolbarButtonSelected');
  311. $('#searchBox').focus();
  312. $('#sitemapToolbar').css('height', '50px');
  313. $('#sitemapTreeContainer').css('top', '63px');
  314. }
  315. }
  316. function search_input_keyup(event) {
  317. var searchVal = $(this).val().toLowerCase();
  318. //If empty search field, show all nodes, else grey+hide all nodes and
  319. //ungrey+unhide all matching nodes, as well as unhide their parent nodes
  320. if(searchVal == '') {
  321. $('.sitemapPageName').removeClass('sitemapGreyedName');
  322. $('.sitemapNode').show();
  323. } else {
  324. $('.sitemapNode').hide();
  325. $('.sitemapPageName').addClass('sitemapGreyedName').each(function() {
  326. var nodeName = $(this).text().toLowerCase();
  327. if(nodeName.indexOf(searchVal) != -1) {
  328. $(this).removeClass('sitemapGreyedName').parents('.sitemapNode:first').show().parents('.sitemapExpandableNode').show();
  329. }
  330. });
  331. }
  332. }
  333. function withoutSitemapRadio_click() {
  334. $('#sitemapLinkWithPlayer').val(currentPageLoc);
  335. $('#minimizeBox').attr('disabled', 'disabled');
  336. $('#footnotesBox').attr('disabled', 'disabled');
  337. $('#highlightBox').attr('disabled', 'disabled');
  338. $('#viewSelect').attr('disabled', 'disabled');
  339. }
  340. function withSitemapRadio_click() {
  341. $('#sitemapLinkWithPlayer').val(currentPlayerLoc + currentPageHashString);
  342. $('#minimizeBox').removeAttr('disabled').change();
  343. $('#footnotesBox').removeAttr('disabled').change();
  344. $('#highlightBox').removeAttr('disabled').change();
  345. $('#viewSelect').removeAttr('disabled').change();
  346. }
  347. function sitemapUrlOptions_change() {
  348. var currLinkHash = '#' + $('#sitemapLinkWithPlayer').val().split("#")[1];
  349. var newHash = null;
  350. var varName = '';
  351. var defVal = 1;
  352. if($(this).is('#minimizeBox')) {
  353. varName = SITEMAP_COLLAPSE_VAR_NAME;
  354. } else if($(this).is('#footnotesBox')) {
  355. varName = FOOTNOTES_VAR_NAME;
  356. defVal = 0;
  357. } else if($(this).is('#highlightBox')) {
  358. varName = HIGHLIGHT_INTERACTIVE_VAR_NAME;
  359. }
  360. newHash = $(this).is(':checked') ? setHashStringVar(currLinkHash, varName, defVal) : deleteHashStringVar(currLinkHash, varName);
  361. if(newHash != null) {
  362. $('#sitemapLinkWithPlayer').val(currentPlayerLoc + newHash);
  363. }
  364. }
  365. function sitemapUrlViewSelect_change() {
  366. var currLinkHash = '#' + $('#sitemapLinkWithPlayer').val().split("#")[1];
  367. var newHash = null;
  368. var $selectedOption = $(this).find('option:selected');
  369. if($selectedOption.length == 0) return;
  370. var selectedVal = $selectedOption.attr('value');
  371. newHash = selectedVal == 'auto' ? deleteHashStringVar(currLinkHash, ADAPTIVE_VIEW_VAR_NAME) : setHashStringVar(currLinkHash, ADAPTIVE_VIEW_VAR_NAME, selectedVal);
  372. if(newHash != null) {
  373. $('#sitemapLinkWithPlayer').val(currentPlayerLoc + newHash);
  374. }
  375. }
  376. function generateSitemap() {
  377. var treeUl = "<div id='sitemapToolbar'>";
  378. treeUl += "<div style='height:30px;'>";
  379. if($axure.document.configuration.enabledViewIds.length > 0) {
  380. treeUl += "<a id='adaptiveButton' title='Select Adaptive View' class='sitemapToolbarButton'></a>";
  381. }
  382. if($axure.document.configuration.showAnnotations == true) {
  383. treeUl += "<a id='footnotesButton' title='Toggle Footnotes' class='sitemapToolbarButton'></a>";
  384. }
  385. treeUl += "<a id='highlightInteractiveButton' title='Highlight interactive elements' class='sitemapToolbarButton'></a>";
  386. treeUl += "<a id='variablesButton' title='View Variables' class='sitemapToolbarButton'></a>";
  387. treeUl += "<a id='linksButton' title='Get Links' class='sitemapToolbarButton'></a>";
  388. treeUl += "<a id='searchButton' title='Search Pages' class='sitemapToolbarButton'></a>";
  389. treeUl += "</div>";
  390. treeUl += '<div id="searchDiv" style="width:98%; clear:both;"><input id="searchBox" style="width: 100%;" type="text"/></div>';
  391. treeUl += "<div id='sitemapLinksContainer' class='sitemapPopupContainer'><span id='sitemapLinksPageName'>Page Name</span>";
  392. treeUl += "<div class='sitemapLinkContainer'><input id='sitemapLinkWithPlayer' type='text' class='sitemapLinkField'/></div>";
  393. treeUl += "<div class='sitemapOptionContainer'>";
  394. treeUl += "<div><label><input type='radio' name='sitemapToggle' value='withoutmap'/>without sitemap</label></div>";
  395. treeUl += "<div><label><input type='radio' name='sitemapToggle' value='withmap'/>with sitemap</label>";
  396. treeUl += "<div id='sitemapOptionsDiv'>";
  397. treeUl += "<div class='sitemapUrlOption'><label><input type='checkbox' id='minimizeBox' />minimize sitemap</label></div>";
  398. if($axure.document.configuration.showAnnotations == true) {
  399. treeUl += "<div class='sitemapUrlOption'><label><input type='checkbox' id='footnotesBox' />hide footnotes</label></div>";
  400. }
  401. treeUl += "<div class='sitemapUrlOption'><label><input type='checkbox' id='highlightBox' />highlight interactive elements</label></div>";
  402. if($axure.document.configuration.enabledViewIds.length > 0) {
  403. treeUl += "<div id='viewSelectDiv' class='sitemapUrlOption'><label>View: <select id='viewSelect'></select></label></div>";
  404. }
  405. treeUl += "</div></div></div></div>";
  406. treeUl += "<div id='variablesContainer' class='sitemapPopupContainer'><a id='variablesClearLink'>Reset Variables</a><br/><br/><div id='variablesDiv'></div></div>";
  407. if($axure.document.adaptiveViews.length > 0) {
  408. treeUl += "<div id='adaptiveViewsContainer' class='sitemapPopupContainer'></div>";
  409. }
  410. treeUl += "</div>";
  411. treeUl += "<div id='sitemapTreeContainer'>";
  412. treeUl += "<ul class='sitemapTree' style='clear:both;'>";
  413. var rootNodes = $axure.document.sitemap.rootNodes;
  414. for(var i = 0; i < rootNodes.length; i++) {
  415. treeUl += generateNode(rootNodes[i], 0);
  416. }
  417. treeUl += "</ul></div>";
  418. $('#sitemapHost').html(treeUl);
  419. }
  420. function generateNode(node, level) {
  421. var hasChildren = (node.children && node.children.length > 0);
  422. if(hasChildren) {
  423. var returnVal = "<li class='sitemapNode sitemapExpandableNode'><div><div class='sitemapPageLinkContainer' style='margin-left:" + (15 + level * 17) + "px'><a class='sitemapPlusMinusLink'><span class='sitemapMinus'></span></a>";
  424. } else {
  425. var returnVal = "<li class='sitemapNode sitemapLeafNode'><div><div class='sitemapPageLinkContainer' style='margin-left:" + (27 + level * 17) + "px'>";
  426. }
  427. var isFolder = node.type == "Folder";
  428. if(!isFolder) returnVal += "<a class='sitemapPageLink' nodeUrl='" + node.url + "'>";
  429. returnVal += "<span class='sitemapPageIcon";
  430. if(node.type == "Flow") { returnVal += " sitemapFlowIcon"; }
  431. if(isFolder) {
  432. if(hasChildren) returnVal += " sitemapFolderOpenIcon";
  433. else returnVal += " sitemapFolderIcon";
  434. }
  435. returnVal += "'></span><span class='sitemapPageName'>";
  436. returnVal += $('<div/>').text(node.pageName).html();
  437. returnVal += "</span>";
  438. if(!isFolder) returnVal += "</a>";
  439. returnVal += "</div></div>";
  440. if(hasChildren) {
  441. returnVal += "<ul>";
  442. for(var i = 0; i < node.children.length; i++) {
  443. var child = node.children[i];
  444. returnVal += generateNode(child, level + 1);
  445. }
  446. returnVal += "</ul>";
  447. }
  448. returnVal += "</li>";
  449. return returnVal;
  450. }
  451. function getHashStringVar(query) {
  452. var qstring = window.location.href.split("#");
  453. if(qstring.length < 2) return "";
  454. var prms = qstring[1].split("&");
  455. var frmelements = new Array();
  456. var currprmeter, querystr = "";
  457. for(var i = 0; i < prms.length; i++) {
  458. currprmeter = prms[i].split("=");
  459. frmelements[i] = new Array();
  460. frmelements[i][0] = currprmeter[0];
  461. frmelements[i][1] = currprmeter[1];
  462. }
  463. for(var j = 0; j < frmelements.length; j++) {
  464. if(frmelements[j][0] == query) {
  465. querystr = frmelements[j][1];
  466. break;
  467. }
  468. }
  469. return querystr;
  470. }
  471. function replaceHash(newHash) {
  472. var currentLocWithoutHash = window.location.toString().split('#')[0];
  473. //We use replace so that every hash change doesn't get appended to the history stack.
  474. //We use replaceState in browsers that support it, else replace the location
  475. if(typeof window.history.replaceState != 'undefined') {
  476. window.history.replaceState(null, null, currentLocWithoutHash + newHash);
  477. } else {
  478. window.location.replace(currentLocWithoutHash + newHash);
  479. }
  480. }
  481. function setHashStringVar(currentHash, varName, varVal) {
  482. var varWithEqual = varName + '=';
  483. var hashToSet = '';
  484. var pageIndex = currentHash.indexOf('#' + varWithEqual);
  485. if(pageIndex == -1) pageIndex = currentHash.indexOf('&' + varWithEqual);
  486. if(pageIndex != -1) {
  487. var newHash = currentHash.substring(0, pageIndex);
  488. newHash = newHash == '' ? '#' + varWithEqual + varVal : newHash + '&' + varWithEqual + varVal;
  489. var ampIndex = currentHash.indexOf('&', pageIndex + 1);
  490. if(ampIndex != -1) {
  491. newHash = newHash + currentHash.substring(ampIndex);
  492. }
  493. hashToSet = newHash;
  494. } else if(currentHash.indexOf('#') != -1) {
  495. hashToSet = currentHash + '&' + varWithEqual + varVal;
  496. } else {
  497. hashToSet = '#' + varWithEqual + varVal;
  498. }
  499. if(hashToSet != '') {
  500. return hashToSet;
  501. }
  502. return null;
  503. }
  504. function setVarInCurrentUrlHash(varName, varVal) {
  505. var newHash = setHashStringVar(window.location.hash, varName, varVal);
  506. if(newHash != null) {
  507. replaceHash(newHash);
  508. }
  509. }
  510. function deleteHashStringVar(currentHash, varName) {
  511. var varWithEqual = varName + '=';
  512. var pageIndex = currentHash.indexOf('#' + varWithEqual);
  513. if(pageIndex == -1) pageIndex = currentHash.indexOf('&' + varWithEqual);
  514. if(pageIndex != -1) {
  515. var newHash = currentHash.substring(0, pageIndex);
  516. var ampIndex = currentHash.indexOf('&', pageIndex + 1);
  517. //IF begin of string....if none blank, ELSE # instead of & and rest
  518. //IF in string....prefix + if none blank, ELSE &-rest
  519. if(newHash == '') { //beginning of string
  520. newHash = ampIndex != -1 ? '#' + currentHash.substring(ampIndex + 1) : '';
  521. } else { //somewhere in the middle
  522. newHash = newHash + (ampIndex != -1 ? currentHash.substring(ampIndex) : '');
  523. }
  524. return newHash;
  525. }
  526. return null;
  527. }
  528. function deleteVarFromCurrentUrlHash(varName) {
  529. var newHash = deleteHashStringVar(window.location.hash, varName);
  530. if(newHash != null) {
  531. replaceHash(newHash);
  532. }
  533. }
  534. })();