Changeset 7858 in spip-zone


Ignore:
Timestamp:
Dec 10, 2006, 9:25:55 PM (12 years ago)
Author:
renato@…
Message:

multilang documents for articles

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

    r7741 r7858  
    1818                "multilang_init_lang({'page':'exec=mots_edit','root':'.cadre-formulaire','fields':'input[@name=\'titre\'],textarea'});\n".
    1919                "multilang_init_lang({'page':'exec=mots_type','root':'#page','form_menu':'div.cadre-formulaire:eq(0)','fields':'input[@name=\'change_type\'],textarea'});\n".
     20                "multilang_init_lang({'page':'exec=articles_edit','root':'#page','forms':'#liste_images form,#liste_documents form','fields':'input,textarea'});\n".
     21                "multilang_init_lang({'page':'exec=articles','root':'#portfolio,#documents','fields':'input,textarea'});\n".
     22                "onAjaxLoad(function(){forms_init_multi({'target':this})});\n".
    2023                "});\n".
    2124                "</script>\n";
  • _plugins_/_dev_/_ze_laboratoire_/multilang_mot_cles/multilang_mots.js

    r7741 r7858  
    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,multilang_menu_selector;
     12var multilang_css_link,multilang_css_cur_link={},multilang_root,multilang_fields_selector,multilang_menu_selector,multilang_forms_selector;
    1313multilang_css_link = {"cursor":"pointer","margin":"2px 5px","float":"left"};
    1414$.extend(multilang_css_cur_link,multilang_css_link);
     
    1818 * - page (mandatory): a string to be searched in the current url. if found the plugin is applied.
    1919 * - 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'.
     20 * - root (optional): the root element of all processing. Default value is 'document'. To speed up search
     21 * - forms (optional): a jQuery selector to set the forms that have to be internationalized. Default value is 'form'.
    2222 * - main_menu (optional): a jQuery selector to set the container for the main menu to control all the selected forms.
    2323 * - form_menu (optional): a jQuery selector to set the container for the form menus.
     
    3636                multilang_menu_lang.append($("<a>").html("["+this+"]").css(this==multilang_def_lang?multilang_css_cur_link:multilang_css_link)[0]);
    3737        });
    38         //store all the fields forms
    39         var forms = options.forms || "form";
    40         multilang_forms = $(forms,multilang_root).submit(forms_multi_submit);
     38        //store all the internationalized forms
     39        multilang_forms_selector = options.forms || "form";
     40        multilang_forms = $(multilang_forms_selector,multilang_root);
    4141        //create menu lang for the global form
    4242        if(multilang_containers.size()) forms_make_menu_lang(multilang_containers);
     
    4444        multilang_fields_selector = options.fields;
    4545        multilang_menu_selector = options.form_menu;
    46         forms_init_multi({"forms_selector":forms,"fields_selector":multilang_fields_selector});
     46        forms_init_multi();
    4747}
    4848
     
    7575
    7676function forms_init_multi(options) {
    77         var target = options.target;
    78         var forms = options.forms_selector;
     77        var target = options?options.target:null;
     78        var init_forms;
    7979        //Update the list of form if this is an update
    80         if(target) multilang_forms.add($(forms,target).get());
     80        if(target) {
     81                //Verify the target is really a form to be internationalized (in case of an ajax request fired by onAjaxLoad)
     82                init_forms = $(target).find('form');
     83                if(!init_forms.length || !in_set(init_forms,$(multilang_forms_selector,multilang_root))) return;
     84                multilang_forms.add(init_forms.each(forms_attach_submit).get());
     85        } else {
     86                //attach multi processing to submit event
     87                init_forms = multilang_forms;
     88                multilang_forms.each(forms_attach_submit);
     89        }
    8190        forms_fields = {};
    8291        forms_fields["undefined"] = $(multilang_fields_selector,multilang_forms);
    83         //store the fields of the target if any
    84         var init_forms = target?$(forms,target):multilang_forms;
    8592        //init the value of the field to current lang
    8693        //add a container for the language menu inside the form
     
    100107                forms_make_menu_lang($(this),$(this).parents("form"));
    101108        });
     109}
     110
     111function forms_attach_submit() {
     112        var oldsubmit = this.onsubmit;
     113        this.onsubmit = "";
     114        if(oldsubmit) $(this).submit(function(){forms_multi_submit.apply(this);return oldsubmit.apply(this);})
     115        else $(this).submit(forms_multi_submit);
    102116}
    103117
     
    179193        if(params) $.extend(params,$(form).formToArray(false));
    180194}
     195
     196function in_set(find,set) {
     197        var result = $.grep(set,function(i){
     198                var elements = find.get();
     199                var found = false;
     200                $.each(elements,function(){
     201                        if(this==i) found=true;
     202                })
     203                return found;
     204        });
     205        return result.length;
     206}
Note: See TracChangeset for help on using the changeset viewer.