X-Git-Url: http://git.cyclocoop.org/?p=velocampus%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fprive%2Fjavascript%2Fmultilang.js;fp=www%2Fprive%2Fjavascript%2Fmultilang.js;h=c0b5e17128e3989c01e747de0fad5fe2527d6e63;hp=0000000000000000000000000000000000000000;hb=80b4d3e85f78d402ed2e73f8f5d1bf4c19962eed;hpb=aaf970bf4cdaf76689ecc10609048e18d073820c diff --git a/www/prive/javascript/multilang.js b/www/prive/javascript/multilang.js new file mode 100644 index 0000000..c0b5e17 --- /dev/null +++ b/www/prive/javascript/multilang.js @@ -0,0 +1,238 @@ +/* + * multilang + * + * Copyright (c) 2006-2010 Renato Formato (rformato@gmail.com) + * Licensed under the GPL License: + * http://www.gnu.org/licenses/gpl.html + * + */ + +var multilang_containers={}, //menu containers + forms_fields={}, + multilang_forms, //forms to be processed (jQuery object) + multilang_menu_lang; //template of the menu (jQuery object) +/* +(?:\[([a-z_]+)\]|^[\s\n]*) +[lang] or white space + +((?:.|\n)*?) +all chars not greedy + +(?=\[[a-z_]+\]|$) +[lang] or end string +*/ +var match_multi = /(?:\[([a-z_]+)\]|^[\s\n]*)((?:.|\n|\s)*?)(?=\[[a-z_]+\]|$)/ig; +var multilang_css_link, + multilang_css_cur_link={}, + multilang_root, //root of the search (jQuery object) + multilang_fields_selector, + multilang_menu_selector, + multilang_forms_selector; //selector of the forms to be processed (string) +multilang_css_link = {"cursor":"pointer","margin":"2px 5px","float":"left"}; +$.extend(multilang_css_cur_link,multilang_css_link,{fontWeight:"bold"}); + +/* options is a hash having the following values: + * - fields (mandatory): a jQuery selector to set the fields that have to be internationalized. + * - page (optional): a string to be searched in the current url. if found the plugin is applied. + * - root (optional): the root element of all processing. Default value is 'document'. To speed up search + * - forms (optional): a jQuery selector to set the forms that have to be internationalized. Default value is 'form'. + * - main_menu (optional): a jQuery selector to set the container for the main menu to control all the selected forms. + * - form_menu (optional): a jQuery selector to set the container for the form menus. + */ +function multilang_init_lang(options) { + //Detect if we're on the right page and if multilinguism is activated. If not return. + if((options.page && window.location.search.indexOf(options.page)==-1) || multilang_avail_langs.length<=1) return; + //set the root element of all processing + var root = options.root || document; + multilang_root = $(root); + //set the main menu element + multilang_containers = options.main_menu ? $(options.main_menu,multilang_root) : $([]); + //create menu lang template + multilang_menu_lang =$("