Permalink
Browse files

Added the syntax $(elm).markItUp('insert', { }); and $(elm).markItUp(…

…'remove');
  • Loading branch information...
1 parent 1a209ed commit 98a170fc1622656725d35e143507628c2892f595 @jaysalvat jaysalvat committed Aug 30, 2012
Showing with 41 additions and 14 deletions.
  1. +2 −1 CHANGELOG.md
  2. +10 −7 index.html
  3. +29 −6 markitup/jquery.markitup.js
View
@@ -6,8 +6,9 @@ markItUp! 1.1.12 2012-08-30
- Fixed Ctrl+Enter syntax error (UltCombo)
- Added the previewHandler option to allow complete control over preview (lecterror)
- Updated events to use namespace (JoyceBabu)
+- Added $(elm).markItUp('insert', { }) and $(elm).markItUp('remove');
+- Updated the demo
- Added package.json
-- Updated jQuery version to 1.8 in the demo
markItUp! 1.1.12 2011-08-11
- Fixed the insertion on empty selection
View
@@ -32,23 +32,26 @@
// Add markItUp! to your textarea in one line
// $('textarea').markItUp( { Settings }, { OptionalExtraSettings } );
$('#markItUp').markItUp(mySettings);
-
+
+
+
// You can add content from anywhere in your page
// $.markItUp( { Settings } );
$('.add').click(function() {
- $.markItUp( { openWith:'<opening tag>',
- closeWith:'<\/closing tag>',
- placeHolder:"New content"
- }
- );
+ $('#markItUp').markItUp('insert',
+ { openWith:'<opening tag>',
+ closeWith:'<\/closing tag>',
+ placeHolder:"New content"
+ }
+ );
return false;
});
// And you can add/remove markItUp! whenever you want
// $(textarea).markItUpRemove();
$('.toggle').click(function() {
if ($("#markItUp.markItUpEditor").length === 1) {
- $("#markItUp").markItUpRemove();
+ $("#markItUp").markItUp('remove');
$("span", this).text("get markItUp! back");
} else {
$('#markItUp').markItUp(mySettings);
@@ -26,9 +26,13 @@
// ----------------------------------------------------------------------------
(function($) {
$.fn.markItUp = function(settings, extraSettings) {
- var options, ctrlKey, shiftKey, altKey;
- ctrlKey = shiftKey = altKey = false;
-
+ var method, params, options, ctrlKey, shiftKey, altKey; ctrlKey = shiftKey = altKey = false;
+
+ if (typeof settings == 'string') {
+ method = settings;
+ params = extraSettings;
+ }
+
options = { id: '',
nameSpace: '',
root: '',
@@ -75,6 +79,20 @@
options.previewParserPath = localize(options.previewParserPath);
options.previewTemplatePath = localize(options.previewTemplatePath);
+ if (method) {
+ switch(method) {
+ case 'remove':
+ remove();
+ break;
+ case 'insert':
+ markup(params);
+ break;
+ default:
+ $.error('Method ' + method + ' does not exist on jQuery.markItUp');
+ }
+ return;
+ }
+
// apply the computed path to ~/
function localize(data, inText) {
if (inText) {
@@ -522,7 +540,7 @@
function writeInPreview(data) {
if (options.previewInElement) {
$(options.previewInElement).html(data);
- } else if (previewWindow.document) {
+ } else if (previewWindow && previewWindow.document) {
try {
sp = previewWindow.document.documentElement.scrollTop
} catch(e) {
@@ -584,14 +602,19 @@
}
}
+ function remove() {
+ $$.unbind(".markItUp").removeClass('markItUpEditor');
+ $$.parent('div').parent('div.markItUp').parent('div').replaceWith($$);
+ $$.data('markItUp', null);
+ }
+
init();
});
};
$.fn.markItUpRemove = function() {
return this.each(function() {
- var $$ = $(this).unbind(".markItUp").removeClass('markItUpEditor');
- $$.parent('div').parent('div.markItUp').parent('div').replaceWith($$);
+ $(this).markItUp('remove');
}
);
};

0 comments on commit 98a170f

Please sign in to comment.