Skip to content

Commit

Permalink
Fix createContextualFragment issue in Safari
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin committed Jan 14, 2016
1 parent 9f2fc4a commit 2b799a7
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions juicy-html.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<script>
(function (scope) {
var JuicyHTMLPrototype = Object.create( (HTMLTemplateElement || HTMLElement ).prototype);

var isSafari = navigator.vendor && navigator.vendor.indexOf("Apple") > -1 && navigator.userAgent && !navigator.userAgent.match("CriOS");

JuicyHTMLPrototype.createdCallback = function(){
var model = null;
Expand Down Expand Up @@ -44,7 +44,14 @@
JuicyHTMLPrototype.reattachTemplate_ = function(html) {
this.clear();
// fragmentFromString(strHTML) from http://stackoverflow.com/a/25214113/868184
var fragment = document.createRange().createContextualFragment(html);
var range = document.createRange();

// Safari does not support `createContextualFragment` without selecting a node.
if (isSafari) {
range.selectNode(this);
}

var fragment = range.createContextualFragment(html);
// convert dynamic NodeList to regullar array
this.stampedNodes = Array.prototype.slice.call(fragment.childNodes);
// attach models
Expand Down

0 comments on commit 2b799a7

Please sign in to comment.