| 1 | Index: plugins/CoreHome/templates/url_anchor.js |
|---|
| 2 | =================================================================== |
|---|
| 3 | --- plugins/CoreHome/templates/url_anchor.js (revision 0) |
|---|
| 4 | +++ plugins/CoreHome/templates/url_anchor.js (revision 0) |
|---|
| 5 | @@ -0,0 +1,83 @@ |
|---|
| 6 | +/* |
|---|
| 7 | + this class will be created by the menu.js file in document.ready(); |
|---|
| 8 | + */ |
|---|
| 9 | + |
|---|
| 10 | +function url_anchor(){ |
|---|
| 11 | + |
|---|
| 12 | + /* |
|---|
| 13 | + * Bind any url click that we want to use the anchor here: |
|---|
| 14 | + */ |
|---|
| 15 | + |
|---|
| 16 | + // handle period click |
|---|
| 17 | + $("#otherPeriods a").bind('click',this.handleAllLinkClick); |
|---|
| 18 | + |
|---|
| 19 | + // sites selection link will be bind within the sites_selection.tpl, |
|---|
| 20 | + // because by the time this get call the sites_selection dom is not ready. |
|---|
| 21 | + |
|---|
| 22 | + return this; |
|---|
| 23 | +b} |
|---|
| 24 | + |
|---|
| 25 | +url_anchor.prototype = |
|---|
| 26 | +{ |
|---|
| 27 | + |
|---|
| 28 | + updateAnchor : function(li_id,urlAjax) |
|---|
| 29 | + { |
|---|
| 30 | + var module = this.getParamValueFromUrl(urlAjax,"module"); |
|---|
| 31 | + var action = this.getParamValueFromUrl(urlAjax,"action"); |
|---|
| 32 | + var anchor = "#module=" + module + "&" + "action=" + action; |
|---|
| 33 | + |
|---|
| 34 | + //we don't want the current anchor on the url address |
|---|
| 35 | + var location_href = window.location.href.substring(0,window.location.href.indexOf("#")); |
|---|
| 36 | + //set the anchor |
|---|
| 37 | + url_anchor.getAnchor = anchor; |
|---|
| 38 | + window.location = location_href + anchor; |
|---|
| 39 | + }, |
|---|
| 40 | + |
|---|
| 41 | + isAnchorExists : function() |
|---|
| 42 | + { |
|---|
| 43 | + var currentUrl = window.location.href; |
|---|
| 44 | + //if currentURL have a #sign we assuming it is an anchor and return the rest of the string |
|---|
| 45 | + var pattern = /#/; |
|---|
| 46 | + if(currentUrl.match(pattern)) |
|---|
| 47 | + { |
|---|
| 48 | + return currentUrl.substring(currentUrl.indexOf("#"),currentUrl.length); |
|---|
| 49 | + } |
|---|
| 50 | + else |
|---|
| 51 | + { |
|---|
| 52 | + return undefined; |
|---|
| 53 | + } |
|---|
| 54 | + }, |
|---|
| 55 | + |
|---|
| 56 | + /* |
|---|
| 57 | + * help to get param value for any given url string and param name |
|---|
| 58 | + * don't pass in url with any anchor#. |
|---|
| 59 | + # if you want to look for anchor param, just pass in the string after the # sign. |
|---|
| 60 | + */ |
|---|
| 61 | + getParamValueFromUrl : function (url,param) |
|---|
| 62 | + { |
|---|
| 63 | + if((startStr = url.indexOf(param)) >= 0) |
|---|
| 64 | + { |
|---|
| 65 | + var endStr = url.indexOf("&", startStr); |
|---|
| 66 | + if(endStr == -1) |
|---|
| 67 | + { |
|---|
| 68 | + endStr = url.length; |
|---|
| 69 | + } |
|---|
| 70 | + return url.substring(startStr + param.length +1,endStr); |
|---|
| 71 | + } |
|---|
| 72 | + else |
|---|
| 73 | + { |
|---|
| 74 | + return undefined; |
|---|
| 75 | + } |
|---|
| 76 | + }, |
|---|
| 77 | + |
|---|
| 78 | + /* |
|---|
| 79 | + * Append the anchor to url before proceed to new url |
|---|
| 80 | + */ |
|---|
| 81 | + handleAllLinkClick : function (e){ |
|---|
| 82 | + e.preventDefault(); |
|---|
| 83 | + |
|---|
| 84 | + var currLink_anchor = $(e.target).attr("href") + url_anchor.getAnchor; |
|---|
| 85 | + |
|---|
| 86 | + window.location.href = currLink_anchor; |
|---|
| 87 | + } |
|---|
| 88 | +}; |
|---|
| 89 | |
|---|
| 90 | Index: plugins/CoreHome/templates/menu.js |
|---|
| 91 | =================================================================== |
|---|
| 92 | --- plugins/CoreHome/templates/menu.js (revision 971) |
|---|
| 93 | +++ plugins/CoreHome/templates/menu.js (working copy) |
|---|
| 94 | @@ -71,7 +71,13 @@ |
|---|
| 95 | data: new Object |
|---|
| 96 | }; |
|---|
| 97 | $.ajax(ajaxRequest); |
|---|
| 98 | - |
|---|
| 99 | + |
|---|
| 100 | + /* |
|---|
| 101 | + * setup anchor and add to the address |
|---|
| 102 | + */ |
|---|
| 103 | + var li_id = $(this).attr("id"); |
|---|
| 104 | + piwikUrlAnchor.updateAnchor(li_id,urlAjax); |
|---|
| 105 | + |
|---|
| 106 | return false; |
|---|
| 107 | |
|---|
| 108 | }, |
|---|
| 109 | @@ -93,20 +99,51 @@ |
|---|
| 110 | .find("li:has(ul)") |
|---|
| 111 | .hover(self.overMainLI, self.outMainLI) |
|---|
| 112 | ; |
|---|
| 113 | + // add support for anchor in url. |
|---|
| 114 | + // for all sub menu we want to have a unique id based on their module and action |
|---|
| 115 | + this.param.superfish.find('li').each(function(){ |
|---|
| 116 | + var url = $(this).find('a').attr('name'); |
|---|
| 117 | + var module = piwikUrlAnchor.getParamValueFromUrl(url,"module"); |
|---|
| 118 | + var action = piwikUrlAnchor.getParamValueFromUrl(url,"action"); |
|---|
| 119 | + //don't add id if it is a main menu, anchor doesn't care about main menu at this point |
|---|
| 120 | + var main_menu = ($(this).parent().attr("class").match(/nav/)) ? true : undefined; |
|---|
| 121 | + if(!main_menu){ |
|---|
| 122 | + $(this).attr({ id: module +'_'+action}); |
|---|
| 123 | + } |
|---|
| 124 | + }); |
|---|
| 125 | }, |
|---|
| 126 | |
|---|
| 127 | loadFirstSection: function() |
|---|
| 128 | { |
|---|
| 129 | - var self=this; |
|---|
| 130 | - $('li:first', self.param.superfish) |
|---|
| 131 | - .click() |
|---|
| 132 | - .each(function(){ |
|---|
| 133 | - $(this).showSuperfishUl(); |
|---|
| 134 | - }); |
|---|
| 135 | + var self=this; |
|---|
| 136 | + |
|---|
| 137 | + //if anchor exist click on the right menu. |
|---|
| 138 | + if(anchor = piwikUrlAnchor.isAnchorExists()) |
|---|
| 139 | + { |
|---|
| 140 | + var anchor_module = piwikUrlAnchor.getParamValueFromUrl(anchor,"module"); |
|---|
| 141 | + var anchor_action = piwikUrlAnchor.getParamValueFromUrl(anchor,"action"); |
|---|
| 142 | + var li_id = anchor_module + '_' + anchor_action; |
|---|
| 143 | + |
|---|
| 144 | + $("#"+li_id).click(); |
|---|
| 145 | + $("#"+li_id).each( function(){ |
|---|
| 146 | + $(this).parents().showSuperfishUl(); |
|---|
| 147 | + }); |
|---|
| 148 | + } |
|---|
| 149 | + else //Default |
|---|
| 150 | + { |
|---|
| 151 | + $('li:first', self.param.superfish) |
|---|
| 152 | + .click() |
|---|
| 153 | + .each(function(){ |
|---|
| 154 | + $(this).showSuperfishUl(); |
|---|
| 155 | + }); |
|---|
| 156 | + } |
|---|
| 157 | } |
|---|
| 158 | -} |
|---|
| 159 | +}; |
|---|
| 160 | |
|---|
| 161 | $(document).ready( function(){ |
|---|
| 162 | + //create the url_anchor obj to be use when user click on a module |
|---|
| 163 | + piwikUrlAnchor = new url_anchor(); |
|---|
| 164 | + |
|---|
| 165 | piwikMenu = new menu(); |
|---|
| 166 | piwikMenu.init(); |
|---|
| 167 | piwikMenu.loadFirstSection(); |
|---|
| 168 | Index: plugins/CoreHome/templates/calendar.js |
|---|
| 169 | =================================================================== |
|---|
| 170 | --- plugins/CoreHome/templates/calendar.js (revision 971) |
|---|
| 171 | +++ plugins/CoreHome/templates/calendar.js (working copy) |
|---|
| 172 | @@ -101,8 +101,16 @@ |
|---|
| 173 | var currentUrl = window.location.href; |
|---|
| 174 | if((startStrDate = currentUrl.indexOf("date")) >= 0) |
|---|
| 175 | { |
|---|
| 176 | - // look for the & after the date |
|---|
| 177 | - var endStrDate = currentUrl.indexOf("&", startStrDate); |
|---|
| 178 | + // look for the # after the date or & after date |
|---|
| 179 | + // We need to know if anchorIndex exist; |
|---|
| 180 | + var anchorIndex = currentUrl.match(/#/) ? currentUrl.indexOf("#", startStrDate) : undefined; |
|---|
| 181 | + var endStrDate = currentUrl.indexOf("&", startStrDate); |
|---|
| 182 | + |
|---|
| 183 | + // if endStrDate is higher than anchorIndex use anchor Index |
|---|
| 184 | + if(anchorIndex && (endStrDate > anchorIndex)){ |
|---|
| 185 | + endStrDate = anchorIndex; |
|---|
| 186 | + } |
|---|
| 187 | + |
|---|
| 188 | if(endStrDate == -1) |
|---|
| 189 | { |
|---|
| 190 | endStrDate = currentUrl.length; |
|---|
| 191 | Index: plugins/CoreHome/templates/sites_selection.tpl |
|---|
| 192 | =================================================================== |
|---|
| 193 | --- plugins/CoreHome/templates/sites_selection.tpl (revision 971) |
|---|
| 194 | +++ plugins/CoreHome/templates/sites_selection.tpl (working copy) |
|---|
| 195 | @@ -24,6 +24,9 @@ |
|---|
| 196 | var widthSitesSelection = $("#selectedSiteName").width() + 4 + extraPadding; |
|---|
| 197 | $("#sitesSelectionWrapper").css('padding-right', widthSitesSelection); |
|---|
| 198 | $("#sitesSelection").fdd2div({CssClassName:"formDiv"}); |
|---|
| 199 | + |
|---|
| 200 | + // this will put the anchor after the url before proceed to different site. |
|---|
| 201 | + $("#sitesSelection ul li").bind('click',piwikUrlAnchor.handleAllLinkClick); |
|---|
| 202 | });</script> |
|---|
| 203 | {/literal} |
|---|
| 204 | </span> |
|---|
| 205 | |
|---|
| 206 | Index: plugins/CoreHome/templates/js_css_includes.tpl |
|---|
| 207 | =================================================================== |
|---|
| 208 | --- plugins/CoreHome/templates/js_css_includes.tpl (revision 971) |
|---|
| 209 | +++ plugins/CoreHome/templates/js_css_includes.tpl (working copy) |
|---|
| 210 | @@ -17,6 +17,7 @@ |
|---|
| 211 | <script type="text/javascript" src="plugins/CoreHome/templates/menu.js"></script> |
|---|
| 212 | <script type="text/javascript" src="libs/jquery/thickbox.js"></script> |
|---|
| 213 | <link rel="stylesheet" type="text/css" href="libs/jquery/thickbox.css" /> |
|---|
| 214 | +<script type="text/javascript" src="plugins/CoreHome/templates/url_anchor.js"></script> |
|---|
| 215 | |
|---|
| 216 | <link rel="stylesheet" type="text/css" href="themes/default/common.css" /> |
|---|
| 217 | <link rel="stylesheet" type="text/css" href="plugins/CoreHome/templates/styles.css" /> |
|---|
| 218 | |
|---|