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 |
/* Copyright (c) 2003-2011, CKSource - Frederico Knabben. All rights reserved. For licensing, see LICENSE.html or http://ckeditor.com/license */ (function() { CKEDITOR.htmlParser.filter = CKEDITOR.tools.createClass( { $ : function( rules ) { this._ = { elementNames : [], attributeNames : [], elements : { $length : 0 }, attributes : { $length : 0 } }; if ( rules ) this.addRules( rules, 10 ); }, proto : { addRules : function( rules, priority ) { if ( typeof priority != 'number' ) priority = 10; // Add the elementNames. addItemsToList( this._.elementNames, rules.elementNames, priority ); // Add the attributeNames. addItemsToList( this._.attributeNames, rules.attributeNames, priority ); // Add the elements. addNamedItems( this._.elements, rules.elements, priority ); // Add the attributes. addNamedItems( this._.attributes, rules.attributes, priority ); // Add the text. this._.text = transformNamedItem( this._.text, rules.text, priority ) || this._.text; // Add the comment. this._.comment = transformNamedItem( this._.comment, rules.comment, priority ) || this._.comment; // Add root fragment. this._.root = transformNamedItem( this._.root, rules.root, priority ) || this._.root; }, onElementName : function( name ) { return filterName( name, this._.elementNames ); }, onAttributeName : function( name ) { return filterName( name, this._.attributeNames ); }, onText : function( text ) { var textFilter = this._.text; return textFilter ? textFilter.filter( text ) : text; }, onComment : function( commentText, comment ) { var textFilter = this._.comment; return textFilter ? textFilter.filter( commentText, comment ) : commentText; }, onFragment : function( element ) { var rootFilter = this._.root; return rootFilter ? rootFilter.filter( element ) : element; }, onElement : function( element ) { // We must apply filters set to the specific element name as // well as those set to the generic $ name. So, add both to an // array and process them in a small loop. var filters = [ this._.elements[ '^' ], this._.elements[ element.name ], this._.elements.$ ], filter, ret; for ( var i = 0 ; i < 3 ; i++ ) { filter = filters[ i ]; if ( filter ) { ret = filter.filter( element, this ); if ( ret === false ) return null; if ( ret && ret != element ) return this.onNode( ret ); // The non-root element has been dismissed by one of the filters. if ( element.parent && !element.name ) break; } } return element; }, onNode : function( node ) { var type = node.type; return type == CKEDITOR.NODE_ELEMENT ? this.onElement( node ) : type == CKEDITOR.NODE_TEXT ? new CKEDITOR.htmlParser.text( this.onText( node.value ) ) : type == CKEDITOR.NODE_COMMENT ? new CKEDITOR.htmlParser.comment( this.onComment( node.value ) ): null; }, onAttribute : function( element, name, value ) { var filter = this._.attributes[ name ]; if ( filter ) { var ret = filter.filter( value, element, this ); if ( ret === false ) return false; if ( typeof ret != 'undefined' ) return ret; } return value; } } }); function filterName( name, filters ) { for ( var i = 0 ; name && i < filters.length ; i++ ) { var filter = filters[ i ]; name = name.replace( filter[ 0 ], filter[ 1 ] ); } return name; } function addItemsToList( list, items, priority ) { if ( typeof items == 'function' ) items = [ items ]; var i, j, listLength = list.length, itemsLength = items && items.length; if ( itemsLength ) { // Find the index to insert the items at. for ( i = 0 ; i < listLength && list[ i ].pri < priority ; i++ ) { /*jsl:pass*/ } // Add all new items to the list at the specific index. for ( j = itemsLength - 1 ; j >= 0 ; j-- ) { var item = items[ j ]; if ( item ) { item.pri = priority; list.splice( i, 0, item ); } } } } function addNamedItems( hashTable, items, priority ) { if ( items ) { for ( var name in items ) { var current = hashTable[ name ]; hashTable[ name ] = transformNamedItem( current, items[ name ], priority ); if ( !current ) hashTable.$length++; } } } function transformNamedItem( current, item, priority ) { if ( item ) { item.pri = priority; if ( current ) { // If the current item is not an Array, transform it. if ( !current.splice ) { if ( current.pri > priority ) current = [ item, current ]; else current = [ current, item ]; current.filter = callItems; } else addItemsToList( current, item, priority ); return current; } else { item.filter = item; return item; } } } // Invoke filters sequentially on the array, break the iteration // when it doesn't make sense to continue anymore. function callItems( currentEntry ) { var isNode = currentEntry.type || currentEntry instanceof CKEDITOR.htmlParser.fragment; for ( var i = 0 ; i < this.length ; i++ ) { // Backup the node info before filtering. if ( isNode ) { var orgType = currentEntry.type, orgName = currentEntry.name; } var item = this[ i ], ret = item.apply( window, arguments ); if ( ret === false ) return ret; // We're filtering node (element/fragment). if ( isNode ) { // No further filtering if it's not anymore // fitable for the subsequent filters. if ( ret && ( ret.name != orgName || ret.type != orgType ) ) { return ret; } } // Filtering value (nodeName/textValue/attrValue). else { // No further filtering if it's not // any more values. if ( typeof ret != 'string' ) return ret; } ret != undefined && ( currentEntry = ret ); } return currentEntry; } })(); // "entities" plugin /* { text : function( text ) { // TODO : Process entities. return text.toUpperCase(); } }; */ |
Commits for namibiapublic/scripts/ckeditor/_source/core/htmlparser/filter.js
Revision | Author | Commited | Message |
---|---|---|---|
df0489 ... | Mark | Fri 14 Oct, 2016 10:01:00 +0000 | initial commit |