Skip to content

Commit

Permalink
Merge pull request arkhitech#36 from tleish/update_jquery_libs
Browse files Browse the repository at this point in the history
Updating jquery overlay and textcomplete libs
  • Loading branch information
hishammalik committed Feb 3, 2016
2 parents 90a5d0e + 0c792e3 commit da63aa0
Show file tree
Hide file tree
Showing 3 changed files with 1,175 additions and 520 deletions.
35 changes: 25 additions & 10 deletions assets/javascripts/jquery.overlay.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@
* Function for escaping strings to HTML interpolation.
*/
var escape = function (str) {
return str.replace(entityRegexe, function (match) {
return entityMap[match];
})
if (typeof str !== 'undefined'){
return str.replace(entityRegexe, function (match) {
return entityMap[match];
})
}
};

/**
Expand Down Expand Up @@ -108,7 +110,6 @@
'font-family',
'font-weight',
'font-size',
'width',
'background-color'
];

Expand Down Expand Up @@ -174,7 +175,7 @@

renderTextOnOverlay: function () {
var text, i, l, strategy, match, style;
text = escape(this.$textarea.val());
text = $('<div></div>').text(this.$textarea.val());

// Apply all strategies
for (i = 0, l = this.strategies.length; i < l; i++) {
Expand All @@ -190,11 +191,25 @@
// Style attribute's string
style = 'background-color:' + strategy.css['background-color'];

text = text.replace(match, function (str) {
return '<span style="' + style + '">' + str + '</span>';
text.contents().each(function () {
var text, html, str, prevIndex;
if (this.nodeType != Node.TEXT_NODE) return;
text = this.textContent;
html = '';
for (prevIndex = match.lastIndex = 0;; prevIndex = match.lastIndex) {
str = match.exec(text);
if (!str) {
if (prevIndex) html += escape(text.substr(prevIndex));
break;
}
str = str[0];
html += escape(text.substr(prevIndex, match.lastIndex - prevIndex - str.length));
html += '<span style="' + style + '">' + escape(str) + '</span>';
};
if (prevIndex) $(this).replaceWith(html);
});
}
this.$el.html(text);
this.$el.html(text.contents());
return this;
},

Expand All @@ -213,7 +228,7 @@
this.$textarea.off('.overlay');
$wrapper = this.$textarea.parent();
$wrapper.after(this.$textarea).remove();
this.$textarea.data('overlay', void 0);
this.$textarea.removeData('overlay');
this.$textarea = null;
}
});
Expand Down Expand Up @@ -245,4 +260,4 @@
});
};

})(window.jQuery);
})(window.jQuery);
Loading

0 comments on commit da63aa0

Please sign in to comment.