function createButton(txt)
  {
    // the element that will be created
    var el, btn, obj = null;
    switch (txt)
    {
      case "separator":
        if ( editor.config.flowToolbars )
        {
          newLine();
        }
        el = document.createElement("div");
        el.className = "separator";
      break;
      case "space":
        el = document.createElement("div");
        el.className = "space";
      break;
      case "linebreak":
        newLine();
        return false;
      case "textindicator":
        el = document.createElement("div");
        el.appendChild(document.createTextNode("A"));
        el.className = "indicator";
        el.title = Xinha._lc("Current style");
        obj =
        {
          name	: txt, // the button name (i.e. 'bold')
          element : el, // the UI element (DIV)
          enabled : true, // is it enabled?
          active	: false, // is it pressed?
          text	: false, // enabled in text mode?
          cmd	: "textindicator", // the command ID
          state	: setButtonStatus // for changing state
        };
      
        Xinha.freeLater(obj);
      
        tb_objects[txt] = obj;
      break;
      default:
        btn = editor.config.btnList[txt];
    }
    if ( !el && btn )
    {
      el = document.createElement("a");
      el.style.display = 'block';
      el.href = 'javascript:void(0)';
      el.style.textDecoration = 'none';
      el.title = btn[0];
      el.className = "button";
      el.style.direction = "ltr";
      // let's just pretend we have a button object, and
      // assign all the needed information to it.
      obj =
      {
        name : txt, // the button name (i.e. 'bold')
        element : el, // the UI element (DIV)
        enabled : true, // is it enabled?
        active : false, // is it pressed?
        text : btn[2], // enabled in text mode?
        cmd	: btn[3], // the command ID
        state	: setButtonStatus, // for changing state
        context : btn[4] || null // enabled in a certain context?
      };
      Xinha.freeLater(el);
      Xinha.freeLater(obj);

      tb_objects[txt] = obj;

      // prevent drag&drop of the icon to content area
      el.ondrag = function() { return false; };

      // handlers to emulate nice flat toolbar buttons
      Xinha._addEvent(
        el,
        "mouseout",
        function(ev)
        {
          if ( obj.enabled )
          {
            //Xinha._removeClass(el, "buttonHover");
            Xinha._removeClass(el, "buttonActive");
            if ( obj.active )
            {
              Xinha._addClass(el, "buttonPressed");
            }
          }
        }
      );

      Xinha._addEvent(
        el,
        "mousedown",
        function(ev)
        {
          if ( obj.enabled )
          {
            Xinha._addClass(el, "buttonActive");
            Xinha._removeClass(el, "buttonPressed");
            Xinha._stopEvent(Xinha.is_ie ? window.event : ev);
          }
        }
      );

      // when clicked, do the following:
      Xinha._addEvent(
        el,
        "click",
        function(ev)
        {
          ev = ev || window.event;
          editor.btnClickEvent = {clientX : ev.clientX, clientY : ev.clientY};
          if ( obj.enabled )
          {
            Xinha._removeClass(el, "buttonActive");
            //Xinha._removeClass(el, "buttonHover");
            if ( Xinha.is_gecko )
            {
              editor.activateEditor();
            }
            obj.cmd(editor, obj.name, obj);
            Xinha._stopEvent(ev);
          }
        }
      );

      var i_contain = Xinha.makeBtnImg(btn[1]);
      var img = i_contain.firstChild;
      Xinha.freeLater(i_contain);
      Xinha.freeLater(img);
      
      el.appendChild(i_contain);

      obj.imgel = img;      
      obj.swapImage = function(newimg)
      {
        if ( typeof newimg != 'string' )
        {
          img.src = newimg[0];
          img.style.position = 'relative';
          img.style.top  = newimg[2] ? ('-' + (18 * (newimg[2] + 1)) + 'px') : '-18px';
          img.style.left = newimg[1] ? ('-' + (18 * (newimg[1] + 1)) + 'px') : '-18px';
        }
        else
        {
          obj.imgel.src = newimg;
          img.style.top = '0px';
          img.style.left = '0px';
        }
      };
      
    }
    else if( !el )
    {
      el = createSelect(txt);
    }

    return el;
  }
