|
48 | 48 | options.width = defaults.width; |
49 | 49 | } |
50 | 50 | } |
| 51 | + |
| 52 | + /** |
| 53 | + * appending a text node to a <table> will |
| 54 | + * cause a jquery crash. |
| 55 | + * so wrap all append() calls and revert to |
| 56 | + * a simple appendChild() in case it fails |
| 57 | + */ |
| 58 | + function appendSafe($target, $elem){ |
| 59 | + try{ |
| 60 | + $target.append($elem); |
| 61 | + }catch(e){ |
| 62 | + $target[0].appendChild($elem[0]); |
| 63 | + } |
| 64 | + } |
51 | 65 |
|
52 | 66 | return this.each(function() { |
53 | 67 | var $inBox = options.target ? $(options.target) : $(this); |
|
64 | 78 |
|
65 | 79 | var adjustment = 0; |
66 | 80 |
|
67 | | - $cache.append($(this).contents().clone(true)); |
| 81 | + appendSafe($cache, $(this).contents().clone(true)); |
68 | 82 |
|
69 | 83 | // images loading after dom load |
70 | 84 | // can screw up the column heights, |
|
78 | 92 | var func = function($inBox,$cache){ return function(){ |
79 | 93 | if(!$inBox.data("firstImageLoaded")){ |
80 | 94 | $inBox.data("firstImageLoaded", "true"); |
81 | | - $inBox.empty().append($cache.children().clone(true)); |
| 95 | + appendSafe($inBox.empty(), $cache.children().clone(true)); |
82 | 96 | $inBox.columnize(options); |
83 | 97 | } |
84 | 98 | }; |
|
149 | 163 | // our column is on a column break, so just end here |
150 | 164 | return; |
151 | 165 | } |
152 | | - $putInHere.append(node); |
| 166 | + appendSafe($putInHere, $(node)); |
153 | 167 | } |
154 | 168 | if($putInHere[0].childNodes.length === 0) return; |
155 | 169 |
|
|
184 | 198 | columnText = oText; |
185 | 199 | } |
186 | 200 | latestTextNode = document.createTextNode(columnText); |
187 | | - $putInHere.append(latestTextNode); |
| 201 | + appendSafe($putInHere, $(latestTextNode)); |
188 | 202 |
|
189 | 203 | if(oText.length > counter2 && indexOfSpace != -1){ |
190 | 204 | oText = oText.substring(indexOfSpace); |
|
207 | 221 | if($pullOutHere.contents().length){ |
208 | 222 | $pullOutHere.prepend($item); |
209 | 223 | }else{ |
210 | | - $pullOutHere.append($item); |
| 224 | + appendSafe($pullOutHere, $item); |
211 | 225 | } |
212 | 226 |
|
213 | 227 | return $item[0].nodeType == 3; |
|
244 | 258 | // |
245 | 259 | // ok, we have a columnbreak, so add it into |
246 | 260 | // the column and exit |
247 | | - $putInHere.append($clone); |
| 261 | + appendSafe($putInHere, $clone); |
248 | 262 | $cloneMe.remove(); |
249 | 263 | }else if (manualBreaks){ |
250 | 264 | // keep adding until we hit a manual break |
251 | | - $putInHere.append($clone); |
| 265 | + appendSafe($putInHere, $clone); |
252 | 266 | $cloneMe.remove(); |
253 | 267 | }else if($clone.get(0).nodeType == 1 && !$clone.hasClass(prefixTheClassName("dontend"))){ |
254 | | - $putInHere.append($clone); |
| 268 | + appendSafe($putInHere, $clone); |
255 | 269 | if($clone.is("img") && $parentColumn.height() < targetHeight + 20){ |
256 | 270 | // |
257 | 271 | // we can't split an img in half, so just add it |
|
351 | 365 | overflow.innerHTML = html; |
352 | 366 |
|
353 | 367 | }else{ |
354 | | - $col.append($destroyable.contents()); |
| 368 | + appendSafe($col, $destroyable.contents()); |
355 | 369 | } |
356 | 370 | $inBox.data("columnizing", false); |
357 | 371 |
|
|
414 | 428 | $inBox.empty(); |
415 | 429 | $inBox.append($("<div style='width:" + (Math.floor(100 / numCols))+ "%; float: " + options.columnFloat + ";'></div>")); //" |
416 | 430 | $col = $inBox.children(":last"); |
417 | | - $col.append($cache.clone()); |
| 431 | + appendSafe($col, $cache.clone()); |
418 | 432 | maxHeight = $col.height(); |
419 | 433 | $inBox.empty(); |
420 | 434 |
|
|
0 commit comments