From 2a4f699be56444e63675e158fb815530717d0c86 Mon Sep 17 00:00:00 2001 From: yomguy Date: Tue, 31 Jan 2012 16:24:50 +0100 Subject: [PATCH] fix drop down menu highlight --- telemeta/htdocs/css/telemeta.css | 5 +- telemeta/htdocs/js/application.js | 483 +++++++++++++------------- telemeta/templates/telemeta/base.html | 20 +- telemeta/urls.py | 12 +- telemeta/views/base.py | 10 +- 5 files changed, 267 insertions(+), 263 deletions(-) diff --git a/telemeta/htdocs/css/telemeta.css b/telemeta/htdocs/css/telemeta.css index 4bec0d50..e1db6f33 100644 --- a/telemeta/htdocs/css/telemeta.css +++ b/telemeta/htdocs/css/telemeta.css @@ -460,6 +460,7 @@ form.login .submit { background-color: #FFF; color: #6a0307; } + #menu .darkblue { border-bottom-color: #0f3179; } #menu .blue { border-bottom-color: #4f628a; } #menu .green { border-bottom-color: #92b220; } @@ -545,10 +546,6 @@ color:#FFF; color: #6a0307 ; } -#nav ul a:active{ - background-color: #FFF; - color: #6a0307 ; -} diff --git a/telemeta/htdocs/js/application.js b/telemeta/htdocs/js/application.js index 9ddf1971..bde5903c 100644 --- a/telemeta/htdocs/js/application.js +++ b/telemeta/htdocs/js/application.js @@ -1,239 +1,246 @@ -/* - * Copyright (C) 2007-2011 Parisson - * Copyright (c) 2011 Riccardo Zaccarelli - * Copyright (c) 2010 Olivier Guilyardi - * - * This file is part of TimeSide. - * - * TimeSide is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 2 of the License, or - * (at your option) any later version. - * - * TimeSide is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with TimeSide. If not, see . - * - * Authors: Riccardo Zaccarelli - * Olivier Guilyardi - */ - -/** - * Class for telemeta global functions. - * Note that the dollar sign is a reserved keyword in some browsers - * (see http://davidwalsh.name/dollar-functions) - * which might be in conflict with jQuery dollar sign. - */ - -//returns the full path of the current url location removing the last slash '/' followed by one or more '#', if any -function urlNormalized(){ - var sPath = window.location.href; - sPath = sPath.replace(/\/#*$/,""); - return sPath; -} -/** - *sets up few stuff when the page is ready (see functions below it) - */ -jQuery(document).ready(function() { - foldInfoBlocks(); - setSelectedMenu(); -}); - -/** - *function inherited from old code, never touched. Guess fixes the click on the left data table, if any - */ -function foldInfoBlocks() { - var $J = jQuery; - var extra = $J('.extraInfos'); - extra.find('.folded dl, .folded table').css('display', 'none'); - extra.find('h4').click(function() { - $J(this).parents('.extraInfos').children().toggleClass('folded').find('dl, table').toggle(100); - //toggle toggles the visibility of elements - return false; - }); -} - -/** - * Global telemeta function which sets the current selected menu according to the current url - */ -function setSelectedMenu(){ - var $J = jQuery; - var menus = $J('#menu a'); - //build collections/items from http:/site/collections/items, - //being http:/site/ = window.location.origin - - //function for normalizing paths (removes last n occurrences of the slash) - var normalize = function(str){ - return str.replace(/\/+#*$/,""); - } - - var host = window.location.host; - var protocol = window.location.protocol - var href = normalize(window.location.href); - - if(!(host) || !(protocol) || !(href)){ - return; - } - - //var pageOrigin = normalize(window.location.origin); //does not exist in FF, so: - var pageOrigin = normalize(protocol+"//"+host); - var pageHref = normalize(href); - - menus.each(function(){ - ///if we are at home, the window location href corresponds to window location origin, - //so we select only links whose link points EXACTLY to the origin (home link) - var linkHref = normalize(this.href); - var elm = $J(this); - if(pageOrigin===pageHref){ - if(pageHref == linkHref){ - elm.addClass('active'); - }else{ - elm.removeClass('active'); - } - }else{ - //here, on the other hand, we select if a link points to a page or super page - //of the current page - if(linkHref!=pageOrigin && pageHref.match("^"+linkHref+".*")){ - elm.addClass('active'); - }else{ - elm.removeClass('active'); - } - } - - }) -} - - - - -/***************************************************************************** - * json(param, method, onSuccesFcn(data, textStatus, jqXHR), onErrorFcn(jqXHR, textStatus, errorThrown)) - * global function to senbd/retrieve data with the server - * - * param: the data to be sent or retrieved. - * param will be converted to string, escaping quotes newlines and backslashes if necessary. - * param can be a javascript string, boolean, number, dictionary and array. - * If dictionary or array, it must contain only the above mentioned recognized types. - * So, eg, {[" a string"]} is fine, {[/asd/]} not - * - * method: the json method, eg "telemeta.update_marker". See base.py - * - * onSuccesFcn(data, textStatus, jqXHR) OPTIONAL --IF MISSING, NOTHING HAPPENS -- - * A function to be called if the request succeeds with the same syntax of jQuery's ajax onSuccess function. - * The function gets passed three arguments - * The data returned from the server, formatted according to the dataType parameter; - * a string describing the status; - * and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object - * - * onErrorFcn(jqXHR, textStatus, errorThrown) OPTIONAL. --IF MISSING, THE DEFAULT ERROR DIALOG IS SHOWN-- - * A function to be called if the request fails with the same syntax of jQuery ajax onError function.. - * The function receives three arguments: - * The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, - * a string describing the type of error that occurred and - * an optional exception object, if one occurred. - * Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". - * ****************************************************************************/ - -var json = function(param,method,onSuccessFcn,onErrorFcn){ - //this function converts a javascript object to a string - var toString_ = function(string){ - if(typeof string == "string"){ - //escapes newlines quotes and backslashes - string = string.replace(/\\/g,"\\\\") - .replace(/\n/g,"\\n") - .replace(/"/g,"\\\""); - } - var array; //used for arrays and objects (see below) - if(typeof string == "boolean" || typeof string== "number" || typeof string == "string"){ - string = '"'+string+'"'; - }else if(string instanceof Array){ - array = []; - for(var i = 0;i + * Copyright (c) 2010 Olivier Guilyardi + * + * This file is part of TimeSide. + * + * TimeSide is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * TimeSide is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with TimeSide. If not, see . + * + * Authors: Riccardo Zaccarelli + * Olivier Guilyardi + */ + +/** + * Class for telemeta global functions. + * Note that the dollar sign is a reserved keyword in some browsers + * (see http://davidwalsh.name/dollar-functions) + * which might be in conflict with jQuery dollar sign. + */ + +//returns the full path of the current url location removing the last slash '/' followed by one or more '#', if any +function urlNormalized(){ + var sPath = window.location.href; + sPath = sPath.replace(/\/#*$/,""); + return sPath; +} +/** + *sets up few stuff when the page is ready (see functions below it) + */ +jQuery(document).ready(function() { + foldInfoBlocks(); + setSelectedMenu(); +}); + +/** + *function inherited from old code, never touched. Guess fixes the click on the left data table, if any + */ +function foldInfoBlocks() { + var $J = jQuery; + var extra = $J('.extraInfos'); + extra.find('.folded dl, .folded table').css('display', 'none'); + extra.find('h4').click(function() { + $J(this).parents('.extraInfos').children().toggleClass('folded').find('dl, table').toggle(100); + //toggle toggles the visibility of elements + return false; + }); +} + +/** + * Global telemeta function which sets the current selected menu according to the current url + */ +function setSelectedMenu(){ + var $J = jQuery; + var menus = $J('#menu a'); + //build collections/items from http:/site/collections/items, + //being http:/site/ = window.location.origin + + //function for normalizing paths (removes last n occurrences of the slash) + var normalize = function(str){ + return str.replace(/\/+#*$/,""); + } + + var host = window.location.host; + var protocol = window.location.protocol + var href = normalize(window.location.href); + + if(!(host) || !(protocol) || !(href)){ + return; + } + + //var pageOrigin = normalize(window.location.origin); //does not exist in FF, so: + var pageOrigin = normalize(protocol+"//"+host); + var pageHref = normalize(href); + + menus.each(function(){ + ///if we are at home, the window location href corresponds to window location origin, + //so we select only links whose link points EXACTLY to the origin (home link) + var linkHref = normalize(this.href); + var elm = $J(this); + + if(linkHref.indexOf("#") != -1){ + var reg = new RegExp("[#]+", "g"); + var baseHref = linkHref.split(reg); + linkHref = pageOrigin + "/" + baseHref[1] + } + + if(pageOrigin===pageHref){ + if(pageHref == linkHref){ + elm.addClass('active'); + }else{ + elm.removeClass('active'); + } + }else{ + //here, on the other hand, we select if a link points to a page or super page + //of the current page + if(linkHref!=pageOrigin && pageHref.match("^"+linkHref+".*")){ + elm.addClass('active'); + }else{ + elm.removeClass('active'); + } + } + + }) +} + + + + +/***************************************************************************** + * json(param, method, onSuccesFcn(data, textStatus, jqXHR), onErrorFcn(jqXHR, textStatus, errorThrown)) + * global function to senbd/retrieve data with the server + * + * param: the data to be sent or retrieved. + * param will be converted to string, escaping quotes newlines and backslashes if necessary. + * param can be a javascript string, boolean, number, dictionary and array. + * If dictionary or array, it must contain only the above mentioned recognized types. + * So, eg, {[" a string"]} is fine, {[/asd/]} not + * + * method: the json method, eg "telemeta.update_marker". See base.py + * + * onSuccesFcn(data, textStatus, jqXHR) OPTIONAL --IF MISSING, NOTHING HAPPENS -- + * A function to be called if the request succeeds with the same syntax of jQuery's ajax onSuccess function. + * The function gets passed three arguments + * The data returned from the server, formatted according to the dataType parameter; + * a string describing the status; + * and the jqXHR (in jQuery 1.4.x, XMLHttpRequest) object + * + * onErrorFcn(jqXHR, textStatus, errorThrown) OPTIONAL. --IF MISSING, THE DEFAULT ERROR DIALOG IS SHOWN-- + * A function to be called if the request fails with the same syntax of jQuery ajax onError function.. + * The function receives three arguments: + * The jqXHR (in jQuery 1.4.x, XMLHttpRequest) object, + * a string describing the type of error that occurred and + * an optional exception object, if one occurred. + * Possible values for the second argument (besides null) are "timeout", "error", "abort", and "parsererror". + * ****************************************************************************/ + +var json = function(param,method,onSuccessFcn,onErrorFcn){ + //this function converts a javascript object to a string + var toString_ = function(string){ + if(typeof string == "string"){ + //escapes newlines quotes and backslashes + string = string.replace(/\\/g,"\\\\") + .replace(/\n/g,"\\n") + .replace(/"/g,"\\\""); + } + var array; //used for arrays and objects (see below) + if(typeof string == "boolean" || typeof string== "number" || typeof string == "string"){ + string = '"'+string+'"'; + }else if(string instanceof Array){ + array = []; + for(var i = 0;i -