SoFunction
Updated on 2025-04-14

[Transfer] Prototype Source Code Interpretation Super Recommended Page 3/3


/**  
2  
3  * Get object array based on the name of class attribute, supporting multiple class
4  
5  *  
6  
7  */  
8   
9  = function(className) {   
10   
11   var children = ('*') || ;   
12   
13   var elements = new Array();   
14   
15   
16   for (var i = 0; i < ; i++) {   
17   
18     var child = children[i];   
19   
20     var classNames = (' ');   
21   
22     for (var j = 0; j < ; j++) {   
23   
24       if (classNames[j] == className) {   
25   
26         (child);   
27   
28         break;   
29   
30       }   
31   
32     }   
33   
34   }   
35   
36   
37   return elements;   
38   
39 }   
40   
41   
42 /*--------------------------------------------------------------------------*/  
43   
44   
45 /**  
46  
47  * Element is like a java tool class, mainly used to hide/show/removal objects,
48  
49  * and simple properties of the object.
50  
51  *  
52  
53  */  
54   
55 var Element = {   
56   
57   toggle: function() {   
58   
59     for (var i = 0; i < ; i++) {   
60   
61       var element = $(arguments[i]);   
62   
63        =   
64   
65         ( == 'none' ? '' : 'none');   
66   
67     }   
68   
69   },   
70   
71   
72   hide: function() {   
73   
74     for (var i = 0; i < ; i++) {   
75   
76       var element = $(arguments[i]);   
77   
78        = 'none';   
79   
80     }   
81   
82   },   
83   
84   
85   show: function() {   
86   
87     for (var i = 0; i < ; i++) {   
88   
89       var element = $(arguments[i]);   
90   
91        = '';   
92   
93     }   
94   
95   },   
96   
97   
98   remove: function(element) {   
99   
100     element = $(element);   
101   
102     (element);   
103   
104   },   
105   
106   
107   getHeight: function(element) {   
108   
109     element = $(element);   
110   
111     return ;   
112   
113   }   
114   
115 }   
116   
117   
118 /**  
119  
120  * A symbolic connection was made for  presumably for compatibility considerations
121  
122  */  
123   
124 var Toggle = new Object();   
125   
126  = ;   
127   
128   
129 /*--------------------------------------------------------------------------*/  
130   
131   
132 /**  
133  
134  * Implementation of dynamic insertion of content, the object in the Jscript implementation of MS has an insertAdjacentHTML method
135  
136  * /workshop/  
137  
138  * author/dhtml/reference/methods/  
139  
140  * This is considered an object-form encapsulation.
141  
142  */  
143   
144  = function(adjacency) {   
145   
146    = adjacency;   
147   
148 }   
149   
150   
151  = {   
152   
153   initialize: function(element, content) {   
154   
155      = $(element);   
156   
157      = content;   
158   
159   
160     if ( && ) {   
161   
162       (, );   
163   
164     } else {   
165   
166      /**  
167  
168       *  gecko Does not support the insertAdjacentHTML method, but the following code can be used instead.
169  
170       */  
171   
172        = ();   
173   
174      /**  
175  
176      * If the initializeRange method is defined, then implement,
177  
178      * This is quite similar to defining an abstract initializeRange method
179  
180       */  
181   
182       if () ();   
183   
184        = ();   
185   
186   
187      /**  
188  
189      *  insertContent is also an abstract method, and subclasses must be implemented
190  
191       */  
192   
193       ();   
194   
195     }   
196   
197   }   
198   
199 }   
200   
201   
202 /**  
203  
204  * prototype Deepened my experience, which is how to follow the writing of js
205  
206  * Don't Repeat Yourself (DRY) Principle
207  
208  * The above is considered an abstract class,
209  
210  * Define an abstract method called initializeRange
211  
212 *  var Insertion = new Object() Create a namespace
213  
214 * |Top|Bottom|After It's like four java
215  
216 * Four static inner classes, and they are inherited from
217  
218  * , and implements the initializeRange method.
219  
220  */  
221   
222 var Insertion = new Object();   
223   
224   
225  = ();   
226   
227  =   
228   
229   (new ('beforeBegin')).extend({   
230   
231   initializeRange: function() {   
232   
233     ();   
234   
235   },   
236   
237   
238   /**  
239  
240    * Insert the content in front of the specified node, at the same level as the specified node
241  
242    */  
243   
244   insertContent: function() {   
245   
246     (, );   
247   
248   }   
249   
250 });   
251   
252   
253  = ();   
254   
255  =   
256   
257   (new ('afterBegin')).extend({   
258   
259   initializeRange: function() {   
260   
261     ();   
262   
263     (true);   
264   
265   },   
266   
267   
268   /**  
269  
270    * Insert the content into the first child node of the specified node, and the content becomes the first child node of the node
271  
272    */  
273   
274   insertContent: function() {   
275   
276     (, );   
277   
278   }   
279   
280 });   
281   
282   
283  = ();   
284   
285  = (new ('beforeEnd')).extend({   
286   
287   initializeRange: function() {   
288   
289     ();   
290   
291     ();   
292   
293   },   
294   
295   
296   /**  
297  
298    * Insert the content at the end of the specified node, so the content becomes the last child node of the node
299  
300    */  
301   
302   insertContent: function() {   
303   
304     ();   
305   
306   }   
307   
308 });   
309   
310   
311   
312  = ();   
313   
314  = (new ('afterEnd')).extend({   
315   
316   initializeRange: function() {   
317   
318     ();   
319   
320   },   
321   
322   
323   /**  
324  
325    * Insert the content behind the specified node, at the same level as the specified node
326  
327    */  
328   
329   insertContent: function() {   
330   
331     (,   
332   
333       );   
334   
335   }   
336   
337 });