+ return function( onlyEditables )\r
+ {\r
+ var cache = this._.cache;\r
+ if ( cache.ranges && !onlyEditables )\r
+ return cache.ranges;\r
+ else if ( !cache.ranges )\r
+ cache.ranges = new CKEDITOR.dom.rangeList( func.call( this ) );\r
+\r
+ // Split range into multiple by read-only nodes.\r
+ if ( onlyEditables )\r
+ {\r
+ var ranges = cache.ranges;\r
+ for ( var i = 0; i < ranges.length; i++ )\r
+ {\r
+ var range = ranges[ i ];\r
+\r
+ // Drop range spans inside one ready-only node.\r
+ var parent = range.getCommonAncestor();\r
+ if ( parent.isReadOnly())\r
+ ranges.splice( i, 1 );\r
+\r
+ if ( range.collapsed )\r
+ continue;\r
+\r
+ var startContainer = range.startContainer,\r
+ endContainer = range.endContainer,\r
+ startOffset = range.startOffset,\r
+ endOffset = range.endOffset,\r
+ walkerRange = range.clone();\r
+\r
+ // Range may start inside a non-editable element, restart range\r
+ // by the end of it.\r
+ var readOnly;\r
+ if ( ( readOnly = startContainer.isReadOnly() ) )\r
+ range.setStartAfter( readOnly );\r
+\r
+ // Enlarge range start/end with text node to avoid walker\r
+ // being DOM destructive, it doesn't interfere our checking\r
+ // of elements below as well.\r
+ if ( startContainer && startContainer.type == CKEDITOR.NODE_TEXT )\r
+ {\r
+ if ( startOffset >= startContainer.getLength() )\r
+ walkerRange.setStartAfter( startContainer );\r
+ else\r
+ walkerRange.setStartBefore( startContainer );\r
+ }\r
+\r
+ if ( endContainer && endContainer.type == CKEDITOR.NODE_TEXT )\r
+ {\r
+ if ( !endOffset )\r
+ walkerRange.setEndBefore( endContainer );\r
+ else\r
+ walkerRange.setEndAfter( endContainer );\r
+ }\r
+\r
+ // Looking for non-editable element inside the range.\r
+ var walker = new CKEDITOR.dom.walker( walkerRange );\r
+ walker.evaluator = function( node )\r
+ {\r
+ if ( node.type == CKEDITOR.NODE_ELEMENT\r
+ && node.getAttribute( 'contenteditable' ) == 'false' )\r
+ {\r
+ var newRange = range.clone();\r
+ range.setEndBefore( node );\r
+\r
+ // Drop collapsed range around read-only elements,\r
+ // it make sure the range list empty when selecting\r
+ // only non-editable elements.\r
+ if ( range.collapsed )\r
+ ranges.splice( i--, 1 );\r
+\r
+ // Avoid creating invalid range.\r
+ if ( !( node.getPosition( walkerRange.endContainer ) & CKEDITOR.POSITION_CONTAINS ) )\r
+ {\r
+ newRange.setStartAfter( node );\r
+ if ( !newRange.collapsed )\r
+ ranges.splice( i + 1, 0, newRange );\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
+ return false;\r
+ };\r
+\r
+ walker.next();\r
+ }\r
+ }\r
+\r
+ return cache.ranges;\r
+ };\r
+ })(),\r