Changeset 7741 in spip-zone


Ignore:
Timestamp:
Dec 4, 2006, 11:03:40 AM (12 years ago)
Author:
fil@…
Message:

the init function now takes an options hash as only argument;
documentation;
multilanguage groups of keywords
(restitution post-crash du commit r7757)

Location:
_plugins_/_dev_/_ze_laboratoire_/multilang_mot_cles
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • _plugins_/_dev_/_ze_laboratoire_/multilang_mot_cles/multilang_mot_cles.php

    r7712 r7741  
    1515                "<script type='text/javascript'>\n".
    1616                "var multilang_def_lang='".$GLOBALS["spip_lang"]."';var multilang_avail_langs=[$active_langs];\n".
    17                 "$(function(){multilang_init_lang('exec=mots_edit','.cadre-formulaire','','','input[@name=\'titre\'],textarea')});\n".
     17                "$(function(){\n".
     18                "multilang_init_lang({'page':'exec=mots_edit','root':'.cadre-formulaire','fields':'input[@name=\'titre\'],textarea'});\n".
     19                "multilang_init_lang({'page':'exec=mots_type','root':'#page','form_menu':'div.cadre-formulaire:eq(0)','fields':'input[@name=\'change_type\'],textarea'});\n".
     20                "});\n".
    1821                "</script>\n";
    1922        }
  • _plugins_/_dev_/_ze_laboratoire_/multilang_mot_cles/multilang_mots.js

    r7712 r7741  
    1010var multilang_containers={},forms_fields={},multilang_forms,multilang_menu_lang;
    1111var match_multi = /(?:\[([a-z_]+)\]|^[\s\n]*)((?:.|\n)*?)(?=\[[a-z_]+\]|$)/ig;
    12 var multilang_css_link,multilang_css_cur_link={},multilang_root,multilang_fields_selector;
     12var multilang_css_link,multilang_css_cur_link={},multilang_root,multilang_fields_selector,multilang_menu_selector;
    1313multilang_css_link = {"cursor":"pointer","margin":"2px 5px","float":"left"};
    1414$.extend(multilang_css_cur_link,multilang_css_link);
    1515$.extend(multilang_css_cur_link,{fontWeight:"bold"});
    1616
    17 function multilang_init_lang(page,root,main_menu,forms,fields) {
     17/* options is a hash having the following values:
     18 * - page (mandatory): a string to be searched in the current url. if found the plugin is applied.
     19 * - fields (mandatory): a jQuery selector to set the fields that have to be internationalized.
     20 * - root (optional): the root element of all processing. Default value is 'document'.
     21 * - forms (optional): a jQuery selector to set the forms that have to be  internationalized. Default value is 'form'.
     22 * - main_menu (optional): a jQuery selector to set the container for the main menu to control all the selected forms.
     23 * - form_menu (optional): a jQuery selector to set the container for the form menus.
     24 */     
     25function multilang_init_lang(options) {
    1826        //Detect if we're on the right page and if multilinguism is activated. If not return.
    19         if(window.location.search.indexOf("exec=mots_edit")==-1 || multilang_avail_langs.length<=1) return;
     27        if(window.location.search.indexOf(options.page)==-1 || multilang_avail_langs.length<=1) return;
    2028        //set the root element of all processing
    21         root = root || document;
     29        var root = options.root || document;
    2230        multilang_root = $(root);
    2331        //set the main menu element
    24         multilang_containers = main_menu ? $(main_menu,multilang_root) : $("empty");
     32        multilang_containers = options.main_menu ? $(options.main_menu,multilang_root) : $("empty");
    2533        //create menu lang template
    2634        multilang_menu_lang =$("<div>");
     
    2937        });
    3038        //store all the fields forms
    31         forms = forms || "form";
     39        var forms = options.forms || "form";
    3240        multilang_forms = $(forms,multilang_root).submit(forms_multi_submit);
    3341        //create menu lang for the global form
    3442        if(multilang_containers.size()) forms_make_menu_lang(multilang_containers);
    3543        //init fields
    36         multilang_fields_selector = fields;
    37         forms_init_multi({"forms_selector":forms,"fields_selector":fields});
     44        multilang_fields_selector = options.fields;
     45        multilang_menu_selector = options.form_menu;
     46        forms_init_multi({"forms_selector":forms,"fields_selector":multilang_fields_selector});
    3847}
    3948
     
    7584        var init_forms = target?$(forms,target):multilang_forms;
    7685        //init the value of the field to current lang
    77         //add a container for the language menu before the form
     86        //add a container for the language menu inside the form
    7887        init_forms.each(function() {
    7988                this.form_lang = multilang_def_lang;
    80                 $(this).before("<div>");
     89                var container = multilang_menu_selector ? $(multilang_menu_selector,this) : $(this);
     90                container.prepend("<div class='menu_lang'>");
    8191        });
    8292        $(multilang_fields_selector,init_forms).each(function(){
     
    8494        });
    8595        //create menu for each form. The menu is just before the form
    86         init_forms.prev().empty().each(function() {
     96        $("div.menu_lang",init_forms).empty().each(function() {
    8797                //store all form containers to allow menu lang update on each container
    8898                //when it is triggered by global menu
    8999                multilang_containers.add(this);
    90                 forms_make_menu_lang($(this),$(this).next());
    91         }).end();
     100                forms_make_menu_lang($(this),$(this).parents("form"));
     101        });
    92102}
    93103
     
    145155        multilang_forms.not(this);
    146156        //remove the current menu lang container from the list
    147         multilang_containers.not($(this).prev());
     157        multilang_containers.not("div.menu_lang",$(this));
    148158        //build the input values
    149159        $(multilang_fields_selector,this).each(function(){
Note: See TracChangeset for help on using the changeset viewer.