diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..61236cc --- /dev/null +++ b/Makefile @@ -0,0 +1,16 @@ +.PHONY: clean dist run test + +build: + npm install + +clean: + rm -rf lib node_modules + +dist: + ./node_modules/requirejs/bin/r.js -o ./tools/build.conf.js + +run: + npm start + +test: + npm test diff --git a/bower.json b/bower.json index 88aa64c..75a920f 100644 --- a/bower.json +++ b/bower.json @@ -1,16 +1,16 @@ { "name": "streamhub-editor", - "version": "1.3.1", + "version": "1.3.2", "main": [ "./src/editor.js" ], "dependencies": { "cajon": "git://github.com/requirejs/cajon.git#0.1.11", "inherits": "git://github.com/Livefyre/inherits.git", - "streamhub-sdk": "git://github.com/Livefyre/streamhub-sdk.git#2.17.0", + "streamhub-sdk": "git://github.com/Livefyre/streamhub-sdk.git#2.21.3", "streamhub-ui": "git://github.com/Livefyre/streamhub-ui.git#0.1.3", "auth": "git://github.com/Livefyre/auth.git#0.4.0", - "livefyre-bootstrap": "git://github.com/Livefyre/livefyre-bootstrap.git#1.2.3", + "livefyre-bootstrap": "git://github.com/Livefyre/livefyre-bootstrap.git#1.3.4", "jquery": "1.10.2", "mustache": "2.2.0", "observer": "git://github.com/Livefyre/Observer.git#0.1.0", @@ -27,9 +27,10 @@ }, "resolutions": { "event-emitter": "0.1", - "livefyre-bootstrap": "v1.3.4", + "livefyre-bootstrap": "1.3.4", "view": "1.4", "auth": "0.4.0", - "base64": "~0.4.0" + "base64": "~0.4.0", + "streamhub-ui": "0.2.0" } } diff --git a/package.json b/package.json index 7822770..6e9891d 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "name": "Mark Doten", "email": "mark@livefyre.com" }, - "version": "1.3.1", + "version": "1.3.2", "dependencies": { "bower": "1.3.8" }, @@ -15,19 +15,16 @@ "http-server": "*", "less": "1.7", "less-middleware": "0.1.15", - "mocha-phantomjs": "3.1.6", - "mocha": "*", "phantomjs": "1.9.2-2", - "karma-script-launcher": "0.1.0", - "karma-chrome-launcher": "0.1.0", - "karma-firefox-launcher": "0.1.0", - "karma-html2js-preprocessor": "0.1.0", - "karma-cajon": "*", - "karma-phantomjs-launcher": "0.1.0", "karma": "0.10.5", - "karma-mocha": "0.1.0", - "karma-safari-launcher": "0.1.1", + "karma-cajon": "0.0.1", + "karma-coffee-preprocessor": "0.1.0", "karma-chai": "0.0.2", + "karma-mocha": "0.1.0", + "karma-mocha-reporter": "0.3.0", + "karma-phantomjs-launcher": "0.1.0", + "mocha": "1.18.2", + "mocha-phantomjs": "3.1.6", "requirejs": "2.1.9" }, "scripts": { diff --git a/src/javascript/main.js b/src/javascript/main.js index 629a548..8e010fa 100644 --- a/src/javascript/main.js +++ b/src/javascript/main.js @@ -346,11 +346,24 @@ Editor.prototype.showError = function (msg) { * @return {boolean} Whether the post data is valid or not. */ Editor.prototype.validate = function (data) { - if (!data.body) { + if (!this.validateBody(data.body)) { this.showError(this._i18n.ERRORS.BODY); return false; } return true; }; +/** + * Validate the body of a post. + * @param {string} body + * @return {boolean} + */ +Editor.prototype.validateBody = function (body) { + if (!body) { + return false; + } + // Ensure that the user hasn't just entered spaces and newlines. + return !/^(

\s*<\/p>)*$/.test(body); +}; + module.exports = Editor; diff --git a/src/styles/editor.css b/src/styles/editor.css new file mode 100644 index 0000000..7a2cc91 --- /dev/null +++ b/src/styles/editor.css @@ -0,0 +1 @@ +textarea.lf-editor-field,input.lf-editor-title,.lf-editor-resize{border:none;-webkit-border-radius:0;-moz-border-radius:0;-ms-border-radius:0;-o-border-radius:0;border-radius:0;-webkit-box-shadow:none;-moz-box-shadow:none;-ms-box-shadow:none;-o-box-shadow:none;box-shadow:none;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;-ms-box-sizing:border-box;-o-box-sizing:border-box;box-sizing:border-box;font:normal 15px/22px Georgia,"Times New Roman",serif;margin:0;max-height:200px;min-height:44px;outline:0;overflow:hidden;padding:0 30px;resize:none;vertical-align:top;width:100%;word-wrap:break-word}.lf-editor-resize{opacity:0;filter:alpha(opacity=0);-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";-moz-opacity:0;-khtml-opacity:0;-webkit-opacity:0;position:absolute;z-index:-1}.lf-editor-resize p{min-height:22px;line-height:22px;margin:0;padding:0}.lf-editor-error{background:#fff;border:1px solid #ccc;-webkit-border-radius:3px;-moz-border-radius:3px;-ms-border-radius:3px;-o-border-radius:3px;border-radius:3px;cursor:pointer;height:100%;left:-1px;opacity:0;filter:alpha(opacity=0);-ms-filter:"progid:DXImageTransform.Microsoft.Alpha(Opacity=0)";-moz-opacity:0;-khtml-opacity:0;-webkit-opacity:0;position:absolute;top:-1px;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;width:100%}.lf-editor-error a.lf-close{color:#999;border:1px solid transparent;color:#a2a5aa;cursor:pointer;display:inline-block;height:22px;line-height:22px;padding:0 6px;text-decoration:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;-o-user-select:none;user-select:none;position:absolute;right:10px;top:10px}.lf-editor-error a.lf-close:hover{background:#f7f7f5;border:1px solid #b7b8ba;-webkit-border-radius:3px;-moz-border-radius:3px;-ms-border-radius:3px;-o-border-radius:3px;border-radius:3px}.lf-editor-error a.lf-close:active{background:#eaeae8;border:1px solid #abacae;-webkit-border-radius:3px;-moz-border-radius:3px;-ms-border-radius:3px;-o-border-radius:3px;border-radius:3px;-webkit-box-shadow:inset 0 1px 2px 0 rgba(0,0,0,0.3);-moz-box-shadow:inset 0 1px 2px 0 rgba(0,0,0,0.3);-ms-box-shadow:inset 0 1px 2px 0 rgba(0,0,0,0.3);-o-box-shadow:inset 0 1px 2px 0 rgba(0,0,0,0.3);box-shadow:inset 0 1px 2px 0 rgba(0,0,0,0.3)}.lf-editor-error span{color:#666;display:block;font-family:"Helvetica Neue",Arial,Helvetica,Geneva,sans-serif;line-height:22px;margin:0 auto;text-align:center;position:relative;top:50%;-webkit-transform:translateY(-50%);-ms-transform:translateY(-50%);-o-transform:translateY(-50%);transform:translateY(-50%);width:70%}.content-editor-avatar{width:36px;height:36px}input.lf-editor-title::-ms-clear{display:none;height:0;width:0} \ No newline at end of file diff --git a/src/styles/editor.less b/src/styles/editor.less index 5aa53cd..d2614f3 100644 --- a/src/styles/editor.less +++ b/src/styles/editor.less @@ -95,3 +95,9 @@ input.lf-editor-title, width: 36px; height: 36px; } + +input.lf-editor-title::-ms-clear { + display: none; + height: 0; + width: 0; +} diff --git a/test/spec/editor.js b/test/spec/editor.js index d7b553f..6da16c6 100644 --- a/test/spec/editor.js +++ b/test/spec/editor.js @@ -56,6 +56,26 @@ describe('streamhub-editor', function() { expect(view.validate({body: 'test'})).to.be.true; }); + it('should validate the normalized html text from the textarea', function() { + view.showError = function(){}; + view.$textareaEl.val(''); + var obj = view.buildPostEventObj(); + expect(obj.body).to.equal('

'); + expect(view.validate(obj)).to.be.false; + view.$textareaEl.val('\n\n'); + obj = view.buildPostEventObj(); + expect(obj.body).to.equal('

'); + expect(view.validate(obj)).to.be.false; + view.$textareaEl.val('something'); + obj = view.buildPostEventObj(); + expect(obj.body).to.equal('

something

'); + expect(view.validate(obj)).to.be.true; + view.$textareaEl.val('\nsomething'); + obj = view.buildPostEventObj(); + expect(obj.body).to.equal('

something

'); + expect(view.validate(obj)).to.be.true; + }); + it('should reset blank field back to placeholder on blur in normal mode', function() { view.$textareaEl.val(''); view.$textareaEl.blur();