Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add quick patch to keep compatibility with jQuery 1.9+

  • Loading branch information...
commit bae7bddecb9d505e32c569edcfdc95f452692b49 1 parent 21d7442
@jaysalvat jaysalvat authored
Showing with 35 additions and 6 deletions.
  1. +35 −6 markitup/jquery.markitup.js
View
41 markitup/jquery.markitup.js
@@ -66,6 +66,35 @@
});
}
+ // Quick patch to keep compatibility with jQuery 1.9
+ var uaMatch = function(ua) {
+ ua = ua.toLowerCase();
+
+ var match = /(chrome)[ \/]([\w.]+)/.exec(ua) ||
+ /(webkit)[ \/]([\w.]+)/.exec(ua) ||
+ /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) ||
+ /(msie) ([\w.]+)/.exec(ua) ||
+ ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) ||
+ [];
+
+ return {
+ browser: match[ 1 ] || "",
+ version: match[ 2 ] || "0"
+ };
+ };
+ var matched = uaMatch( navigator.userAgent );
+ var browser = {};
+
+ if (matched.browser) {
+ browser[matched.browser] = true;
+ browser.version = matched.version;
+ }
+ if (browser.chrome) {
+ browser.webkit = true;
+ } else if (browser.webkit) {
+ browser.safari = true;
+ }
+
return this.each(function() {
var $$, textarea, levels, scrollPosition, caretPosition, caretOffset,
clicked, hash, header, footer, previewWindow, template, iFrame, abort;
@@ -126,7 +155,7 @@
footer = $('<div class="markItUpFooter"></div>').insertAfter($$);
// add the resize handle after textarea
- if (options.resizeHandle === true && $.browser.safari !== true) {
+ if (options.resizeHandle === true && browser.safari !== true) {
resizeHandle = $('<div class="markItUpResizeHandle"></div>')
.insertAfter($$)
.bind("mousedown.markItUp", function(e) {
@@ -339,7 +368,7 @@
string = { block:lines.join('\n')};
start = caretPosition;
- len = string.block.length + (($.browser.opera) ? n-1 : 0);
+ len = string.block.length + ((browser.opera) ? n-1 : 0);
} else if (ctrlKey === true) {
string = build(selection);
start = caretPosition + string.openWith.length;
@@ -396,14 +425,14 @@
// Substract linefeed in Opera
function fixOperaBug(string) {
- if ($.browser.opera) {
+ if (browser.opera) {
return string.length - string.replace(/\n*/g, '').length;
}
return 0;
}
// Substract linefeed in IE
function fixIeBug(string) {
- if ($.browser.msie) {
+ if (browser.msie) {
return string.length - string.replace(/\r*/g, '').length;
}
return 0;
@@ -423,7 +452,7 @@
function set(start, len) {
if (textarea.createTextRange){
// quick fix to make it work on Opera 9.5
- if ($.browser.opera && $.browser.version >= 9.5 && len == 0) {
+ if (browser.opera && browser.version >= 9.5 && len == 0) {
return false;
}
range = textarea.createTextRange();
@@ -445,7 +474,7 @@
scrollPosition = textarea.scrollTop;
if (document.selection) {
selection = document.selection.createRange().text;
- if ($.browser.msie) { // ie
+ if (browser.msie) { // ie
var range = document.selection.createRange(), rangeCopy = range.duplicate();
rangeCopy.moveToElementText(textarea);
caretPosition = -1;
Please sign in to comment.
Something went wrong with that request. Please try again.