diff --git a/examples/basic.html b/examples/basic.html index 595a6fe..4831a2f 100644 --- a/examples/basic.html +++ b/examples/basic.html @@ -6,13 +6,13 @@ A tiny, opensource, Bootstrap WYSIWYG rich text editor - - - + + + - + > - + @@ -26,6 +26,8 @@

Basic editor, no fancy bits.

href="#!" onClick="$('#editorPreview').html($('#editor').html());">Submit

- + \ No newline at end of file diff --git a/examples/clear-formatting.html b/examples/clear-formatting.html index 963afe8..77c75f6 100644 --- a/examples/clear-formatting.html +++ b/examples/clear-formatting.html @@ -6,14 +6,14 @@ A tiny, opensource, Bootstrap WYSIWYG rich text editor - - - + + + - +
- +

Simple Editor with Toolbar

@@ -52,9 +52,9 @@

Simple Editor with Toolbar

- - - + + +
@@ -69,14 +69,14 @@

Simple Editor with Toolbar

- + - + + - + + - + + + - + + - + + - + + - + + - + - - - diff --git a/js/bootstrap-wysiwyg.min.js b/js/bootstrap-wysiwyg.min.js index 110a13f..333f8aa 100644 --- a/js/bootstrap-wysiwyg.min.js +++ b/js/bootstrap-wysiwyg.min.js @@ -1 +1 @@ -!function(t){"use strict";var e=function(e){var n=t.Deferred(),a=new FileReader;return a.onload=function(t){n.resolve(t.target.result)},a.onerror=n.reject,a.onprogress=n.notify,a.readAsDataURL(e),n.promise()};t.fn.cleanHtml=function(e){if(t(this).data("wysiwyg-html-mode")===!0&&(t(this).html(t(this).text()),t(this).attr("contenteditable",!0),t(this).data("wysiwyg-html-mode",!1)),e===!0&&t(this).parent().is("form")){var n=t(this).html;if(t(n).has("img").length){var a=t("img",t(n)),o=[],i=t(this).parent();t.each(a,function(e,n){t(n).attr("src").match(/^data:image\/.*$/)&&(o.push(a[e]),t(i).prepend(""),t(n).attr("src","postedimage/"+e))})}}var r=t(this).html();return r&&r.replace(/(
|\s|

<\/div>| )*$/,"")},t.fn.wysiwyg=function(n){var a,o,i,r=this,l=function(){o.activeToolbarClass&&t(o.toolbarSelector).find(i).each(function(){var e=t(this).data(o.commandRole).split(" "),n=e[0];e.length>1&&document.queryCommandEnabled(n)&&document.queryCommandValue(n)===e[1]?t(this).addClass(o.activeToolbarClass):1===e.length&&document.queryCommandEnabled(n)&&document.queryCommandState(n)?t(this).addClass(o.activeToolbarClass):t(this).removeClass(o.activeToolbarClass)})},s=function(t,e){var n=t.split(" "),a=n.shift(),o=n.join(" ")+(e||""),i=t.split("-");1===i.length?document.execCommand(a,!1,o):"format"===i[0]&&2===i.length&&document.execCommand("formatBlock",!1,i[1]),r.trigger("change"),l()},d=function(e){t.each(e,function(t,e){r.keydown(t,function(t){r.attr("contenteditable")&&r.is(":visible")&&(t.preventDefault(),t.stopPropagation(),s(e))}).keyup(t,function(t){r.attr("contenteditable")&&r.is(":visible")&&(t.preventDefault(),t.stopPropagation())})}),r.keyup(function(){r.trigger("change")})},c=function(){var t,e;return window.getSelection?(t=window.getSelection(),t.getRangeAt&&t.rangeCount&&(e=t.getRangeAt(0))):document.selection&&(e=document.selection.createRange()),e},u=function(){a=c()},m=function(){var t;if(window.getSelection||document.createRange){if(t=window.getSelection(),a){try{t.removeAllRanges()}catch(e){document.body.createTextRange().select(),document.selection.empty()}t.addRange(a)}}else document.selection&&a&&a.select()},h=function(){if(t(r).data("wysiwyg-html-mode")!==!0){var e=t(r).html(),n=t("
");t(n).append(document.createTextNode(e)),t(n).attr("contenteditable",!0),t(r).html(" "),t(r).append(t(n)),t(r).attr("contenteditable",!1),t(r).data("wysiwyg-html-mode",!0),t(n).focus()}else t(r).html(t(r).text()),t(r).attr("contenteditable",!0),t(r).data("wysiwyg-html-mode",!1),t(r).focus()},f=function(n){r.focus(),t.each(n,function(n,a){/^image\//.test(a.type)?t.when(e(a)).done(function(t){s("insertimage",t),r.trigger("image-inserted")}).fail(function(t){o.fileUploadError("file-reader",t)}):o.fileUploadError("unsupported-file-type",a.type)})},p=function(t,e){m(),document.queryCommandSupported("hiliteColor")&&document.execCommand("hiliteColor",!1,e||"transparent"),u(),t.data(o.selectionMarker,e)},g=function(e,n){e.find(i).click(function(){m(),r.focus(),"html"===t(this).data(n.commandRole)?h():s(t(this).data(n.commandRole)),u()}),e.find("[data-toggle=dropdown]").click(m),e.find("input[type=text][data-"+n.commandRole+"]").on("webkitspeechchange change",function(){var e=this.value;this.value="",m(),e&&(r.focus(),s(t(this).data(n.commandRole),e)),u()}).on("focus",function(){var e=t(this);e.data(n.selectionMarker)||(p(e,n.selectionColor),e.focus())}).on("blur",function(){var e=t(this);e.data(n.selectionMarker)&&p(e,!1)}),e.find("input[type=file][data-"+n.commandRole+"]").change(function(){m(),"file"===this.type&&this.files&&this.files.length>0&&f(this.files),u(),this.value=""})},y=function(){r.on("dragenter dragover",!1).on("drop",function(t){var e=t.originalEvent.dataTransfer;t.stopPropagation(),t.preventDefault(),e&&e.files&&e.files.length>0&&f(e.files)})};return o=t.extend(!0,{},t.fn.wysiwyg.defaults,n),i="a[data-"+o.commandRole+"],button[data-"+o.commandRole+"],input[type=button][data-"+o.commandRole+"]",d(o.hotKeys),""!==t(this).attr("placeholder")&&(t(this).addClass("placeholderText"),t(this).html(t(this).attr("placeholder")),t(this).bind("focus",function(){""!==t(this).attr("placeholder")&&t(this).text()===t(this).attr("placeholder")&&(t(this).removeClass("placeholderText"),t(this).html(""))}),t(this).bind("blur",function(){""!==t(this).attr("placeholder")&&""===t(this).text()&&(t(this).addClass("placeholderText"),t(this).html(t(this).attr("placeholder")))})),o.dragAndDropImages&&y(),g(t(o.toolbarSelector),o),r.attr("contenteditable",!0).on("mouseup keyup mouseout",function(){u(),l()}),t(window).bind("touchend",function(t){var e=r.is(t.target)||r.has(t.target).length>0,n=c(),a=n&&n.startContainer===n.endContainer&&n.startOffset===n.endOffset;(!a||e)&&(u(),l())}),this},t.fn.wysiwyg.defaults={hotKeys:{"Ctrl+b meta+b":"bold","Ctrl+i meta+i":"italic","Ctrl+u meta+u":"underline","Ctrl+z":"undo","Ctrl+y meta+y meta+shift+z":"redo","Ctrl+l meta+l":"justifyleft","Ctrl+r meta+r":"justifyright","Ctrl+e meta+e":"justifycenter","Ctrl+j meta+j":"justifyfull","Shift+tab":"outdent",tab:"indent"},toolbarSelector:"[data-role=editor-toolbar]",commandRole:"edit",activeToolbarClass:"btn-info",selectionMarker:"edit-focus-marker",selectionColor:"darkgrey",dragAndDropImages:!0,keypressTimeout:200,fileUploadError:function(t,e){console.log("File upload error",t,e)}}}(window.jQuery);
\ No newline at end of file
+!function(t){"use strict";var e=function(e){var n=t.Deferred(),a=new FileReader;return a.onload=function(t){n.resolve(t.target.result)},a.onerror=n.reject,a.onprogress=n.notify,a.readAsDataURL(e),n.promise()};t.fn.cleanHtml=function(e){if(t(this).data("wysiwyg-html-mode")===!0&&(t(this).html(t(this).text()),t(this).attr("contenteditable",!0),t(this).data("wysiwyg-html-mode",!1)),e===!0&&t(this).parent().is("form")){var n=t(this).html;if(t(n).has("img").length){var a=t("img",t(n)),o=[],i=t(this).parent();t.each(a,function(e,n){t(n).attr("src").match(/^data:image\/.*$/)&&(o.push(a[e]),t(i).prepend(""),t(n).attr("src","postedimage/"+e))})}}var r=t(this).html();return r&&r.replace(/(
|\s|

<\/div>| )*$/,"")},t.fn.wysiwyg=function(n){var a,o,i,r=this,l=function(){o.activeToolbarClass&&t(o.toolbarSelector).find(i).each(function(){var e=t(this).data(o.commandRole).split(" "),n=e[0];e.length>1&&document.queryCommandEnabled(n)&&document.queryCommandValue(n)===e[1]?t(this).addClass(o.activeToolbarClass):1===e.length&&document.queryCommandEnabled(n)&&document.queryCommandState(n)?t(this).addClass(o.activeToolbarClass):t(this).removeClass(o.activeToolbarClass)})},s=function(t,e){var n=t.split(" "),a=n.shift(),o=n.join(" ")+(e||""),i=t.split("-");1===i.length?document.execCommand(a,!1,o):"format"===i[0]&&2===i.length&&document.execCommand("formatBlock",!1,i[1]),r.trigger("change"),l()},d=function(e){t.each(e,function(t,e){r.keydown(t,function(t){r.attr("contenteditable")&&r.is(":visible")&&(t.preventDefault(),t.stopPropagation(),s(e))}).keyup(t,function(t){r.attr("contenteditable")&&r.is(":visible")&&(t.preventDefault(),t.stopPropagation())})}),r.keyup(function(){r.trigger("change")})},c=function(){var t,e;return window.getSelection?(t=window.getSelection(),t.getRangeAt&&t.rangeCount&&(e=t.getRangeAt(0))):document.selection&&(e=document.selection.createRange()),e},u=function(){a=c()},m=function(){var t;if(window.getSelection||document.createRange){if(t=window.getSelection(),a){try{t.removeAllRanges()}catch(e){document.body.createTextRange().select(),document.selection.empty()}t.addRange(a)}}else document.selection&&a&&a.select()},f=function(){if(t(r).data("wysiwyg-html-mode")!==!0){var e=t(r).html(),n=t("
");t(n).append(document.createTextNode(e)),t(n).attr("contenteditable",!0),t(r).html(" "),t(r).append(t(n)),t(r).attr("contenteditable",!1),t(r).data("wysiwyg-html-mode",!0),t(n).focus()}else t(r).html(t(r).text()),t(r).attr("contenteditable",!0),t(r).data("wysiwyg-html-mode",!1),t(r).focus()},h=function(n){r.focus(),t.each(n,function(n,a){/^image\//.test(a.type)?t.when(e(a)).done(function(t){s("insertimage",t),r.trigger("image-inserted")}).fail(function(t){o.fileUploadError("file-reader",t)}):o.fileUploadError("unsupported-file-type",a.type)})},g=function(t,e){m(),document.queryCommandSupported("hiliteColor")&&document.execCommand("hiliteColor",!1,e||"transparent"),u(),t.data(o.selectionMarker,e)},p=function(e,n){e.find(i).click(function(){m(),r.focus(),"html"===t(this).data(n.commandRole)?f():s(t(this).data(n.commandRole)),u()}),e.find("[data-toggle=dropdown]").click(m),e.find("input[type=text][data-"+n.commandRole+"]").on("webkitspeechchange change",function(){var e=this.value;this.value="",m(),e&&(r.focus(),s(t(this).data(n.commandRole),e)),u()}).on("focus",function(){var e=t(this);e.data(n.selectionMarker)||(g(e,n.selectionColor),e.focus())}).on("blur",function(){var e=t(this);e.data(n.selectionMarker)&&g(e,!1)}),e.find("input[type=file][data-"+n.commandRole+"]").change(function(){m(),"file"===this.type&&this.files&&this.files.length>0&&h(this.files),u(),this.value=""})},y=function(){r.on("dragenter dragover",!1).on("drop",function(t){var e=t.originalEvent.dataTransfer;t.stopPropagation(),t.preventDefault(),e&&e.files&&e.files.length>0&&h(e.files)})};o=t.extend(!0,{},t.fn.wysiwyg.defaults,n),i="a[data-"+o.commandRole+"],button[data-"+o.commandRole+"],input[type=button][data-"+o.commandRole+"]",d(o.hotKeys);var v=t(this).attr("placeholder");return""!==v&&(""!==v&&""===t(this).text()&&(t(this).addClass("placeholderText"),t(this).html(v)),t(this).bind("focus",function(){""!==v&&t(this).text()===v&&(t(this).removeClass("placeholderText"),t(this).html(""))}),t(this).bind("blur",function(){""!==v&&""===t(this).text()&&(t(this).addClass("placeholderText"),t(this).html(v))})),o.dragAndDropImages&&y(),p(t(o.toolbarSelector),o),r.attr("contenteditable",!0).on("mouseup keyup mouseout",function(){u(),l()}),t(window).bind("touchend",function(t){var e=r.is(t.target)||r.has(t.target).length>0,n=c(),a=n&&n.startContainer===n.endContainer&&n.startOffset===n.endOffset;a&&!e||(u(),l())}),this},t.fn.wysiwyg.defaults={hotKeys:{"Ctrl+b meta+b":"bold","Ctrl+i meta+i":"italic","Ctrl+u meta+u":"underline","Ctrl+z":"undo","Ctrl+y meta+y meta+shift+z":"redo","Ctrl+l meta+l":"justifyleft","Ctrl+r meta+r":"justifyright","Ctrl+e meta+e":"justifycenter","Ctrl+j meta+j":"justifyfull","Shift+tab":"outdent",tab:"indent"},toolbarSelector:"[data-role=editor-toolbar]",commandRole:"edit",activeToolbarClass:"btn-info",selectionMarker:"edit-focus-marker",selectionColor:"darkgrey",dragAndDropImages:!0,keypressTimeout:200,fileUploadError:function(t,e){console.log("File upload error",t,e)}}}(window.jQuery);
\ No newline at end of file
diff --git a/package.json b/package.json
index 24a3a0f..ba0a11c 100644
--- a/package.json
+++ b/package.json
@@ -10,26 +10,35 @@
     {
       "name": "Tyler Hughes",
       "url": "https://github.com/RandomlyKnighted"
+    },
+    {
+      "name": "Rory Hunter",
+      "url": "https://github.com/pugnascotia"
     }
   ],
+  "scripts": {
+    "postinstall": "bower install",
+    "build": "gulp"
+  },
   "dependencies": {},
   "devDependencies": {
+    "bower": "^1.7.9",
     "check-pages": "^0.9.0",
     "grunt": "^0.4.5",
     "grunt-bootlint": "^0.9.1",
     "grunt-bumpup": "^0.6.2",
     "grunt-check-pages": "^0.9.0",
-    "grunt-contrib-jshint": "^0.11.2",
-    "grunt-contrib-rename": "^0.0.3",
-    "grunt-contrib-uglify": "^0.9.1",
+    "grunt-contrib-jshint": "^0.11.3",
+    "grunt-contrib-rename": "0.0.3",
+    "grunt-contrib-uglify": "^0.10.0",
     "grunt-contrib-watch": "^0.6.1",
     "grunt-release": "^0.13.0",
     "gulp": "^3.9.0",
-    "gulp-bootlint": "^0.5.0",
+    "gulp-bootlint": "^0.6.4",
     "gulp-html5-lint": "^1.0.1",
-    "gulp-jshint": "^1.11.0",
+    "gulp-jshint": "^1.11.2",
     "gulp-rename": "^1.2.2",
-    "gulp-uglify": "^1.2.0"
+    "gulp-uglify": "^1.4.2"
   },
   "repository": {
     "type": "git",
diff --git a/src/bootstrap-wysiwyg.js b/src/bootstrap-wysiwyg.js
index 61ae23b..d5c742b 100644
--- a/src/bootstrap-wysiwyg.js
+++ b/src/bootstrap-wysiwyg.js
@@ -243,19 +243,24 @@
 		bindHotkeys(options.hotKeys);
 
 		// Support placeholder attribute on the DIV
-		if ($(this).attr('placeholder') !== '') {
-			$(this).addClass('placeholderText');
-			$(this).html($(this).attr('placeholder'));
+		var placeholder = $(this).attr('placeholder');
+
+		if (placeholder !== '') {
+			// Set iniitial state without trashing existing text.
+			if ( placeholder !== '' && $(this).text() === '' ) {
+				$(this).addClass('placeholderText');
+				$(this).html(placeholder);
+			}
 			$(this).bind('focus',function() {
-				if ( $(this).attr('placeholder') !== '' && $(this).text() === $(this).attr('placeholder') ) {
+				if (placeholder !== '' && $(this).text() === placeholder ) {
 					$(this).removeClass('placeholderText');
 					$(this).html('');
 				}
 			});
 			$(this).bind('blur',function() {
-				if ( $(this).attr('placeholder') !== '' && $(this).text() === '' ) {
+				if (placeholder !== '' && $(this).text() === '' ) {
 					$(this).addClass('placeholderText');
-					$(this).html($(this).attr('placeholder'));
+					$(this).html(placeholder);
 				}
 			});
 		}