[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/libraries/ckeditor/_source/plugins/pagebreak/ -> plugin.js (source)

   1  /*

   2  Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.

   3  For licensing, see LICENSE.html or http://ckeditor.com/license

   4  */
   5  
   6  /**

   7   * @file Horizontal Page Break

   8   */
   9  
  10  // Register a plugin named "pagebreak".

  11  CKEDITOR.plugins.add( 'pagebreak',
  12  {
  13      init : function( editor )
  14      {
  15          // Register the command.

  16          editor.addCommand( 'pagebreak', CKEDITOR.plugins.pagebreakCmd );
  17  
  18          // Register the toolbar button.

  19          editor.ui.addButton( 'PageBreak',
  20              {
  21                  label : editor.lang.pagebreak,
  22                  command : 'pagebreak'
  23              });
  24  
  25          // Add the style that renders our placeholder.

  26          editor.addCss(
  27              'img.cke_pagebreak' +
  28              '{' +
  29                  'background-image: url(' + CKEDITOR.getUrl( this.path + 'images/pagebreak.gif' ) + ');' +
  30                  'background-position: center center;' +
  31                  'background-repeat: no-repeat;' +
  32                  'clear: both;' +
  33                  'display: block;' +
  34                  'float: none;' +
  35                  'width:100% !important; _width:99.9% !important;' +
  36                  'border-top: #999999 1px dotted;' +
  37                  'border-bottom: #999999 1px dotted;' +
  38                  'height: 5px !important;' +
  39                  'page-break-after: always;' +
  40  
  41              '}' );
  42      },
  43  
  44      afterInit : function( editor )
  45      {
  46          // Register a filter to displaying placeholders after mode change.

  47  
  48          var dataProcessor = editor.dataProcessor,
  49              dataFilter = dataProcessor && dataProcessor.dataFilter;
  50  
  51          if ( dataFilter )
  52          {
  53              dataFilter.addRules(
  54                  {
  55                      elements :
  56                      {
  57                          div : function( element )
  58                          {
  59                              var attributes = element.attributes,
  60                                  style = attributes && attributes.style,
  61                                  child = style && element.children.length == 1 && element.children[ 0 ],
  62                                  childStyle = child && ( child.name == 'span' ) && child.attributes.style;
  63  
  64                              if ( childStyle && ( /page-break-after\s*:\s*always/i ).test( style ) && ( /display\s*:\s*none/i ).test( childStyle ) )
  65                                  return editor.createFakeParserElement( element, 'cke_pagebreak', 'div' );
  66                          }
  67                      }
  68                  });
  69          }
  70      },
  71  
  72      requires : [ 'fakeobjects' ]
  73  });
  74  
  75  CKEDITOR.plugins.pagebreakCmd =
  76  {
  77      exec : function( editor )
  78      {
  79          // Create the element that represents a print break.

  80          var breakObject = CKEDITOR.dom.element.createFromHtml( '<div style="page-break-after: always;"><span style="display: none;">&nbsp;</span></div>' );
  81  
  82          // Creates the fake image used for this element.

  83          breakObject = editor.createFakeElement( breakObject, 'cke_pagebreak', 'div' );
  84  
  85          var ranges = editor.getSelection().getRanges( true );
  86  
  87          editor.fire( 'saveSnapshot' );
  88  
  89          for ( var range, i = ranges.length - 1 ; i >= 0; i-- )
  90          {
  91              range = ranges[ i ];
  92  
  93              if ( i < ranges.length -1 )
  94                  breakObject = breakObject.clone( true );
  95  
  96              range.splitBlock( 'p' );
  97              range.insertNode( breakObject );
  98              if ( i == ranges.length - 1 )
  99              {
 100                  range.moveToPosition( breakObject, CKEDITOR.POSITION_AFTER_END );
 101                  range.select();
 102              }
 103  
 104              var previous = breakObject.getPrevious();
 105  
 106              if ( CKEDITOR.dtd[ previous.getName() ].div )
 107                  breakObject.move( previous );
 108          }
 109  
 110          editor.fire( 'saveSnapshot' );
 111      }
 112  };


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7