Announcement

Do not use the forums to submit bug reports, feature requests or patches, submit a New Ticket instead.

#1 2011-12-09 07:19:53

silentauben
New member
Registered: 2011-12-09
Posts: 1

using Class and Id in same time

Hi, i made some changes at XinhaCore.js (Xinha.makeEditors) to be able to use Id 'AND' Class.

I am not a pro at javascript so maybe the code isn't as good as it can be, but working.

Xinha.makeEditors = function(editor_names, default_config, plugin_names)
{    
    for(i in editor_names)
    {
        if(typeof editor_names[i] == 'string')
        {
                        /** testing if the editor_names is a class
                         *   if it is, i concat the list of objects to editor_names and nullify the value
                         *   if not the name is kept so can be tested later for id
                         */
            list = Xinha.getElementsByClassName(document, editor_names[i]);
            if(list.length > 0)
            {
                editor_names = editor_names.concat(list);
                editor_names[i] = null;
            }
        }
    }
    
  if (!Xinha.isSupportedBrowser) 
  {
    return;
  }
  
  if ( typeof default_config == 'function' )
  {
    default_config = default_config();
  }

  var editors = {};
  var textarea;
  
  for ( var x = 0; x < editor_names.length; x++ )
  {
         /** testing if the name is null
          *   it would be better to delete the line in the table ...
          */
    if( editor_names[x] != null )
    {        
        if ( typeof editor_names[x] == 'string' ) // the regular case, an id of a textarea
        {
          textarea = Xinha.getElementById('textarea', editor_names[x] );
          if (!textarea) // the id may be specified for a textarea that is maybe on another page; we simply skip it and go on
          {
            editor_names[x] = null;
            continue;
          }
        }
         // make it possible to pass a reference instead of an id, for example from  document.getElementsByTagName('textarea')
        else if ( typeof editor_names[x] == 'object' && editor_names[x].tagName && editor_names[x].tagName.toLowerCase() == 'textarea' )
        {
          textarea =  editor_names[x];
          if ( !textarea.id ) // we'd like to have the textarea have an id
          {
            textarea.id = 'xinha_id_' + x;
          } 
        }
        var editor = new Xinha(textarea, Xinha.cloneObject(default_config));
        editor.registerPlugins(plugin_names);
        editors[textarea.id] = editor;
    }
  }
  return editors;
};

i am using Xinha with Jquery tabs so i need the Id's to use with hidden textarea but didnt want to loose the benefits of class call.

thank you to X*, you shown me the direction with you post Use HTML class instead of id to fetch textareas (xinha_editors)

sorry for my english, i am french tongue

Last edited by silentauben (2011-12-09 08:24:49)

Offline

Board footer

Powered by FluxBB