// appends a new button to toolbar
appends a new button to toolbar
appends a new button to toolbar
function createButton(txt)
  {
    var el, btn, obj = null;
    switch (txt)
    {
      case "separator":
        if ( editor.config.flowToolbars )
        {
          newLine();
        }
        el = document.createElement("div");
        el.className = "separator";
      break;
      case "space":
        el = document.createElement("div");
        el.className = "space";
      break;
      case "linebreak":
        newLine();
        return false;
      case "textindicator":
        el = document.createElement("div");
        el.appendChild(document.createTextNode("A"));
        el.className = "indicator";
        el.title = Xinha._lc("Current style");
        obj =
        {
          name	: txt, 
          element : el, 
          enabled : true, 
          active	: false, 
          text	: false, 
          cmd	: "textindicator", 
          state	: setButtonStatus 
        };
        Xinha.freeLater(obj);
        tb_objects[txt] = obj;
      break;
      default:
        btn = editor.config.btnList[txt];
    }
    if ( !el && btn )
    {
      el = document.createElement("a");
      el.style.display = 'block';
      el.href = 'javascript:void(0)';
      el.style.textDecoration = 'none';
      el.title = btn[0];
      el.className = "button";
      el.style.direction = "ltr";
      obj =
      {
        name : txt, 
        element : el, 
        enabled : true, 
        active : false, 
        text : btn[2], 
        cmd	: btn[3], 
        state	: setButtonStatus, 
        context : btn[4] || null 
      };
      Xinha.freeLater(el);
      Xinha.freeLater(obj);
      tb_objects[txt] = obj;
      el.ondrag = function() { return false; };
      Xinha._addEvent(
        el,
        "mouseout",
        function(ev)
        {
          if ( obj.enabled )
          {
            Xinha._removeClass(el, "buttonActive");
            if ( obj.active )
            {
              Xinha._addClass(el, "buttonPressed");
            }
          }
        }
      );
      Xinha._addEvent(
        el,
        "mousedown",
        function(ev)
        {
          if ( obj.enabled )
          {
            Xinha._addClass(el, "buttonActive");
            Xinha._removeClass(el, "buttonPressed");
            Xinha._stopEvent(Xinha.is_ie ? window.event : ev);
          }
        }
      );
      Xinha._addEvent(
        el,
        "click",
        function(ev)
        {
          ev = ev || window.event;
          editor.btnClickEvent = {clientX : ev.clientX, clientY : ev.clientY};
          if ( obj.enabled )
          {
            Xinha._removeClass(el, "buttonActive");
            if ( Xinha.is_gecko )
            {
              editor.activateEditor();
            }
            obj.cmd(editor, obj.name, obj);
            Xinha._stopEvent(ev);
          }
        }
      );
      var i_contain = Xinha.makeBtnImg(btn[1]);
      var img = i_contain.firstChild;
      Xinha.freeLater(i_contain);
      Xinha.freeLater(img);
      el.appendChild(i_contain);
      obj.imgel = img;      
      obj.swapImage = function(newimg)
      {
        if ( typeof newimg != 'string' )
        {
          img.src = newimg[0];
          img.style.position = 'relative';
          img.style.top  = newimg[2] ? ('-' + (18 * (newimg[2] + 1)) + 'px') : '-18px';
          img.style.left = newimg[1] ? ('-' + (18 * (newimg[1] + 1)) + 'px') : '-18px';
        }
        else
        {
          obj.imgel.src = newimg;
          img.style.top = '0px';
          img.style.left = '0px';
        }
      };
    }
    else if( !el )
    {
      el = createSelect(txt);
    }
    return el;
  }
