sitemap.js 28 KB

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