Mercurial > public > sg101
diff static/js/markitup/jquery.markitup.js @ 466:c78c6e007e61
Upgrading to markitup version 1.1.11. This fixes #226.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 24 Jul 2011 02:35:17 +0000 |
parents | 88b2b9cb8c1f |
children | d280b27fed17 |
line wrap: on
line diff
--- a/static/js/markitup/jquery.markitup.js Sat Jul 09 02:28:33 2011 +0000 +++ b/static/js/markitup/jquery.markitup.js Sun Jul 24 02:35:17 2011 +0000 @@ -1,9 +1,9 @@ // ---------------------------------------------------------------------------- // markItUp! Universal MarkUp Engine, JQuery plugin -// v 1.1.x +// v 1.1.11 // Dual licensed under the MIT and GPL licenses. // ---------------------------------------------------------------------------- -// Copyright (C) 2007-2010 Jay Salvat +// Copyright (C) 2007-2011 Jay Salvat // http://markitup.jaysalvat.com/ // ---------------------------------------------------------------------------- // Permission is hereby granted, free of charge, to any person obtaining a copy @@ -36,6 +36,7 @@ previewAutoRefresh: true, previewPosition: 'after', previewTemplatePath: '~/templates/preview.html', + previewParser: false, previewParserPath: '', previewParserVar: 'data', resizeHandle: true, @@ -162,9 +163,9 @@ return false; }).click(function() { return false; - }).focusin(function(){ + }).bind("focusin", function(){ $$.focus(); - }).mousedown(function() { + }).mouseup(function() { if (button.call) { eval(button.call)(); } @@ -233,17 +234,39 @@ // build block to insert function build(string) { - openWith = prepare(clicked.openWith); - placeHolder = prepare(clicked.placeHolder); - replaceWith = prepare(clicked.replaceWith); - closeWith = prepare(clicked.closeWith); + var openWith = prepare(clicked.openWith); + var placeHolder = prepare(clicked.placeHolder); + var replaceWith = prepare(clicked.replaceWith); + var closeWith = prepare(clicked.closeWith); + var openBlockWith = prepare(clicked.openBlockWith); + var closeBlockWith = prepare(clicked.closeBlockWith); + var multiline = clicked.multiline; + if (replaceWith !== "") { block = openWith + replaceWith + closeWith; } else if (selection === '' && placeHolder !== '') { block = openWith + placeHolder + closeWith; } else { - block = openWith + (string||selection) + closeWith; + string = string || selection; + + var lines = selection.split(/\r?\n/), blocks = []; + for (var l=0; l < lines.length; l++) { + line = lines[l]; + if ($.trim(line) == '') { + continue; + } + if (line.match(/ +$/)) { + blocks.push(openWith + line.replace(/ $/, '') + closeWith + ' '); + } else { + blocks.push(openWith + line + closeWith); + } + } + + block = blocks.join("\n"); } + + block = openBlockWith + block + closeBlockWith; + return { block:block, openWith:openWith, replaceWith:replaceWith, @@ -257,7 +280,6 @@ var len, j, n, i; hash = clicked = button; get(); - $.extend(hash, { line:"", root:options.root, textarea:textarea, @@ -271,12 +293,12 @@ // callbacks before insertion prepare(options.beforeInsert); prepare(clicked.beforeInsert); - if (ctrlKey === true && shiftKey === true) { + if ((ctrlKey === true && shiftKey === true) || button.multiline === true) { prepare(clicked.beforeMultiInsert); } $.extend(hash, { line:1 }); - - if (ctrlKey === true && shiftKey === true) { + + if ((ctrlKey === true && shiftKey === true)) { lines = selection.split(/\r?\n/); for (j = 0, n = lines.length, i = 0; i < n; i++) { if ($.trim(lines[i]) !== '') { @@ -293,6 +315,7 @@ string = build(selection); start = caretPosition + string.openWith.length; len = string.block.length - string.openWith.length - string.closeWith.length; + len = len - (string.block.match(/ $/) ? 1 : 0); len -= fixIeBug(string.block); } else if (shiftKey === true) { string = build(selection); @@ -327,7 +350,7 @@ $.extend(hash, { line:'', selection:selection }); // callbacks after insertion - if (ctrlKey === true && shiftKey === true) { + if ((ctrlKey === true && shiftKey === true) || button.multiline === true) { prepare(clicked.afterMultiInsert); } prepare(clicked.afterInsert); @@ -406,6 +429,7 @@ } } else { // gecko & webkit caretPosition = textarea.selectionStart; + selection = textarea.value.substring(caretPosition, textarea.selectionEnd); } return selection; @@ -451,23 +475,30 @@ function renderPreview() { var phtml; - if (options.previewParserPath !== '') { - $.ajax( { + if (options.previewParser && typeof options.previewParser === 'function') { + var data = options.previewParser( $$.val() ); + writeInPreview( localize(data, 1) ); + } else if (options.previewParserPath !== '') { + $.ajax({ type: 'POST', + dataType: 'text', + global: false, url: options.previewParserPath, data: options.previewParserVar+'='+encodeURIComponent($$.val()), success: function(data) { writeInPreview( localize(data, 1) ); } - } ); + }); } else { if (!template) { - $.ajax( { + $.ajax({ url: options.previewTemplatePath, + dataType: 'text', + global: false, success: function(data) { writeInPreview( localize(data, 1).replace(/<!-- content -->/g, $$.val()) ); } - } ); + }); } } return false; @@ -491,15 +522,15 @@ function keyPressed(e) { shiftKey = e.shiftKey; altKey = e.altKey; - ctrlKey = (!(e.altKey && e.ctrlKey)) ? e.ctrlKey : false; + ctrlKey = (!(e.altKey && e.ctrlKey)) ? (e.ctrlKey || e.metaKey) : false; if (e.type === 'keydown') { if (ctrlKey === true) { - li = $("a[accesskey="+String.fromCharCode(e.keyCode)+"]", header).parent('li'); + li = $('a[accesskey="'+String.fromCharCode(e.keyCode)+'"]', header).parent('li'); if (li.length !== 0) { ctrlKey = false; setTimeout(function() { - li.triggerHandler('mousedown'); + li.triggerHandler('mouseup'); },1); return false; }