@@ -24,19 +24,26 @@ define([
24
24
* @param {jQuery } element - Comment holder
25
25
*/
26
26
( function lookup ( element ) {
27
- if ( element . is ( 'iframe' ) ) {
28
- var hostName = window . location . hostname ,
29
- iFrameHostName = $ ( '<a>' ) . prop ( 'href' , element . prop ( 'src' ) ) . prop ( 'hostname' ) ;
30
-
31
- if ( hostName != iFrameHostName ) {
32
- return ;
33
- }
34
- }
35
- element . contents ( ) . each ( function ( i , el ) {
36
- if ( el . nodeType == 8 ) {
37
- elements . push ( el ) ;
38
- } else if ( el . nodeType == 1 ) {
39
- lookup ( $ ( el ) ) ;
27
+ $ ( element ) . contents ( ) . each ( function ( index , el ) {
28
+ switch ( el . nodeType ) {
29
+ case 1 : // ELEMENT_NODE
30
+ lookup ( el ) ;
31
+ break ;
32
+
33
+ case 8 : // COMMENT_NODE
34
+ elements . push ( el ) ;
35
+ break ;
36
+
37
+ case 9 : // DOCUMENT_NODE
38
+ var hostName = window . location . hostname ,
39
+ iFrameHostName = $ ( '<a>' )
40
+ . prop ( 'href' , element . prop ( 'src' ) )
41
+ . prop ( 'hostname' ) ;
42
+
43
+ if ( hostName === iFrameHostName ) {
44
+ lookup ( $ ( el ) . find ( 'body' ) ) ;
45
+ }
46
+ break ;
40
47
}
41
48
} ) ;
42
49
} ) ( this ) ;
@@ -59,10 +66,7 @@ define([
59
66
*/
60
67
_create : function ( ) {
61
68
if ( $ . mage . cookies . get ( this . options . msgBoxCookieName ) ) {
62
- $ . mage . cookies . set ( this . options . msgBoxCookieName , null , {
63
- expires : new Date ( ) ,
64
- path : '/'
65
- } ) ;
69
+ $ . mage . cookies . clear ( this . options . msgBoxCookieName ) ;
66
70
} else {
67
71
$ ( this . options . msgBoxSelector ) . hide ( ) ;
68
72
}
@@ -125,7 +129,7 @@ define([
125
129
}
126
130
placeholders = this . _searchPlaceholders ( this . element . comments ( ) ) ;
127
131
128
- if ( placeholders . length ) {
132
+ if ( placeholders && placeholders . length ) {
129
133
this . _ajax ( placeholders , version ) ;
130
134
}
131
135
} ,
@@ -140,13 +144,14 @@ define([
140
144
var placeholders = [ ] ,
141
145
tmp = { } ,
142
146
ii ,
147
+ len ,
143
148
el , matches , name ;
144
149
145
- if ( ! elements . length ) {
150
+ if ( ! ( elements && elements . length ) ) {
146
151
return placeholders ;
147
152
}
148
153
149
- for ( ii = 0 ; ii < elements . length ; ii ++ ) {
154
+ for ( ii = 0 , len = elements . length ; ii < len ; ii ++ ) {
150
155
el = elements [ ii ] ;
151
156
matches = this . options . patternPlaceholderOpen . exec ( el . nodeValue ) ;
152
157
name = null ;
@@ -182,14 +187,19 @@ define([
182
187
* @protected
183
188
*/
184
189
_replacePlaceholder : function ( placeholder , html ) {
190
+ if ( ! placeholder || ! html ) {
191
+ return ;
192
+ }
193
+
185
194
var parent = $ ( placeholder . openElement ) . parent ( ) ,
186
195
contents = parent . contents ( ) ,
187
196
startReplacing = false ,
188
197
prevSibling = null ,
189
198
yy ,
199
+ len ,
190
200
element ;
191
201
192
- for ( yy = 0 ; yy < contents . length ; yy ++ ) {
202
+ for ( yy = 0 , len = contents . length ; yy < len ; yy ++ ) {
193
203
element = contents [ yy ] ;
194
204
195
205
if ( element == placeholder . openElement ) {
@@ -286,6 +296,7 @@ define([
286
296
*/
287
297
function generateRandomString ( chars , length ) {
288
298
var result = '' ;
299
+ length = length > 0 && Number . isFinite ( length ) ? length : 1 ;
289
300
290
301
while ( length -- ) {
291
302
result += chars [ Math . round ( Math . random ( ) * ( chars . length - 1 ) ) ] ;
0 commit comments