Index: trunk/parsers/wikidom/lib/es/es.Content.Selection.js |
— | — | @@ -1,142 +0,0 @@ |
2 | | -/** |
3 | | - * Creates a selection of content objects. |
4 | | - * |
5 | | - * @class |
6 | | - * @constructor |
7 | | - * @extends {es.EventEmitter} |
8 | | - * @param contents {Array} List of content objects to append |
9 | | - * @property contents {Array} List of content objects in selection |
10 | | - */ |
11 | | -es.Content.Selection = function( contents ) { |
12 | | - es.EventEmitter.call( this ); |
13 | | - this.contents = contents || []; |
14 | | -}; |
15 | | - |
16 | | -/** |
17 | | - * Gets the first content object in the selection. |
18 | | - * |
19 | | - * @method |
20 | | - * @returns {es.Content} First child object |
21 | | - */ |
22 | | -es.Content.Selection.prototype.first = function() { |
23 | | - return this.contents.length ? this.contents[0] : null; |
24 | | -}; |
25 | | - |
26 | | -/** |
27 | | - * Gets the last content object in the selection. |
28 | | - * |
29 | | - * @method |
30 | | - * @returns {es.Content} Last child object |
31 | | - */ |
32 | | -es.Content.Selection.prototype.last = function() { |
33 | | - return this.contents.length ? this.contents[this.contents.length - 1] : null; |
34 | | -}; |
35 | | - |
36 | | -/** |
37 | | - * Iterates over content objects, executing a callback for each. |
38 | | - * |
39 | | - * Returning false in the callback will stop iteration. |
40 | | - * |
41 | | - * @method |
42 | | - * @param callback {Function} Function to call on each content object which takes content and index |
43 | | - * arguments |
44 | | - */ |
45 | | -es.Content.Selection.prototype.each = function( callback ) { |
46 | | - for ( var i = 0; i < this.contents.length; i++ ) { |
47 | | - if ( !callback( this.contents[i], i ) ) { |
48 | | - break; |
49 | | - } |
50 | | - } |
51 | | -}; |
52 | | - |
53 | | -/** |
54 | | - * Adds a content object to the end of the selection. |
55 | | - * |
56 | | - * @method |
57 | | - * @param content {es.Content} Content to append |
58 | | - * @emits "update" |
59 | | - */ |
60 | | -es.Content.Selection.prototype.append = function( content ) { |
61 | | - var selection = this; |
62 | | - content.on( 'update', function() { |
63 | | - selection.emit( 'update' ); |
64 | | - } ); |
65 | | - this.contents.push( content ); |
66 | | - this.emit( 'update' ); |
67 | | -}; |
68 | | - |
69 | | -/** |
70 | | - * Adds a content object to the beginning of the selection. |
71 | | - * |
72 | | - * @method |
73 | | - * @param content {es.Content} Content to prepend |
74 | | - * @emits "update" |
75 | | - */ |
76 | | -es.Content.Selection.prototype.prepend = function( content ) { |
77 | | - var selection = this; |
78 | | - content.on( 'update', function() { |
79 | | - selection.emit( 'update' ); |
80 | | - } ); |
81 | | - this.contents.unshift( content ); |
82 | | - this.emit( 'update' ); |
83 | | -}; |
84 | | - |
85 | | -/** |
86 | | - * Adds a content object to the selection after an existing one. |
87 | | - * |
88 | | - * @method |
89 | | - * @param content {es.Content} Content to insert |
90 | | - * @param before {es.Content} Content to insert before, if null content will be inserted at the end |
91 | | - * @emits "update" |
92 | | - */ |
93 | | -es.Content.Selection.prototype.insertBefore = function( content, before ) { |
94 | | - var selection = this; |
95 | | - content.on( 'update', function() { |
96 | | - selection.emit( 'update' ); |
97 | | - } ); |
98 | | - if ( before ) { |
99 | | - this.contents.splice( before.getIndex(), 0, content ); |
100 | | - } else { |
101 | | - this.contents.push( content ); |
102 | | - } |
103 | | - this.emit( 'update' ); |
104 | | -}; |
105 | | -/** |
106 | | - * Adds a content object to the selection after an existing one. |
107 | | - * |
108 | | - * @method |
109 | | - * @param content {Object} Content to insert |
110 | | - * @param after {Object} Content to insert after, if null content will be inserted at the end |
111 | | - * @emits "update" |
112 | | - */ |
113 | | -es.Content.Selection.prototype.insertAfter = function( content, after ) { |
114 | | - var selection = this; |
115 | | - content.on( 'update', function() { |
116 | | - selection.emit( 'update' ); |
117 | | - } ); |
118 | | - if ( after ) { |
119 | | - this.contents.splice( after.getIndex() + 1, 0, content ); |
120 | | - } else { |
121 | | - this.contents.push( content ); |
122 | | - } |
123 | | - this.emit( 'update' ); |
124 | | -}; |
125 | | - |
126 | | -/** |
127 | | - * Removes a content object from the selection. |
128 | | - * |
129 | | - * Also detaches item's Element object to the DOM and removes all listeners its "update" events. |
130 | | - * |
131 | | - * @method |
132 | | - * @param content {Object} Content to remove |
133 | | - * @emits "update" |
134 | | - */ |
135 | | -es.Content.Selection.prototype.remove = function( content ) { |
136 | | - content.removeAllListeners( 'update' ); |
137 | | - this.contents.splice( content.getIndex(), 1 ); |
138 | | - this.emit( 'update' ); |
139 | | -}; |
140 | | - |
141 | | -/* Inheritance */ |
142 | | - |
143 | | -es.extend( es.Content.Selection, es.EventEmitter ); |