namibia
df0489e1eeeeab5a9bd44e1d84fce49924fe1bac
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
/* Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ /** * @file Blockquote. */ (function() { function getState( editor, path ) { var firstBlock = path.block || path.blockLimit; if ( !firstBlock || firstBlock.getName() == 'body' ) return CKEDITOR.TRISTATE_OFF; // See if the first block has a blockquote parent. if ( firstBlock.getAscendant( 'blockquote', true ) ) return CKEDITOR.TRISTATE_ON; return CKEDITOR.TRISTATE_OFF; } function onSelectionChange( evt ) { var editor = evt.editor; if ( editor.readOnly ) return; var command = editor.getCommand( 'blockquote' ); command.state = getState( editor, evt.data.path ); command.fire( 'state' ); } function noBlockLeft( bqBlock ) { for ( var i = 0, length = bqBlock.getChildCount(), child ; i < length && ( child = bqBlock.getChild( i ) ) ; i++ ) { if ( child.type == CKEDITOR.NODE_ELEMENT && child.isBlockBoundary() ) return false; } return true; } var commandObject = { exec : function( editor ) { var state = editor.getCommand( 'blockquote' ).state, selection = editor.getSelection(), range = selection && selection.getRanges( true )[0]; if ( !range ) return; var bookmarks = selection.createBookmarks(); // Kludge for #1592: if the bookmark nodes are in the beginning of // blockquote, then move them to the nearest block element in the // blockquote. if ( CKEDITOR.env.ie ) { var bookmarkStart = bookmarks[0].startNode, bookmarkEnd = bookmarks[0].endNode, cursor; if ( bookmarkStart && bookmarkStart.getParent().getName() == 'blockquote' ) { cursor = bookmarkStart; while ( ( cursor = cursor.getNext() ) ) { if ( cursor.type == CKEDITOR.NODE_ELEMENT && cursor.isBlockBoundary() ) { bookmarkStart.move( cursor, true ); break; } } } if ( bookmarkEnd && bookmarkEnd.getParent().getName() == 'blockquote' ) { cursor = bookmarkEnd; while ( ( cursor = cursor.getPrevious() ) ) { if ( cursor.type == CKEDITOR.NODE_ELEMENT && cursor.isBlockBoundary() ) { bookmarkEnd.move( cursor ); break; } } } } var iterator = range.createIterator(), block; iterator.enlargeBr = editor.config.enterMode != CKEDITOR.ENTER_BR; if ( state == CKEDITOR.TRISTATE_OFF ) { var paragraphs = []; while ( ( block = iterator.getNextParagraph() ) ) paragraphs.push( block ); // If no paragraphs, create one from the current selection position. if ( paragraphs.length < 1 ) { var para = editor.document.createElement( editor.config.enterMode == CKEDITOR.ENTER_P ? 'p' : 'div' ), firstBookmark = bookmarks.shift(); range.insertNode( para ); para.append( new CKEDITOR.dom.text( '\ufeff', editor.document ) ); range.moveToBookmark( firstBookmark ); range.selectNodeContents( para ); range.collapse( true ); firstBookmark = range.createBookmark(); paragraphs.push( para ); bookmarks.unshift( firstBookmark ); } // Make sure all paragraphs have the same parent. var commonParent = paragraphs[0].getParent(), tmp = []; for ( var i = 0 ; i < paragraphs.length ; i++ ) { block = paragraphs[i]; commonParent = commonParent.getCommonAncestor( block.getParent() ); } // The common parent must not be the following tags: table, tbody, tr, ol, ul. var denyTags = { table : 1, tbody : 1, tr : 1, ol : 1, ul : 1 }; while ( denyTags[ commonParent.getName() ] ) commonParent = commonParent.getParent(); // Reconstruct the block list to be processed such that all resulting blocks // satisfy parentNode.equals( commonParent ). var lastBlock = null; while ( paragraphs.length > 0 ) { block = paragraphs.shift(); while ( !block.getParent().equals( commonParent ) ) block = block.getParent(); if ( !block.equals( lastBlock ) ) tmp.push( block ); lastBlock = block; } // If any of the selected blocks is a blockquote, remove it to prevent // nested blockquotes. while ( tmp.length > 0 ) { block = tmp.shift(); if ( block.getName() == 'blockquote' ) { var docFrag = new CKEDITOR.dom.documentFragment( editor.document ); while ( block.getFirst() ) { docFrag.append( block.getFirst().remove() ); paragraphs.push( docFrag.getLast() ); } docFrag.replace( block ); } else paragraphs.push( block ); } // Now we have all the blocks to be included in a new blockquote node. var bqBlock = editor.document.createElement( 'blockquote' ); bqBlock.insertBefore( paragraphs[0] ); while ( paragraphs.length > 0 ) { block = paragraphs.shift(); bqBlock.append( block ); } } else if ( state == CKEDITOR.TRISTATE_ON ) { var moveOutNodes = [], database = {}; while ( ( block = iterator.getNextParagraph() ) ) { var bqParent = null, bqChild = null; while ( block.getParent() ) { if ( block.getParent().getName() == 'blockquote' ) { bqParent = block.getParent(); bqChild = block; break; } block = block.getParent(); } // Remember the blocks that were recorded down in the moveOutNodes array // to prevent duplicates. if ( bqParent && bqChild && !bqChild.getCustomData( 'blockquote_moveout' ) ) { moveOutNodes.push( bqChild ); CKEDITOR.dom.element.setMarker( database, bqChild, 'blockquote_moveout', true ); } } CKEDITOR.dom.element.clearAllMarkers( database ); var movedNodes = [], processedBlockquoteBlocks = []; database = {}; while ( moveOutNodes.length > 0 ) { var node = moveOutNodes.shift(); bqBlock = node.getParent(); // If the node is located at the beginning or the end, just take it out // without splitting. Otherwise, split the blockquote node and move the // paragraph in between the two blockquote nodes. if ( !node.getPrevious() ) node.remove().insertBefore( bqBlock ); else if ( !node.getNext() ) node.remove().insertAfter( bqBlock ); else { node.breakParent( node.getParent() ); processedBlockquoteBlocks.push( node.getNext() ); } // Remember the blockquote node so we can clear it later (if it becomes empty). if ( !bqBlock.getCustomData( 'blockquote_processed' ) ) { processedBlockquoteBlocks.push( bqBlock ); CKEDITOR.dom.element.setMarker( database, bqBlock, 'blockquote_processed', true ); } movedNodes.push( node ); } CKEDITOR.dom.element.clearAllMarkers( database ); // Clear blockquote nodes that have become empty. for ( i = processedBlockquoteBlocks.length - 1 ; i >= 0 ; i-- ) { bqBlock = processedBlockquoteBlocks[i]; if ( noBlockLeft( bqBlock ) ) bqBlock.remove(); } if ( editor.config.enterMode == CKEDITOR.ENTER_BR ) { var firstTime = true; while ( movedNodes.length ) { node = movedNodes.shift(); if ( node.getName() == 'div' ) { docFrag = new CKEDITOR.dom.documentFragment( editor.document ); var needBeginBr = firstTime && node.getPrevious() && !( node.getPrevious().type == CKEDITOR.NODE_ELEMENT && node.getPrevious().isBlockBoundary() ); if ( needBeginBr ) docFrag.append( editor.document.createElement( 'br' ) ); var needEndBr = node.getNext() && !( node.getNext().type == CKEDITOR.NODE_ELEMENT && node.getNext().isBlockBoundary() ); while ( node.getFirst() ) node.getFirst().remove().appendTo( docFrag ); if ( needEndBr ) docFrag.append( editor.document.createElement( 'br' ) ); docFrag.replace( node ); firstTime = false; } } } } selection.selectBookmarks( bookmarks ); editor.focus(); } }; CKEDITOR.plugins.add( 'blockquote', { init : function( editor ) { editor.addCommand( 'blockquote', commandObject ); editor.ui.addButton( 'Blockquote', { label : editor.lang.blockquote, command : 'blockquote' } ); editor.on( 'selectionChange', onSelectionChange ); }, requires : [ 'domiterator' ] } ); })(); |
Commits for namibiapublic/scripts/ckeditor/_source/plugins/blockquote/plugin.js
Revision | Author | Commited | Message |
---|---|---|---|
df0489 ... | Mark | Fri 14 Oct, 2016 10:01:00 +0000 | initial commit |