Ignore:
Timestamp:
11/09/09 08:39:07 (10 years ago)
Author:
gogo
Message:

Ticket #1189

Add the xml:lang attribute to LangMarks? plugin.

The configuration for this plugin has changed, old configurations are accepted with a warning to the console.

By default BOTH lang="" and xml:lang="" are emitted for compatability, simply remove one or the other from the LangMarks?.attributes array.

Xinha.Config.prototype.LangMarks = {
  'languages': [
    { name:"Greek",   code: "el" } ,
    { name:"English", code: "en" },
    { name:"French",  code: "fr" } ,
    { name:"Latin" ,  code: "la" }  
  ],
  
  'attributes': [
    'lang',
    'xml:lang'    
  ],
};
Location:
trunk/plugins/LangMarks
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/plugins/LangMarks/LangMarks.js

    r1067 r1215  
    1212  var options = {}; 
    1313  options[this._lc("— language —")] = ''; 
    14         for (var i in cfg.LangMarks) 
    15         { 
    16                 if (typeof i != 'string') continue; 
    17                 options[this._lc(i)] = cfg.LangMarks[i]; 
     14   
     15  // Old configuration type 
     16  if(!cfg.LangMarks.languages) 
     17  { 
     18    Xinha.debugMsg('Warning: Old style LangMarks configuration detected, please update your LangMarks configuration.'); 
     19    var newConfig = { 
     20      languages:  [], 
     21      attributes: Xinha.Config.prototype.attributes       
     22    }; 
     23     
     24    for (var i in cfg.LangMarks) 
     25    { 
     26      if (typeof i != 'string') continue; 
     27      newConfig.languages.push( { name: i, code: cfg.LangMarks[i] } );       
     28    } 
     29     
     30    cfg.LangMarks = newConfig; 
     31  } 
     32   
     33        for (var i = 0; i < cfg.LangMarks.languages.length; i++) 
     34        {                
     35                options[this._lc(cfg.LangMarks.languages[i].name)] = cfg.LangMarks.languages[i].code; 
    1836        } 
     37   
    1938 
    2039  cfg.registerDropdown({ 
     
    4059 
    4160Xinha.Config.prototype.LangMarks = { 
    42   "Greek" : "el", 
    43   "English" : "en", 
    44   "French" : "fr", 
    45   "Latin" : "la" 
     61  'languages': [ 
     62    { name:"Greek",   code: "el" } , 
     63    { name:"English", code: "en" }, 
     64    { name:"French",  code: "fr" } , 
     65    { name:"Latin" ,  code: "la" }   
     66  ], 
     67   
     68  'attributes': [ 
     69    'lang', 
     70    'xml:lang'     
     71  ], 
    4672}; 
    4773 
     
    6894  if (update_parent) { 
    6995    parent.className = "haslang"; 
    70     parent.lang = language; 
     96    parent.lang = language;     
     97     
     98    for(var i = 0; i < this.editor.config.LangMarks.attributes.length; i++) 
     99    { 
     100      parent.setAttribute(this.editor.config.LangMarks.attributes[i], language); 
     101    } 
     102     
    71103    editor.updateToolbar(); 
    72104    return; 
     
    87119      parent.className = "haslang"; 
    88120      parent.lang = language; 
     121       
     122      for(var i = 0; i < this.editor.config.LangMarks.attributes.length; i++) 
     123      { 
     124        parent.setAttribute(this.editor.config.LangMarks.attributes[i], language); 
     125      } 
     126             
    89127      surround = false; 
    90128      // in this case we should handle the toolbar updation 
     
    100138    // it's dangerous when selection spans multiple block-level 
    101139    // elements. 
    102     editor.surroundHTML('<span lang="' + language + '" class="haslang">', '</span>'); 
     140    var html = ''; 
     141    for(var i = 0; i < this.editor.config.LangMarks.attributes.length; i++) 
     142    { 
     143      html += ' ' +this.editor.config.LangMarks.attributes[i] + '="'+language+'"'; 
     144    } 
     145     
     146    editor.surroundHTML('<span'+html+' class="haslang">', '</span>'); 
    103147  } 
    104148}; 
     
    108152  var parents = editor.getAllAncestors(); 
    109153  var parent; 
     154  var lang; 
    110155        for (var i=0;i<parents.length;i++) 
    111156        { 
    112                 if (parents[i].lang) parent = parents[i]; 
     157    for(var j = 0; j < editor.config.LangMarks.attributes.length; j++) 
     158    {       
     159      if(parents[i].getAttribute(this.editor.config.LangMarks.attributes[j])) 
     160      { 
     161         parent = parents[i];       
     162         lang = parents[i].getAttribute(this.editor.config.LangMarks.attributes[j]);                 
     163      } 
     164    }            
    113165        } 
    114166        if (parent) { 
    115167    var options = select.options; 
    116     var value = parent.lang; 
     168    var value = lang; 
    117169    for (var i = options.length; --i >= 0;) { 
    118170      var option = options[i]; 
  • trunk/plugins/LangMarks/lang-marks.css

    r995 r1215  
    33        white-space : nowrap; 
    44} 
     5 
     6 
     7 
    58span[lang]::after { 
    69        content: attr(lang); 
     
    1417        vertical-align: top; 
    1518} 
     19 
     20/* 
     21 * NOTE: The "proper" way to do this is with a CSS namespace 
     22 * @namespace xml "http://www.w3.org/XML/1998/namespace"; 
     23 * and putting xmlns:xml="http://www.w3.org/XML/1998/namespace" 
     24 * on the root <html> element or the <span> itself, then using  
     25 * span[xml|lang] as the selector, but this simply doesn't work  
     26 * in most browsers.  Which sucks. 
     27 */ 
     28 
     29span[xml\:lang]::after { 
     30  content: attr(xml\:lang); 
     31  text-transform: uppercase; 
     32  font-family: sans-serif; 
     33  color: white; 
     34  background: red; 
     35  border: 1px solid red; 
     36  font-size: x-small; 
     37  font-weight: normal; 
     38  vertical-align: top; 
     39} 
     40 
Note: See TracChangeset for help on using the changeset viewer.