PageSourceSearch

http://www.efojs.com/elefunfunt/plugins/sitemap/sitemap.js

js efojs.com collected 2026-10-06 03:41:08 UTC 22,023 bytes, 490 lines download raw bytes

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

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.