function createButton ( txt ) { var el , btn , obj = null ; switch ( txt ) { case "separator" : if ( editor . config . flowToolbars ) { newLine ( ) ; } el = document . createElement ( "div" ) ; el . className = "separator" ; break ; case "space" : el = document . createElement ( "div" ) ; el . className = "space" ; break ; case "linebreak" : newLine ( ) ; return false ; case "textindicator" : el = document . createElement ( "div" ) ; el . appendChild ( document . createTextNode ( "A" ) ) ; el . className = "indicator" ; el . title = Xinha . _lc ( "Current style" ) ; obj = { name : txt , element : el , enabled : true , active : false , text : false , cmd : "textindicator" , state : setButtonStatus } ; Xinha . freeLater ( obj ) ; tb_objects [ txt ] = obj ; break ; default : btn = editor . config . btnList [ txt ] ; } if ( ! el && btn ) { el = document . createElement ( "a" ) ; el . style . display = 'block' ; el . href = 'javascript:void(0)' ; el . style . textDecoration = 'none' ; el . title = btn [ 0 ] ; el . className = "button" ; el . style . direction = "ltr" ; obj = { name : txt , element : el , enabled : true , active : false , text : btn [ 2 ] , cmd : btn [ 3 ] , state : setButtonStatus , context : btn [ 4 ] || null } ; Xinha . freeLater ( el ) ; Xinha . freeLater ( obj ) ; tb_objects [ txt ] = obj ; el . ondrag = function ( ) { return false ; } ; Xinha . _addEvent ( el , "mouseout" , function ( ev ) { if ( obj . enabled ) { Xinha . _removeClass ( el , "buttonActive" ) ; if ( obj . active ) { Xinha . _addClass ( el , "buttonPressed" ) ; } } } ) ; Xinha . _addEvent ( el , "mousedown" , function ( ev ) { if ( obj . enabled ) { Xinha . _addClass ( el , "buttonActive" ) ; Xinha . _removeClass ( el , "buttonPressed" ) ; Xinha . _stopEvent ( Xinha . is_ie ? window . event : ev ) ; } } ) ; Xinha . _addEvent ( el , "click" , function ( ev ) { ev = ev || window . event ; editor . btnClickEvent = { clientX : ev . clientX , clientY : ev . clientY } ; if ( obj . enabled ) { Xinha . _removeClass ( el , "buttonActive" ) ; if ( Xinha . is_gecko ) { editor . activateEditor ( ) ; } obj . cmd ( editor , obj . name , obj ) ; Xinha . _stopEvent ( ev ) ; } } ) ; var i_contain = Xinha . makeBtnImg ( btn [ 1 ] ) ; var img = i_contain . firstChild ; Xinha . freeLater ( i_contain ) ; Xinha . freeLater ( img ) ; el . appendChild ( i_contain ) ; obj . imgel = img ; obj . swapImage = function ( newimg ) { if ( typeof newimg != 'string' ) { img . src = newimg [ 0 ] ; img . style . position = 'relative' ; img . style . top = newimg [ 2 ] ? ( '-' + ( 18 * ( newimg [ 2 ] + 1 ) ) + 'px' ) : '-18px' ; img . style . left = newimg [ 1 ] ? ( '-' + ( 18 * ( newimg [ 1 ] + 1 ) ) + 'px' ) : '-18px' ; } else { obj . imgel . src = newimg ; img . style . top = '0px' ; img . style . left = '0px' ; } } ; } else if ( ! el ) { el = createSelect ( txt ) ; } return el ; }
appends a new button to toolbar
appends a new button to toolbar
// the element that will be created // the button name (i.e. 'bold') // the UI element (DIV) // is it enabled? // is it pressed? // enabled in text mode? // the command ID // for changing state // let's just pretend we have a button object, and // assign all the needed information to it. // the button name (i.e. 'bold') // the UI element (DIV) // is it enabled? // is it pressed? // enabled in text mode? // the command ID // for changing state // enabled in a certain context? // prevent drag&drop of the icon to content area // handlers to emulate nice flat toolbar buttons //Xinha._removeClass(el, "buttonHover"); // when clicked, do the following: //Xinha._removeClass(el, "buttonHover");