Skip to content

Commit

Permalink
Add quick patch to keep compatibility with jQuery 1.9+
Browse files Browse the repository at this point in the history
  • Loading branch information
jaysalvat committed Jan 29, 2013
1 parent 21d7442 commit bae7bdd
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions markitup/jquery.markitup.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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() { return this.each(function() {
var $$, textarea, levels, scrollPosition, caretPosition, caretOffset, var $$, textarea, levels, scrollPosition, caretPosition, caretOffset,
clicked, hash, header, footer, previewWindow, template, iFrame, abort; clicked, hash, header, footer, previewWindow, template, iFrame, abort;
Expand Down Expand Up @@ -126,7 +155,7 @@
footer = $('<div class="markItUpFooter"></div>').insertAfter($$); footer = $('<div class="markItUpFooter"></div>').insertAfter($$);


// add the resize handle after textarea // 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>') resizeHandle = $('<div class="markItUpResizeHandle"></div>')
.insertAfter($$) .insertAfter($$)
.bind("mousedown.markItUp", function(e) { .bind("mousedown.markItUp", function(e) {
Expand Down Expand Up @@ -339,7 +368,7 @@


string = { block:lines.join('\n')}; string = { block:lines.join('\n')};
start = caretPosition; start = caretPosition;
len = string.block.length + (($.browser.opera) ? n-1 : 0); len = string.block.length + ((browser.opera) ? n-1 : 0);
} else if (ctrlKey === true) { } else if (ctrlKey === true) {
string = build(selection); string = build(selection);
start = caretPosition + string.openWith.length; start = caretPosition + string.openWith.length;
Expand Down Expand Up @@ -396,14 +425,14 @@


// Substract linefeed in Opera // Substract linefeed in Opera
function fixOperaBug(string) { function fixOperaBug(string) {
if ($.browser.opera) { if (browser.opera) {
return string.length - string.replace(/\n*/g, '').length; return string.length - string.replace(/\n*/g, '').length;
} }
return 0; return 0;
} }
// Substract linefeed in IE // Substract linefeed in IE
function fixIeBug(string) { function fixIeBug(string) {
if ($.browser.msie) { if (browser.msie) {
return string.length - string.replace(/\r*/g, '').length; return string.length - string.replace(/\r*/g, '').length;
} }
return 0; return 0;
Expand All @@ -423,7 +452,7 @@
function set(start, len) { function set(start, len) {
if (textarea.createTextRange){ if (textarea.createTextRange){
// quick fix to make it work on Opera 9.5 // 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; return false;
} }
range = textarea.createTextRange(); range = textarea.createTextRange();
Expand All @@ -445,7 +474,7 @@
scrollPosition = textarea.scrollTop; scrollPosition = textarea.scrollTop;
if (document.selection) { if (document.selection) {
selection = document.selection.createRange().text; selection = document.selection.createRange().text;
if ($.browser.msie) { // ie if (browser.msie) { // ie
var range = document.selection.createRange(), rangeCopy = range.duplicate(); var range = document.selection.createRange(), rangeCopy = range.duplicate();
rangeCopy.moveToElementText(textarea); rangeCopy.moveToElementText(textarea);
caretPosition = -1; caretPosition = -1;
Expand Down

0 comments on commit bae7bdd

Please sign in to comment.