[ Index ]
 

Code source de LifeType 1.2.4

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/js/editor/ -> lifetypeeditor.js (source)

   1  /**

   2   * LifetypeEditor.js

   3   *

   4   * Non-wysiwyg javascript-based editor for textarea controls in browsers. It works in

   5   * exactly the same as HTMLArea control but instead of graphically showing the contents

   6   * of the post, works based on raw html code. It does not offer as many features as

   7   * htmlarea but it does offer some other things as customizable toolbars, support

   8   * for text selections and ranges, etc. It should work in every major browser with

   9   * some support for DOM and DHTML.

  10   *

  11   * This code is licensed under the terms of the GPL license.

  12   *

  13   * -- Installation and usage --

  14   *

  15   * Place this file somewhere in your web server tree and from your html files, call it like

  16   * <html>

  17   *  <head>

  18   *   <link rel="stylesheet" href="plogeditor.css" type="text/css">

  19   *   <script type="text/javascript" src="lifetypeeditor.js"></script>

  20   *  </head>

  21   *  <body>

  22   *   <h1>Lifetype Javascript Sample</h1>

  23   *   <form name="textEditor" id="textEditor">

  24   *    text1:<br/>

  25   *    <script type="text/javascript">ed1 = new Lifetype.UI.Editor('text1', 'ed1');</script>

  26   *    <textarea id="text1" name="text1" rows="8" cols="60"></textarea>

  27   *    <br/>text2:<br/>

  28   *    <script type="text/javascript">ed2 = new Lifetype.UI.Editor('text2', 'ed2');</script>

  29   *    <textarea id="text2" name="text1" rows="8" cols="60"></textarea>

  30   *   </form>

  31   *  </body>

  32   * </html>

  33   *

  34   * Create a new pLogEditor object in the place where you would like to show the 

  35   * toolbar of the editor. The first paramter for the constructor is the value of the 'id'

  36   * attribute of the textarea that will be the content area for the toolbar. The second parameter

  37   * is the name of the object itself, so if you are creating an editor called 'myEditor', the second

  38   * parameter will be 'myEditor.

  39   */
  40   
  41  /**

  42   * main class

  43   *

  44   */
  45  Lifetype.UI.Editor = function(txtId, objName) 
  46  {
  47  
  48    // class attributes    

  49    this.txtId = txtId;
  50    this.objName = objName;
  51    
  52    // array with all the open tags that haven't been closed

  53    this.tagStack = new Array();
  54    
  55    this.debug = false;
  56  
  57    this.setToolbar = function()
  58    {
  59        // --

  60        // our very own toolbar

  61        // --

  62        this.toolBar = new Array();
  63        options = new Array();
  64        options['8'] = '8 pt';
  65        options['10'] = '10 pt';
  66        options['12'] = '12 pt';
  67        options['14'] = '14 pt';
  68        options['18'] = '18 pt';
  69        options['24'] = '24 pt';  
  70        options['36'] = '36 pt';
  71        this.toolBar['list_font_size'] = new Lifetype.UI.Editor.List.FontSize( 'list_font_size', options );
  72        this.toolBar['1_but_b']  = new Lifetype.UI.Editor.Button( '1_but_b', 'bold', '<strong>', '</strong>', 'ed_format_bold.gif', 1 );
  73        this.toolBar['2_but_i']  = new Lifetype.UI.Editor.Button( '2_but_i', 'italics', '<em>', '</em>', 'ed_format_italic.gif', 1 );
  74        this.toolBar['3_but_u']  = new Lifetype.UI.Editor.Button( '3_but_u', 'underline', '<span style="text-decoration:underline">', '</span>', 'ed_format_underline.gif', 1 );
  75        this.toolBar['4_but_strikethrough'] = new Lifetype.UI.Editor.Button( '4_but_strikethrough', 'strikethrough', '<span style="text-decoration: line-through;">', '</span>', 'ed_format_strike.gif', 1 );
  76        this.toolBar['but_sep1'] =  new Lifetype.UI.Editor.Button.Separator();
  77        this.toolBar['but_align_left'] = new Lifetype.UI.Editor.Button( 'but_align_left', 'align left', '<div style="text-align: left;">', '</div>', 'ed_align_left.gif' );
  78        this.toolBar['but_align_center'] = new Lifetype.UI.Editor.Button( 'but_align_center', 'align center', '<div style="text-align: center;">', '</div>', 'ed_align_center.gif' );
  79        this.toolBar['but_align_right'] = new Lifetype.UI.Editor.Button( 'but_align_right', 'align right', '<div style="text-align: right;">', '</div>', 'ed_align_right.gif' );
  80        this.toolBar['but_align_justify'] = new Lifetype.UI.Editor.Button( 'but_align_justify', 'align justify', '<div style="text-align: justify;">', '</div>', 'ed_align_justify.gif' );
  81        this.toolBar['but_sep2'] =  new Lifetype.UI.Editor.Button.Separator();
  82        this.toolBar['but_ordered_list'] = new Lifetype.UI.Editor.Button( 'but_ordered_list', 'ordered list', '<ol><li></li></ol>', '', 'ed_list_num.gif', -1 );
  83        this.toolBar['but_unordered_list'] = new Lifetype.UI.Editor.Button( 'but_unordered_list', 'unordered list', '<ul><li></li></ul>', '', 'ed_list_bullet.gif', -1 );  
  84        this.toolBar['5_but_a']  = new Lifetype.UI.Editor.Button.Link( '5_but_a', 'anchor', 'ed_link.gif' );
  85        this.toolBar['6_but_img']= new Lifetype.UI.Editor.Button.Image( '6_but_img', 'image', 'ed_image.gif' );
  86        this.toolBar['7_but_res']= new Lifetype.UI.Editor.Button.Resource ('7_but_res', 'resource', 'ed_resource.gif' );
  87        this.toolBar['8_but_more']= new Lifetype.UI.Editor.Button.More ('8_but_more', 'more', 'ed_more.gif' );  
  88    }
  89    
  90    /**

  91     * returns whether our browser supports the features that we are going

  92     * to use or not

  93     *

  94     * @return true if supported, false if not

  95     */
  96    this.isSupportedBrowser = function()
  97    {
  98       return( document.getElementById || document.all );
  99    }
 100  
 101    /**

 102     * draws the buttons. Takes no parameters

 103     *

 104     * @return nothing

 105     */
 106    this.init = function() 
 107    {
 108        // generate the toolbar

 109        this.setToolbar();
 110      
 111        // load the editor stylesheet dynamically

 112        link = document.createElement( "link" );
 113        link.rel  = "stylesheet";
 114        link.type = "text/css";
 115        link.href = Lifetype.getBaseURL() + "/js/editor/lifetypeeditor.css";
 116        head = document.getElementsByTagName('head').item( 0 );
 117        head.appendChild( link );
 118        
 119        // first of all, check for unsupported browsers. If the browser

 120        // is not supported, we will silently not do anything... since we won't

 121        // even print the toolbar! (and nothing will happen without a toolbar)

 122        if( !this.isSupportedBrowser())
 123            return;
 124          
 125        markup = '';
 126        
 127        document.write('<div class="textEditorToolbar" id="textEditorToolbar">');
 128        for( var buttonId in this.toolBar ) {
 129            if ( Lifetype.prototypeCompatibabilityCheck( buttonId ) )
 130                continue;
 131            button = this.toolBar[buttonId];
 132            markup += button.show(this.txtId, this.objName);
 133        }
 134        document.write(markup);
 135        document.write('</div>');
 136        
 137        if( this.debug ) {
 138          document.write('<textarea>'+markup+'</textarea>');
 139        }
 140    }
 141    
 142    // after initializing the buttons, we can generate the toolbar

 143    // we can't call this method after defining it!! :)

 144    this.init();    
 145    
 146    /**

 147     * calls the edButton.execute() callback

 148     *

 149     * @param txtId

 150     * @param buttonId

 151     * @return nothing

 152     */
 153    this.execute = function( txtId, buttonId, param )
 154    {
 155        // get the button from the array

 156        var edButton = this.toolBar[buttonId];
 157        
 158        // execute the button

 159        if( !this.selectionExists()) {
 160            result = edButton.execute( txtId, param );
 161          if( result != 'undefined' )
 162              this.insertText( result );
 163          }
 164          else {
 165             surroundInfo = edButton.surround( txtId, param ); 
 166           this.surroundText( surroundInfo['start'], surroundInfo['end'] );      
 167        }
 168    }
 169    
 170    /**

 171     * returns the textarea object associated to this editor

 172     *

 173     * @return a textarea object

 174     */
 175    this.getTextArea = function()
 176    {
 177        textArea = document.getElementById( this.txtId );
 178        return textArea;
 179    }
 180    
 181    /** 

 182     * calls the onMouseOver handler for this button

 183     *

 184     * @param txtId

 185     * @param buttonId

 186     */
 187    this.mouseOver = function( txtId, buttonId )
 188    {
 189        var edButton = this.toolBar[buttonId];
 190        edButton.mouseOver();
 191    }
 192    
 193    /**

 194     * calls the onMouseOut handler for this button

 195     *

 196     * @param txtId

 197     * @param buttonId

 198     */
 199    this.mouseOut = function( txtId, buttonId )
 200    {
 201        var edButton = this.toolBar[buttonId];
 202        edButton.mouseOut();      
 203    }
 204    
 205      /**

 206        * inserts text where the cursor is

 207        * 

 208        * @param myField

 209        * @param myValue

 210        * @return nothing

 211        */
 212      this.insertText = function(myValue) 
 213      {
 214          myField = this.getTextArea();
 215          
 216          //IE support

 217          if (document.selection) {
 218              myField.focus();
 219              sel = document.selection.createRange();
 220              sel.text = myValue;
 221              myField.focus();
 222          }
 223          //MOZILLA/NETSCAPE support

 224          else if (myField.selectionStart || myField.selectionStart == '0') {
 225              var startPos = myField.selectionStart;
 226              var endPos = myField.selectionEnd;
 227              myField.value = myField.value.substring(0, startPos)
 228                            + myValue 
 229                            + myField.value.substring(endPos, myField.value.length);
 230              myField.focus();
 231              myField.selectionStart = startPos + myValue.length;
 232              myField.selectionEnd = startPos + myValue.length;
 233          } else {
 234              myField.value += myValue;
 235              myField.focus();
 236          }
 237      }  
 238      
 239      /**

 240       * surrounds the current selection with the given opening and closing texts

 241       *

 242       * @param myValueOpen

 243       * @param myValueClose

 244       */
 245      this.surroundText = function( myValueOpen, myValueClose )
 246        {
 247          myField = this.getTextArea();
 248          if (document.selection) {
 249              myField.focus();
 250              sel = document.selection.createRange();
 251              sel.text = myValueOpen + sel.text + myValueClose;
 252              myField.focus();
 253          }
 254          else if (myField.selectionStart || myField.selectionStart == '0') {
 255              var startPos = myField.selectionStart;
 256              var endPos = myField.selectionEnd;
 257              var cursorPos = endPos;        
 258              myField.value = myField.value.substring(0, startPos)
 259                        + myValueOpen
 260                        + myField.value.substring(startPos, endPos)
 261                        + myValueClose
 262                        + myField.value.substring(endPos, myField.value.length);
 263              cursorPos += myValueOpen.length + myValueClose.length;        
 264              myField.selectionStart = cursorPos;
 265              myField.selectionEnd = cursorPos;
 266              myField.focus();        
 267          } 
 268          else {
 269              myField.value += myValueOpen;
 270              myField.focus();
 271          }      
 272        }
 273    
 274    /**

 275     * returns whether there is a user selection in the given editor

 276     *

 277     * @return True if there is a selection or false otherwise

 278     */
 279    this.selectionExists = function()
 280    {
 281      var selection = false;
 282      var myField = this.getTextArea();
 283        
 284      if (document.selection) {
 285          // for IE

 286          myField.focus();
 287          sel = document.selection.createRange();
 288          selection = (sel.text != '' );
 289          myField.focus();
 290      }
 291      else if (myField.selectionStart || myField.selectionStart == '0') {
 292          // for Mozilla

 293          selection = (myField.selectionEnd > myField.selectionStart)
 294      }
 295      else {
 296          // for everybody else...

 297          selection = false;
 298      }
 299  
 300      return selection;
 301    }
 302  }
 303  
 304  /**

 305   * represents a button from our toolbar

 306   *

 307   * @param id

 308   * @param display

 309   * @param tagStart

 310   * @param tagEnd

 311   * @param icon

 312   * @param open

 313   */
 314  Lifetype.UI.Editor.Button = function(id, display, tagStart, tagEnd, icon, open) 
 315  {
 316      this.id = id;                // used to name the toolbar button

 317      this.display = display;        // label on button

 318      this.tagStart = tagStart;     // open tag

 319      this.tagEnd = tagEnd;        // close tag

 320      this.open = open;            // set to -1 if tag does not need to be closed

 321      this.isOpen = false;
 322      this.icon = icon;
 323      this.htmlId = '';
 324      this.currentStatus = 'normalButton';
 325      
 326      /**

 327       * renders the button

 328       *

 329       * @param txtId

 330       * @return nothing

 331       */
 332      this.show = function(txtId, objName)
 333      {
 334          // a very simple document.write...

 335          this.htmlId = txtId + '_' + this.id;
 336          var buttonText = '<img src="' + Lifetype.getBaseURL() + "/js/editor/images"+'/'+this.icon+'" id="' + txtId + '_' + this.id + '" class="normalButton" onmouseout="'+objName+'.mouseOut(\'' + txtId + '\', \'' + this.id + '\');" onmouseover="'+objName+'.mouseOver(\'' + txtId + '\', \'' + this.id + '\');" onclick="'+objName+'.execute(\'' + txtId + '\', \'' + this.id + '\', null );" alt = "' + this.display + '" />';
 337          
 338          return(buttonText);
 339      }
 340          
 341      /**

 342       * returns the html element to which this button is associated

 343       *

 344       * @return an html element

 345       */
 346      this.getHtmlButton = function()
 347      {
 348          return document.getElementById( this.htmlId );    
 349      }
 350      
 351      /**

 352       * whether this button needs to be closed or not

 353       *

 354       * @return True whether it needs to be closed or false otherwise

 355       */
 356      this.needsClose = function()
 357      {
 358          return( this.open != -1 );
 359      }
 360      
 361      /**

 362       * handler for the onMouseOver event, changes the colour of the borders

 363       */
 364      this.mouseOver = function()
 365      {
 366          htmlButton = this.getHtmlButton();
 367          htmlButton.className = 'buttonHover';
 368      }
 369      
 370      /** 

 371       * handler for the onMouseOut event, returns the button to its original state

 372       */
 373      this.mouseOut = function()
 374      {
 375          htmlButton = htmlButton = this.getHtmlButton();        
 376          htmlButton.className = this.currentStatus;
 377      }
 378      
 379      /**

 380       * checks/unchecks the button

 381       */
 382      this.toggle = function()
 383      {
 384          htmlButton = this.getHtmlButton();
 385  
 386           // change its class and save it for later use...

 387           if( this.currentStatus == 'pressedButton' )
 388               this.currentStatus = 'normalButton';
 389           else
 390               this.currentStatus = 'pressedButton';
 391               
 392           htmlButton.className = this.currentStatus;
 393      }
 394      
 395      /**

 396       * performs the button's action

 397       *

 398       * @param txtId

 399       * @return nothing

 400       */
 401      this.execute = function( txtId, param )
 402      {
 403          var text = '';
 404          
 405          // check if the tag needs a closing tag

 406          if( this.open == -1 ) {
 407              // it doesnt...

 408              text = this.tagStart;
 409          }
 410          else {
 411              // it does...

 412              if( this.isOpen )
 413                  text = this.tagEnd;
 414              else
 415                  text = this.tagStart;
 416              
 417              // change the status of the button

 418              this.isOpen = !this.isOpen;            
 419          }
 420          
 421          // change the look of the button

 422          if( this.open != -1 ) {
 423              this.toggle();
 424          }
 425  
 426          // return the text to be added

 427          return text;
 428      }
 429  
 430      /**

 431       * special callback function that is executed when the main editor would like to 

 432       * surround the current selection in the browser

 433       *

 434       * @param txtId the textarea id

 435       */    
 436      this.surround = function( txtId, param )
 437      {
 438          surroundInfo = Array()
 439          surroundInfo['start'] = this.tagStart;
 440          surroundInfo['end'] = this.tagEnd;
 441          
 442          return surroundInfo;
 443      }
 444      
 445      this.toString = function()
 446      {
 447          objSignature = this.id + ' Button';
 448          return( objSignature );
 449      }
 450  }
 451  
 452  /**

 453   * visual separators for the toolbar are also implemented as buttons, but they do

 454   * do nothing and only show a vertical bar anyway with some margin on both sides...

 455   */ 
 456  Lifetype.UI.Editor.Button.Separator = function()
 457  {
 458      this.prototype = new Lifetype.UI.Editor.Button('separator', '', '', '', '', -1 );
 459      this.prototype.constructor = Lifetype.UI.Editor.Button;
 460      this.superclass = Lifetype.UI.Editor.Button;
 461      
 462      this.superclass('separator', '', '', '', '', -1 );
 463      
 464      /**

 465       * draws a vertical line

 466       */
 467      this.show = function( txtId, objName )
 468      {
 469          separatorCode = '<span class="separator"></span>';
 470          
 471          return( separatorCode );
 472      }
 473  }
 474  
 475  /**

 476   * special button that only adds a link

 477   *

 478   * @param id

 479   * @param display

 480   * @param icon

 481   */
 482  Lifetype.UI.Editor.Button.Link = function(id, display, icon) 
 483  {
 484      //

 485      // strange javascript thingies used for object inheritance...

 486      //

 487      this.prototype = new Lifetype.UI.Editor.Button(id, display, '', '', icon, -1 );
 488      this.prototype.constructor = Lifetype.UI.Editor.Button;
 489      this.superclass = Lifetype.UI.Editor.Button;
 490      
 491      this.superclass(id, display, '', '', icon, -1 );
 492  
 493      /**

 494       * function redefined from above so that users can type links

 495       *

 496       * @param txtId

 497       */
 498      this.execute = function( txtId, param )
 499      {        
 500          this.toggle();
 501          
 502          linkText = prompt('Enter the link text: ');
 503          if( linkText == null ) {
 504              this.toggle();
 505              return '';
 506          }
 507          
 508          linkDest = prompt('Enter the destination for the link:');
 509          if( linkDest == null ) {
 510              this.toggle();
 511              return '';
 512          }
 513  
 514          this.toggle();        
 515  
 516          // if everything went fine, add the link and return

 517          var linkTag = '<a href="' + linkDest + '">' + linkText + '</a>'; 
 518          return linkTag;
 519      }
 520      
 521      /**

 522       * special behaviour for this function... It will only ask for the link destination

 523       * and surround the current selection with the user's input

 524       *

 525       * @param txtId

 526       */
 527      this.surround = function( txtId, param )
 528      {
 529          surroundInfo = Array();
 530          surroundInfo['start'] = '';
 531          surroundInfo['end'] = '';        
 532          
 533          this.toggle();
 534          linkDest = prompt('Enter the destination for the link:');
 535          if( linkDest == null ) {
 536              this.toggle();
 537              return surroundInfo;
 538          }
 539          
 540          surroundInfo['start'] = '<a href="' + linkDest + '">';
 541          surroundInfo['end'] = '</a>';
 542          
 543          this.toggle();
 544          
 545          return surroundInfo;
 546      }
 547  }
 548  
 549  /**

 550   * special button that only adds a link

 551   *

 552   * @param id

 553   * @param display

 554   * @param icon

 555   */
 556  Lifetype.UI.Editor.Button.BR = function(id, display, icon) 
 557  {
 558      //

 559      // strange javascript thingies used for object inheritance...

 560      //

 561      this.prototype = new Lifetype.UI.Editor.Button(id, display, '', '', icon, -1 );
 562      this.prototype.constructor = Lifetype.UI.Editor.Button;
 563      this.superclass = Lifetype.UI.Editor.Button;
 564      
 565      this.superclass(id, display, '<br />', '', icon, -1 );
 566  
 567      /**

 568       * special behaviour for this function... It will only ask for the link destination

 569       * and surround the current selection with the user's input

 570       *

 571       * @param txtId

 572       */
 573      this.surround = function( txtId, param )
 574      {
 575          surroundInfo = Array();
 576          surroundInfo['start'] = '<p>';
 577          surroundInfo['end'] = '</p>';
 578          this.toggle();
 579          
 580          return surroundInfo;
 581      }
 582  }
 583  
 584  /**

 585   * special button that adds/removes the "[@more@]" separator

 586   *

 587   * @param id

 588   * @param display

 589   * @param icon

 590   */
 591  Lifetype.UI.Editor.Button.More = function(id, display, icon) 
 592  {
 593      //

 594      // strange javascript thingies used for object inheritance...

 595      //

 596      this.prototype = new Lifetype.UI.Editor.Button(id, display, '', '', icon, -1 );
 597      this.prototype.constructor = Lifetype.UI.Editor.Button;
 598      this.superclass = Lifetype.UI.Editor.Button;
 599      
 600      this.superclass(id, display, '', '', icon, -1 );
 601      
 602      /**

 603       * @private

 604       */
 605      this._getMoreTag = function()
 606      {
 607          return( "[@more@]" );
 608      }
 609      
 610      this.execute = function( txtId, param ) 
 611      {
 612          var txtArea = document.getElementById( txtId );
 613          var content = txtArea.value;
 614          var bFound = 0;
 615          var startPos = 0;
 616          var returnValue = '';
 617          
 618          // Parse all img tags and remove any 'more' tags

 619          while((startPos = content.indexOf(this._getMoreTag(), startPos)) != -1) {
 620             var contentAfter = content.substring(startPos + this._getMoreTag().length);
 621             content = content.substring(0, startPos) + contentAfter;
 622             startPos++;
 623             bFound = 1;
 624          }
 625          
 626          if(bFound ) {
 627              // the tag is already there and should be removed, we can use a regular expression

 628              // to easily remove it

 629              returnValue = '';
 630              txtArea.value = content;
 631           }
 632           else {
 633              // the tag is not there and can be safely added

 634              returnValue = '\n' + this._getMoreTag() + '\n'; 
 635          }
 636      
 637          return( returnValue );
 638      }
 639  }
 640  
 641  /**

 642   * special button that only adds an image

 643   *

 644   * @param id

 645   * @param display

 646   * @param icon

 647   */
 648  Lifetype.UI.Editor.Button.Image = function(id, display, icon) 
 649  {
 650      //

 651      // strange javascript thingies used for object inheritance...

 652      //

 653      this.prototype = new Lifetype.UI.Editor.Button(id, display, '', '', icon, -1 );
 654      this.prototype.constructor = Lifetype.UI.Editor.Button;
 655      this.superclass = Lifetype.UI.Editor.Button;
 656      
 657      this.superclass(id, display, '', '', icon, -1 );
 658  
 659      /**

 660       * reimplemented from edButton so that we can ask for an image url and a description

 661       *

 662       * @param txtId

 663       */
 664      this.execute = function( txtId, param )
 665      {
 666          textArea = document.getElementById(txtId);
 667          
 668          this.toggle();
 669          
 670          imgSrc = prompt('Enter the image source: ');
 671          if( imgSrc == null ) {
 672              this.toggle();
 673              return '';
 674          }
 675          
 676          imgAlt = prompt('Enter an image description:');
 677          if( imgAlt == null ) {
 678              this.toggle();
 679              return '';
 680          }
 681          
 682          this.toggle();
 683  
 684          // if everything went fine, add the link and return

 685          var imgTag = '<img src="' + imgSrc + '" alt="' + imgAlt + '" />';
 686          return imgTag;
 687      }
 688  }
 689  
 690  /**

 691   * special button that only adds an resource

 692   *

 693   * @param id

 694   * @param display

 695   * @param icon

 696   */
 697  Lifetype.UI.Editor.Button.Resource = function(id, display, icon)
 698  {
 699      //

 700      // strange javascript thingies used for object inheritance...

 701      //

 702      this.prototype = new Lifetype.UI.Editor.Button(id, display, '', '', icon, -1 );
 703      this.prototype.constructor = Lifetype.UI.Editor.Button;
 704      this.superclass = Lifetype.UI.Editor.Button;
 705      
 706      this.superclass(id, display, '', '', icon, -1 );
 707  
 708      /**

 709       * reimplemented from edButton so that we can ask for an image url and a description

 710       *

 711       * @param txtId

 712       */
 713      this.execute = function( txtId, param )
 714      {
 715          if ( txtId == 'postText' )
 716              resource_list_window(1);
 717          else
 718              resource_list_window(2);
 719          return '';
 720      }
 721  }
 722  
 723  /**

 724   * implements drop-down lists

 725   */
 726  Lifetype.UI.Editor.List = function( id, options )
 727  {
 728      //

 729      // strange javascript thingies used for object inheritance...

 730      //

 731      this.prototype = new Lifetype.UI.Editor.Button(id, '', '', '', '', -1 );
 732      this.prototype.constructor = Lifetype.UI.Editor.Button;
 733      this.superclass = Lifetype.UI.Editor.Button;
 734      
 735      this.options = options;
 736      
 737      this.superclass(id, '', '', '', '', -1 );
 738      
 739      /**

 740       * renders the button. In our case, creates a drop-down list with the available options

 741       *

 742       * @param txtId

 743       * @returns the markup that is going to be written to the document

 744       */
 745      this.show = function(txtId, objName)
 746      {
 747          selectBox = '<select class="editorDropDownList" name=\''+this.id+'\' onChange="'+objName+'.execute(\'' + txtId + '\', \'' + this.id + '\', this);">';
 748          for( var key in this.options ) {
 749              if ( Lifetype.prototypeCompatibabilityCheck( key ) )
 750                  continue;            
 751              selectBox += '<option value=\''+key+'\'>'+this.options[key]+'</option>';
 752          }
 753          selectBox += '</select>';
 754          
 755          return( selectBox );
 756      }
 757      
 758      /**

 759       * reimplement this method for lists that should behave in a particular way when an option

 760       * is selected

 761       */
 762      this.execute = function( txtId, param )
 763      {
 764          // param is the drop-down list that generated the event, so we can easily learn

 765          // more about what was selected by 

 766          opt = param.selectedIndex;
 767      
 768          return( param.options[opt].value );
 769      }
 770      
 771      /**

 772       * does nothing

 773       */
 774      this.surround = function( txtId, param )
 775      {
 776          surroundInfo = Array();
 777          return( surroundInfo );
 778      }
 779  
 780  }
 781  
 782  /**

 783   * button that shows a list with different font sizes

 784   */
 785  Lifetype.UI.Editor.List.FontSize = function( id, options )
 786  {
 787      //

 788      // strange javascript thingies used for object inheritance...

 789      //

 790      this.prototype = new Lifetype.UI.Editor.List(id, options );
 791      this.prototype.constructor = Lifetype.UI.Editor.List;
 792      this.superclass = Lifetype.UI.Editor.List;
 793      
 794      this.superclass(id, options );
 795      
 796      /**

 797       * returns the right <span style=...></span> markup

 798       */
 799      this.execute = function( txtId, param )
 800      {
 801          // param is the drop-down list that generated the event, so we can easily learn

 802          // more about what was selected in the dropdown list

 803          opt = param.selectedIndex;
 804          fontSizePt = param.options[opt].value;
 805          
 806          spanCode = '<span style="font-size: '+fontSizePt+'pt;"></span>';
 807      
 808          return( spanCode );
 809      }
 810      
 811      /**

 812       * surrouns the selected text with the right <span>...</span> tags

 813       */
 814      this.surround = function( txtId, param )
 815      {
 816          opt = param.selectedIndex;
 817          fontSizePt = param.options[opt].value;    
 818      
 819          surroundInfo = Array();
 820          surroundInfo['start'] = '<span style="font-size: '+fontSizePt+'pt;">';
 821          surroundInfo['end'] = '</span>';
 822          return( surroundInfo );
 823      }
 824  }


Généré le : Mon Nov 26 21:04:15 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics