diff --git a/bower.json b/bower.json index 7f0a632b..b1c01525 100644 --- a/bower.json +++ b/bower.json @@ -36,10 +36,10 @@ "emitify": "~2.1.1", "findit": "^1.1.5", "menu": "~1.0.2", - "smalltalk": "^1.6.8", "promise-polyfill": "^5.2.0", "olark": "^1.0.0", "philip": "^1.3.3", - "jquery": "3.1.0" + "jquery": "3.1.0", + "smalltalk": "^2.0.0" } } diff --git a/lib/client/dialog.js b/lib/client/dialog.js index 77f7a7ad..c246c2f1 100644 --- a/lib/client/dialog.js +++ b/lib/client/dialog.js @@ -33,9 +33,7 @@ } this.alert = function(title, message) { - return smalltalk.alert(title, message, { - cancel: false - }); + return smalltalk.alert(title, message); }; this.prompt = function(title, message, value, options) { diff --git a/modules/philip/.bower.json b/modules/philip/.bower.json index 0974d4af..b8aac78f 100644 --- a/modules/philip/.bower.json +++ b/modules/philip/.bower.json @@ -33,7 +33,6 @@ "commit": "48670d1115fb983e7774fa6d0118736a697081fe" }, "_source": "https://github.com/coderaiser/domfs-philip.git", - "_target": "^1.3.4", - "_originalSource": "philip", - "_direct": true + "_target": "^1.3.3", + "_originalSource": "philip" } \ No newline at end of file diff --git a/modules/smalltalk/.bower.json b/modules/smalltalk/.bower.json index fd84a386..000be719 100644 --- a/modules/smalltalk/.bower.json +++ b/modules/smalltalk/.bower.json @@ -1,6 +1,5 @@ { "name": "smalltalk", - "version": "1.6.8", "homepage": "https://github.com/coderaiser/smalltalk", "authors": [ "coderaiser " @@ -20,22 +19,19 @@ "license": "MIT", "ignore": [ "**/.*", - "node_modules", - "bower_components", - "modules", - "test", - "tests", - "screen" + "screen", + "example" ], "dependencies": {}, - "_release": "1.6.8", + "version": "2.0.0", + "_release": "2.0.0", "_resolution": { "type": "version", - "tag": "v1.6.8", - "commit": "5987bdf6249185738eff1ce84486ceed866aa721" + "tag": "v2.0.0", + "commit": "55325c8ace27e53c002cb207981031a0adb083b7" }, "_source": "https://github.com/coderaiser/smalltalk.git", - "_target": "^1.6.8", + "_target": "^2.0.0", "_originalSource": "smalltalk", "_direct": true } \ No newline at end of file diff --git a/modules/smalltalk/ChangeLog b/modules/smalltalk/ChangeLog index 7c17f777..816d95f3 100644 --- a/modules/smalltalk/ChangeLog +++ b/modules/smalltalk/ChangeLog @@ -1,3 +1,28 @@ +2016.07.15, v2.0.0 + +feature: +- (npmignore) add +- (package) add legacy:index +- (smalltalk) hide all bu first +- (bower) ignore: clean +- (smalltalk) alert: rm options +- (package) lint: add eslint +- (smalltalk) src -> lib +- (gitignore) legacy +- (package) add bundle +- (example) add legacy +- (smalltalk) IIFE -> commonjs +- (jshint) esversion: 6 +- (package) redrun v5.0.0 +- (package) add lint +- (package) redrun v5.0.0 +- (package) stylelint-config-standard v10.0.0 +- (package) redrun v4.0.0 +- (package) watch v0.19.1 +- (package) stylelint-config-standard v9.0.0 +- (package) stylelint-config-standard v8.0.0 + + 2016.05.10, v1.6.8 feature: diff --git a/modules/smalltalk/README.md b/modules/smalltalk/README.md index 0b5800e7..ad17b7d8 100644 --- a/modules/smalltalk/README.md +++ b/modules/smalltalk/README.md @@ -27,15 +27,13 @@ for preventing of handling cancel event. } ``` -## smalltalk.alert(title, message [, options]) +## smalltalk.alert(title, message) ![Alert](https://raw.githubusercontent.com/coderaiser/smalltalk/master/screen/alert.png "Alert") ```js smalltalk.alert('Error', 'There was an error!').then(function() { console.log('ok'); -}, function() { - console.log('cancel'); }); ``` @@ -74,3 +72,4 @@ MIT [BuildStatusURL]: https://travis-ci.org/coderaiser/smalltalk "Build Status" [DependencyStatusURL]: https://gemnasium.com/coderaiser/smalltalk "Dependency Status" [LicenseURL]: https://tldrlegal.com/license/mit-license "MIT License" + diff --git a/modules/smalltalk/bower.json b/modules/smalltalk/bower.json index caf1d836..385c23db 100644 --- a/modules/smalltalk/bower.json +++ b/modules/smalltalk/bower.json @@ -1,6 +1,5 @@ { "name": "smalltalk", - "version": "1.6.8", "homepage": "https://github.com/coderaiser/smalltalk", "authors": [ "coderaiser " @@ -20,12 +19,8 @@ "license": "MIT", "ignore": [ "**/.*", - "node_modules", - "bower_components", - "modules", - "test", - "tests", - "screen" + "screen", + "example" ], "dependencies": {} } diff --git a/modules/smalltalk/css/smalltalk.css b/modules/smalltalk/css/smalltalk.css index 55533970..0614b952 100644 --- a/modules/smalltalk/css/smalltalk.css +++ b/modules/smalltalk/css/smalltalk.css @@ -24,6 +24,10 @@ z-index: 100; } +.smalltalk + .smalltalk { + transition: ease 1s; + display: none; +} .smalltalk .page { border-radius: 3px; diff --git a/modules/smalltalk/dist/smalltalk.min.css b/modules/smalltalk/dist/smalltalk.min.css index 15265cc5..c0b36c41 100644 --- a/modules/smalltalk/dist/smalltalk.min.css +++ b/modules/smalltalk/dist/smalltalk.min.css @@ -1 +1 @@ -.smalltalk{display:-webkit-flex;display:-moz-box;display:-ms-flexbox;display:flex;align-items:center;flex-direction:column;justify-content:center;-webkit-transition:.2s opacity;-moz-transition:.2s opacity;-ms-transition:.2s opacity;-o-transition:.2s opacity;transition:.2s opacity;bottom:0;left:0;overflow:auto;padding:20px;position:fixed;right:0;top:0;z-index:100}.smalltalk .page .content-area,.smalltalk .page header{overflow:hidden;text-overflow:ellipsis;max-width:500px}.smalltalk .page{border-radius:3px;background:#fff;box-shadow:0 4px 23px 5px rgba(0,0,0,.2),0 2px 6px rgba(0,0,0,.15);color:#333;min-width:400px;padding:0;position:relative;z-index:0}@media only screen and (max-width:500px){.smalltalk .page{min-width:0}}.smalltalk .page>.close-button{background-image:url(../img/IDR_CLOSE_DIALOG.png);background-position:center;background-repeat:no-repeat;height:14px;position:absolute;right:7px;top:7px;width:14px;z-index:1}.smalltalk .page>.close-button:hover{background-image:url(../img/IDR_CLOSE_DIALOG_H.png)}.smalltalk .page header{white-space:nowrap;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;color:#333;font-size:120%;font-weight:700;margin:0;padding:14px 17px;text-shadow:#fff 0 1px 2px}.smalltalk .page .content-area{padding:6px 17px;position:relative}.smalltalk .page .action-area{padding:14px 17px}.smalltalk .page .button-strip{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:flex;flex-direction:row;justify-content:flex-end}.smalltalk .page .button-strip>button{-webkit-margin-start:10px;-moz-margin-start:10px;-ms-margin-start:10px}.smalltalk button:enabled:active{background-image:-webkit-linear-gradient(#e7e7e7,#e7e7e7 38%,#d7d7d7);background-image:-moz-linear-gradient(#e7e7e7,#e7e7e7 38%,#d7d7d7);background-image:-ms-linear-gradient(#e7e7e7,#e7e7e7 38%,#d7d7d7);background-image:linear-gradient(#e7e7e7,#e7e7e7 38%,#d7d7d7);box-shadow:none;text-shadow:none}.smalltalk .smalltalk,.smalltalk button{min-height:2em;min-width:4em}.smalltalk button::-moz-focus-inner{border:0}.smalltalk button{-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;appearance:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:-webkit-linear-gradient(#ededed,#ededed 38%,#dedede);background-image:-moz-linear-gradient(#ededed,#ededed 38%,#dedede);background-image:-ms-linear-gradient(#ededed,#ededed 38%,#dedede);background-image:linear-gradient(#ededed,#ededed 38%,#dedede);border:1px solid #000;border:1px solid rgba(0,0,0,.25);border-radius:2px;box-shadow:0 1px 0 rgba(0,0,0,.08),inset 0 1px 2px rgba(255,255,255,.75);color:#444;font:inherit;margin:0 1px 0 0;text-shadow:0 1px 0 #f0f0f0}.smalltalk button:enabled:focus,.smalltalk input:enabled:focus{-webkit-transition:border-color .2s;-moz-transition:border-color .2s;-ms-transition:border-color .2s;-o-transition:border-color .2s;transition:border-color .2s;border-color:#4d90fe;outline:0}.smalltalk input{width:100%;border:1px solid #bfbfbf;border-radius:2px;box-sizing:border-box;color:#444;font:inherit;margin:0;min-height:2em;padding:3px;outline:0}button{font-family:Ubuntu,Arial,sans-serif} +.smalltalk{display:-webkit-flex;display:-moz-box;display:-ms-flexbox;display:flex;align-items:center;flex-direction:column;justify-content:center;-webkit-transition:.2s opacity;-moz-transition:.2s opacity;-ms-transition:.2s opacity;-o-transition:.2s opacity;transition:.2s opacity;bottom:0;left:0;overflow:auto;padding:20px;position:fixed;right:0;top:0;z-index:100}.smalltalk .page .content-area,.smalltalk .page header{overflow:hidden;text-overflow:ellipsis;max-width:500px}.smalltalk+.smalltalk{transition:ease 1s;display:none}.smalltalk .page{border-radius:3px;background:#fff;box-shadow:0 4px 23px 5px rgba(0,0,0,.2),0 2px 6px rgba(0,0,0,.15);color:#333;min-width:400px;padding:0;position:relative;z-index:0}@media only screen and (max-width:500px){.smalltalk .page{min-width:0}}.smalltalk .page>.close-button{background-image:url(../img/IDR_CLOSE_DIALOG.png);background-position:center;background-repeat:no-repeat;height:14px;position:absolute;right:7px;top:7px;width:14px;z-index:1}.smalltalk .page>.close-button:hover{background-image:url(../img/IDR_CLOSE_DIALOG_H.png)}.smalltalk .page header{white-space:nowrap;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;color:#333;font-size:120%;font-weight:700;margin:0;padding:14px 17px;text-shadow:#fff 0 1px 2px}.smalltalk .page .content-area{padding:6px 17px;position:relative}.smalltalk .page .action-area{padding:14px 17px}.smalltalk .page .button-strip{display:-webkit-box;display:-moz-box;display:-ms-flexbox;display:flex;flex-direction:row;justify-content:flex-end}.smalltalk .page .button-strip>button{-webkit-margin-start:10px;-moz-margin-start:10px;-ms-margin-start:10px}.smalltalk button:enabled:active{background-image:-webkit-linear-gradient(#e7e7e7,#e7e7e7 38%,#d7d7d7);background-image:-moz-linear-gradient(#e7e7e7,#e7e7e7 38%,#d7d7d7);background-image:-ms-linear-gradient(#e7e7e7,#e7e7e7 38%,#d7d7d7);background-image:linear-gradient(#e7e7e7,#e7e7e7 38%,#d7d7d7);box-shadow:none;text-shadow:none}.smalltalk .smalltalk,.smalltalk button{min-height:2em;min-width:4em}.smalltalk button::-moz-focus-inner{border:0}.smalltalk button{-webkit-appearance:none;-moz-appearance:none;-ms-appearance:none;appearance:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background-image:-webkit-linear-gradient(#ededed,#ededed 38%,#dedede);background-image:-moz-linear-gradient(#ededed,#ededed 38%,#dedede);background-image:-ms-linear-gradient(#ededed,#ededed 38%,#dedede);background-image:linear-gradient(#ededed,#ededed 38%,#dedede);border:1px solid #000;border:1px solid rgba(0,0,0,.25);border-radius:2px;box-shadow:0 1px 0 rgba(0,0,0,.08),inset 0 1px 2px rgba(255,255,255,.75);color:#444;font:inherit;margin:0 1px 0 0;text-shadow:0 1px 0 #f0f0f0}.smalltalk button:enabled:focus,.smalltalk input:enabled:focus{-webkit-transition:border-color .2s;-moz-transition:border-color .2s;-ms-transition:border-color .2s;-o-transition:border-color .2s;transition:border-color .2s;border-color:#4d90fe;outline:0}.smalltalk input{width:100%;border:1px solid #bfbfbf;border-radius:2px;box-sizing:border-box;color:#444;font:inherit;margin:0;min-height:2em;padding:3px;outline:0}button{font-family:Ubuntu,Arial,sans-serif} diff --git a/modules/smalltalk/dist/smalltalk.min.js b/modules/smalltalk/dist/smalltalk.min.js index 96414fa3..dceeeb44 100644 --- a/modules/smalltalk/dist/smalltalk.min.js +++ b/modules/smalltalk/dist/smalltalk.min.js @@ -1 +1 @@ -"use strict";!function(n){function t(n){function e(n,t,e,r){if(!Array.isArray(r))throw Error("buttons should be array!");return'
\n
\n
'+n+'
\n
\n '+t+"\n "+e+'\n
\n
\n
'+r.map(function(n,t){return""}).join("")+"\n
\n
\n
"}function r(n,t,r,o,u){var c=document.createElement("div"),l=["cancel","close","ok"],d=void 0,v=void 0,p=new Promise(function(n,t){var e=u&&!u.cancel,r=function(){};d=n,v=t,e&&(v=r)}),m=e(n,t,r,o);return c.innerHTML=m,c.className="smalltalk",document.body.appendChild(c),f(c,["ok","input"]).forEach(function(n){return n.focus()}),f(c,["input"]).forEach(function(n){n.setSelectionRange(0,r.length)}),s("click",c,l,function(n){return i(n.target,c,d,v)}),["click","contextmenu"].forEach(function(n){return c.addEventListener(n,function(){return f(c,["ok","input"]).forEach(function(n){return n.focus()})})}),c.addEventListener("keydown",a(c,d,v)),p}function a(n,t,e){return function(r){var a={ENTER:13,ESC:27,TAB:9,LEFT:37,UP:38,RIGHT:39,DOWN:40},s=r.keyCode,l=r.target,d=["ok","cancel","input"],p=f(n,d).map(function(n){return o(n)});switch(s){case a.ENTER:i(l,n,t,e),r.preventDefault();break;case a.ESC:v(),e();break;case a.TAB:r.shiftKey&&c(n,p),c(n,p),r.preventDefault();break;default:var m=["left","right","up","down"].some(function(n){return s===a[n.toUpperCase()]});m&&u(n,p)}r.stopPropagation()}}function o(n){return n.getAttribute("data-name").replace("js-","")}function u(n,t){var e="",r=document.activeElement,a=o(r),u=/ok|cancel/.test(a),c=t.length-1;"input"!==a&&c&&u&&(e="cancel"===a?"ok":"cancel",f(n,[e]).forEach(function(n){return n.focus()}))}function c(n,t){var e=document.activeElement,r=o(e),a=t.length-1,u=t.indexOf(r);u===a?u=0:a>u&&++u;var c=t[u];f(n,[c]).forEach(function(n){return n.focus()})}function i(n,t,e,r){var a=void 0,o=n.getAttribute("data-name").replace("js-","");/close|cancel/.test(o)?r():(a=f(t,["input"]).reduce(function(n,t){return t.value},null),e(a)),v()}function f(n,t){var e=t.map(function(t){return n.querySelector('[data-name="js-'+t+'"]')}).filter(function(n){return n});return e}function s(n,t,e,r){f(t,e).forEach(function(t){return t.addEventListener(n,r)})}function l(n){var t=document.querySelector(n);t.parentElement.removeChild(t)}function d(n){for(var t=arguments.length,e=Array(t>1?t-1:0),r=1;t>r;r++)e[r-1]=arguments[r];return function(){return n.apply(void 0,e)}}if(!(this instanceof t))return new t(n);var v=d(l,".smalltalk"),p=["OK"],m=["OK","Cancel"];this.alert=function(n,t,e){return r(n,t,"",p,e)},this.prompt=function(n,t,e,a){var o=e||"",u='';return r(n,t,u,m,a)},this.confirm=function(n,t,e){return r(n,t,"",m,e)}}"undefined"!=typeof module&&module.exports?module.exports=t():n.smalltalk=t()}("undefined"!=typeof window&&window); +!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.smalltalk=n()}}(function(){return function n(e,t,r){function o(u,i){if(!t[u]){if(!e[u]){var c="function"==typeof require&&require;if(!i&&c)return c(u,!0);if(a)return a(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var l=t[u]={exports:{}};e[u][0].call(l.exports,function(n){var t=e[u][1][n];return o(t?t:n)},l,l.exports,n,e,t,r)}return t[u].exports}for(var a="function"==typeof require&&require,u=0;u\n
\n
'+n+'
\n
\n '+e+"\n "+t+'\n
\n
\n
'+r.map(function(n,e){return""}).join("")+"\n
\n
\n "}function o(n,e,t,o,u){var i=void 0,c=void 0,s=document.createElement("div"),p=["cancel","close","ok"],v=new Promise(function(n,e){var t=u&&!u.cancel,r=function(){};i=n,c=e,t&&(c=r)}),m=r(n,e,t,o);return s.innerHTML=m,s.className="smalltalk",document.body.appendChild(s),l(s,["ok","input"]).forEach(function(n){return n.focus()}),l(s,["input"]).forEach(function(n){n.setSelectionRange(0,t.length)}),d("click",s,p,function(n){return f(n.target,s,i,c)}),["click","contextmenu"].forEach(function(n){return s.addEventListener(n,function(){return l(s,["ok","input"]).forEach(function(n){return n.focus()})})}),s.addEventListener("keydown",a(s,i,c)),v}function a(n,e,t){return function(r){var o={ENTER:13,ESC:27,TAB:9,LEFT:37,UP:38,RIGHT:39,DOWN:40},a=r.keyCode,d=r.target,s=["ok","cancel","input"],p=l(n,s).map(function(n){return u(n)}),m=void 0;switch(a){case o.ENTER:f(d,n,e,t),r.preventDefault();break;case o.ESC:v(),t();break;case o.TAB:r.shiftKey&&c(n,p),c(n,p),r.preventDefault();break;default:m=["left","right","up","down"].some(function(n){return a===o[n.toUpperCase()]}),m&&i(n,p)}r.stopPropagation()}}function u(n){return n.getAttribute("data-name").replace("js-","")}function i(n,e){var t="",r=document.activeElement,o=u(r),a=/ok|cancel/.test(o),i=e.length-1;"input"!==o&&i&&a&&(t="cancel"===o?"ok":"cancel",l(n,[t]).forEach(function(n){n.focus()}))}function c(n,e){var t=document.activeElement,r=u(t),o=e.length-1,a=e.indexOf(r);a===o?a=0:a1?e-1:0),r=1;r';return o(n,e,u,E,r)},t.confirm=function(n,e,t){return o(n,e,"",E,t)}},{}]},{},["smalltalk"])("smalltalk")}); diff --git a/modules/smalltalk/dist/smalltalk.native.min.js b/modules/smalltalk/dist/smalltalk.native.min.js index 82ffbb1f..61082ba2 100644 --- a/modules/smalltalk/dist/smalltalk.native.min.js +++ b/modules/smalltalk/dist/smalltalk.native.min.js @@ -1 +1 @@ -"use strict";!function(n){function e(){return this instanceof e?(this.alert=function(n,e){var t=new Promise(function(n){alert(e),n()});return t},this.prompt=function(n,e,t,o){var r=o,i=new Promise(function(n,o){var i=r&&!r.cancel,u=prompt(e,t);null!==u?n(u):i||o()});return i},void(this.confirm=function(n,e,t){var o=t,r=o&&!o.noCancel,i=new Promise(function(n,t){var o=confirm(e);o?n():r||t()});return i})):new e}"undefined"!=typeof module&&module.exports?module.exports=e():n.smalltalk=e()}("undefined"!=typeof window&&window); +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.smalltalk=e()}}(function(){return function e(n,r,t){function o(i,u){if(!r[i]){if(!n[i]){var l="function"==typeof require&&require;if(!u&&l)return l(i,!0);if(f)return f(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var c=r[i]={exports:{}};n[i][0].call(c.exports,function(e){var r=n[i][1][e];return o(r?r:e)},c,c.exports,e,n,r,t)}return r[i].exports}for(var f="function"==typeof require&&require,i=0;it;t++)r(e,e._deferreds[t]);e._deferreds=null}function c(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}function s(e,t){var n=!1;try{e(function(e){n||(n=!0,i(t,e))},function(e){n||(n=!0,f(t,e))})}catch(o){if(n)return;n=!0,f(t,o)}}var l=setTimeout,a="function"==typeof setImmediate&&setImmediate||function(e){l(e,1)},d=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};o.prototype["catch"]=function(e){return this.then(null,e)},o.prototype.then=function(e,n){var i=new o(t);return r(this,new c(e,n,i)),i},o.all=function(e){var t=Array.prototype.slice.call(e);return new o(function(e,n){function o(i,f){try{if(f&&("object"==typeof f||"function"==typeof f)){var u=f.then;if("function"==typeof u)return void u.call(f,function(e){o(i,e)},n)}t[i]=f,0===--r&&e(t)}catch(c){n(c)}}if(0===t.length)return e([]);for(var r=t.length,i=0;io;o++)e[o].then(t,n)})},o._setImmediateFn=function(e){a=e},o._setUnhandledRejectionFn=function(e){d=e},"undefined"!=typeof module&&module.exports?module.exports=o:e.Promise||(e.Promise=o)}(this);"use strict";!function(n){function e(){return this instanceof e?(this.alert=function(n,e){var t=new Promise(function(n){alert(e),n()});return t},this.prompt=function(n,e,t,o){var r=o,i=new Promise(function(n,o){var i=r&&!r.cancel,u=prompt(e,t);null!==u?n(u):i||o()});return i},void(this.confirm=function(n,e,t){var o=t,r=o&&!o.noCancel,i=new Promise(function(n,t){var o=confirm(e);o?n():r||t()});return i})):new e}"undefined"!=typeof module&&module.exports?module.exports=e():n.smalltalk=e()}("undefined"!=typeof window&&window); +!function(t){function e(){}function n(t,e){return function(){t.apply(e,arguments)}}function o(t){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],s(t,this)}function r(t,e){for(;3===t._state;)t=t._value;return 0===t._state?void t._deferreds.push(e):(t._handled=!0,void a(function(){var n=1===t._state?e.onFulfilled:e.onRejected;if(null===n)return void(1===t._state?i:f)(e.promise,t._value);var o;try{o=n(t._value)}catch(r){return void f(e.promise,r)}i(e.promise,o)}))}function i(t,e){try{if(e===t)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var r=e.then;if(e instanceof o)return t._state=3,t._value=e,void u(t);if("function"==typeof r)return void s(n(r,e),t)}t._state=1,t._value=e,u(t)}catch(i){f(t,i)}}function f(t,e){t._state=2,t._value=e,u(t)}function u(t){2===t._state&&0===t._deferreds.length&&a(function(){t._handled||d(t._value)});for(var e=0,n=t._deferreds.length;n>e;e++)r(t,t._deferreds[e]);t._deferreds=null}function c(t,e,n){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof e?e:null,this.promise=n}function s(t,e){var n=!1;try{t(function(t){n||(n=!0,i(e,t))},function(t){n||(n=!0,f(e,t))})}catch(o){if(n)return;n=!0,f(e,o)}}var l=setTimeout,a="function"==typeof setImmediate&&setImmediate||function(t){l(t,0)},d=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)};o.prototype["catch"]=function(t){return this.then(null,t)},o.prototype.then=function(t,n){var o=new this.constructor(e);return r(this,new c(t,n,o)),o},o.all=function(t){var e=Array.prototype.slice.call(t);return new o(function(t,n){function o(i,f){try{if(f&&("object"==typeof f||"function"==typeof f)){var u=f.then;if("function"==typeof u)return void u.call(f,function(t){o(i,t)},n)}e[i]=f,0===--r&&t(e)}catch(c){n(c)}}if(0===e.length)return t([]);for(var r=e.length,i=0;io;o++)t[o].then(e,n)})},o._setImmediateFn=function(t){a=t},o._setUnhandledRejectionFn=function(t){d=t},"undefined"!=typeof module&&module.exports?module.exports=o:t.Promise||(t.Promise=o)}(this);!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.smalltalk=e()}}(function(){return function e(n,r,t){function o(i,u){if(!r[i]){if(!n[i]){var l="function"==typeof require&&require;if(!u&&l)return l(i,!0);if(f)return f(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var c=r[i]={exports:{}};n[i][0].call(c.exports,function(e){var r=n[i][1][e];return o(r?r:e)},c,c.exports,e,n,r,t)}return r[i].exports}for(var f="function"==typeof require&&require,i=0;it;t++)r(e,e._deferreds[t]);e._deferreds=null}function c(e,t,n){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.promise=n}function s(e,t){var n=!1;try{e(function(e){n||(n=!0,i(t,e))},function(e){n||(n=!0,f(t,e))})}catch(o){if(n)return;n=!0,f(t,o)}}var l=setTimeout,a="function"==typeof setImmediate&&setImmediate||function(e){l(e,1)},d=function(e){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",e)};o.prototype["catch"]=function(e){return this.then(null,e)},o.prototype.then=function(e,n){var i=new o(t);return r(this,new c(e,n,i)),i},o.all=function(e){var t=Array.prototype.slice.call(e);return new o(function(e,n){function o(i,f){try{if(f&&("object"==typeof f||"function"==typeof f)){var u=f.then;if("function"==typeof u)return void u.call(f,function(e){o(i,e)},n)}t[i]=f,0===--r&&e(t)}catch(c){n(c)}}if(0===t.length)return e([]);for(var r=t.length,i=0;io;o++)e[o].then(t,n)})},o._setImmediateFn=function(e){a=e},o._setUnhandledRejectionFn=function(e){d=e},"undefined"!=typeof module&&module.exports?module.exports=o:e.Promise||(e.Promise=o)}(this);"use strict";!function(n){function t(n){function e(n,t,e,r){if(!Array.isArray(r))throw Error("buttons should be array!");return'
\n
\n
'+n+'
\n
\n '+t+"\n "+e+'\n
\n
\n
'+r.map(function(n,t){return""}).join("")+"\n
\n
\n
"}function r(n,t,r,o,u){var c=document.createElement("div"),l=["cancel","close","ok"],d=void 0,v=void 0,p=new Promise(function(n,t){var e=u&&!u.cancel,r=function(){};d=n,v=t,e&&(v=r)}),m=e(n,t,r,o);return c.innerHTML=m,c.className="smalltalk",document.body.appendChild(c),f(c,["ok","input"]).forEach(function(n){return n.focus()}),f(c,["input"]).forEach(function(n){n.setSelectionRange(0,r.length)}),s("click",c,l,function(n){return i(n.target,c,d,v)}),["click","contextmenu"].forEach(function(n){return c.addEventListener(n,function(){return f(c,["ok","input"]).forEach(function(n){return n.focus()})})}),c.addEventListener("keydown",a(c,d,v)),p}function a(n,t,e){return function(r){var a={ENTER:13,ESC:27,TAB:9,LEFT:37,UP:38,RIGHT:39,DOWN:40},s=r.keyCode,l=r.target,d=["ok","cancel","input"],p=f(n,d).map(function(n){return o(n)});switch(s){case a.ENTER:i(l,n,t,e),r.preventDefault();break;case a.ESC:v(),e();break;case a.TAB:r.shiftKey&&c(n,p),c(n,p),r.preventDefault();break;default:var m=["left","right","up","down"].some(function(n){return s===a[n.toUpperCase()]});m&&u(n,p)}r.stopPropagation()}}function o(n){return n.getAttribute("data-name").replace("js-","")}function u(n,t){var e="",r=document.activeElement,a=o(r),u=/ok|cancel/.test(a),c=t.length-1;"input"!==a&&c&&u&&(e="cancel"===a?"ok":"cancel",f(n,[e]).forEach(function(n){return n.focus()}))}function c(n,t){var e=document.activeElement,r=o(e),a=t.length-1,u=t.indexOf(r);u===a?u=0:a>u&&++u;var c=t[u];f(n,[c]).forEach(function(n){return n.focus()})}function i(n,t,e,r){var a=void 0,o=n.getAttribute("data-name").replace("js-","");/close|cancel/.test(o)?r():(a=f(t,["input"]).reduce(function(n,t){return t.value},null),e(a)),v()}function f(n,t){var e=t.map(function(t){return n.querySelector('[data-name="js-'+t+'"]')}).filter(function(n){return n});return e}function s(n,t,e,r){f(t,e).forEach(function(t){return t.addEventListener(n,r)})}function l(n){var t=document.querySelector(n);t.parentElement.removeChild(t)}function d(n){for(var t=arguments.length,e=Array(t>1?t-1:0),r=1;t>r;r++)e[r-1]=arguments[r];return function(){return n.apply(void 0,e)}}if(!(this instanceof t))return new t(n);var v=d(l,".smalltalk"),p=["OK"],m=["OK","Cancel"];this.alert=function(n,t,e){return r(n,t,"",p,e)},this.prompt=function(n,t,e,a){var o=e||"",u='';return r(n,t,u,m,a)},this.confirm=function(n,t,e){return r(n,t,"",m,e)}}"undefined"!=typeof module&&module.exports?module.exports=t():n.smalltalk=t()}("undefined"!=typeof window&&window); +!function(t){function e(){}function n(t,e){return function(){t.apply(e,arguments)}}function o(t){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],s(t,this)}function r(t,e){for(;3===t._state;)t=t._value;return 0===t._state?void t._deferreds.push(e):(t._handled=!0,void a(function(){var n=1===t._state?e.onFulfilled:e.onRejected;if(null===n)return void(1===t._state?i:f)(e.promise,t._value);var o;try{o=n(t._value)}catch(r){return void f(e.promise,r)}i(e.promise,o)}))}function i(t,e){try{if(e===t)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var r=e.then;if(e instanceof o)return t._state=3,t._value=e,void u(t);if("function"==typeof r)return void s(n(r,e),t)}t._state=1,t._value=e,u(t)}catch(i){f(t,i)}}function f(t,e){t._state=2,t._value=e,u(t)}function u(t){2===t._state&&0===t._deferreds.length&&a(function(){t._handled||d(t._value)});for(var e=0,n=t._deferreds.length;n>e;e++)r(t,t._deferreds[e]);t._deferreds=null}function c(t,e,n){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof e?e:null,this.promise=n}function s(t,e){var n=!1;try{t(function(t){n||(n=!0,i(e,t))},function(t){n||(n=!0,f(e,t))})}catch(o){if(n)return;n=!0,f(e,o)}}var l=setTimeout,a="function"==typeof setImmediate&&setImmediate||function(t){l(t,0)},d=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)};o.prototype["catch"]=function(t){return this.then(null,t)},o.prototype.then=function(t,n){var o=new this.constructor(e);return r(this,new c(t,n,o)),o},o.all=function(t){var e=Array.prototype.slice.call(t);return new o(function(t,n){function o(i,f){try{if(f&&("object"==typeof f||"function"==typeof f)){var u=f.then;if("function"==typeof u)return void u.call(f,function(t){o(i,t)},n)}e[i]=f,0===--r&&t(e)}catch(c){n(c)}}if(0===e.length)return t([]);for(var r=e.length,i=0;io;o++)t[o].then(e,n)})},o._setImmediateFn=function(t){a=t},o._setUnhandledRejectionFn=function(t){d=t},"undefined"!=typeof module&&module.exports?module.exports=o:t.Promise||(t.Promise=o)}(this);!function(n){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=n();else if("function"==typeof define&&define.amd)define([],n);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.smalltalk=n()}}(function(){return function n(e,t,r){function o(u,i){if(!t[u]){if(!e[u]){var c="function"==typeof require&&require;if(!i&&c)return c(u,!0);if(a)return a(u,!0);var f=new Error("Cannot find module '"+u+"'");throw f.code="MODULE_NOT_FOUND",f}var l=t[u]={exports:{}};e[u][0].call(l.exports,function(n){var t=e[u][1][n];return o(t?t:n)},l,l.exports,n,e,t,r)}return t[u].exports}for(var a="function"==typeof require&&require,u=0;u\n
\n
'+n+'
\n
\n '+e+"\n "+t+'\n
\n
\n
'+r.map(function(n,e){return""}).join("")+"\n
\n
\n "}function o(n,e,t,o,u){var i=void 0,c=void 0,s=document.createElement("div"),p=["cancel","close","ok"],v=new Promise(function(n,e){var t=u&&!u.cancel,r=function(){};i=n,c=e,t&&(c=r)}),m=r(n,e,t,o);return s.innerHTML=m,s.className="smalltalk",document.body.appendChild(s),l(s,["ok","input"]).forEach(function(n){return n.focus()}),l(s,["input"]).forEach(function(n){n.setSelectionRange(0,t.length)}),d("click",s,p,function(n){return f(n.target,s,i,c)}),["click","contextmenu"].forEach(function(n){return s.addEventListener(n,function(){return l(s,["ok","input"]).forEach(function(n){return n.focus()})})}),s.addEventListener("keydown",a(s,i,c)),v}function a(n,e,t){return function(r){var o={ENTER:13,ESC:27,TAB:9,LEFT:37,UP:38,RIGHT:39,DOWN:40},a=r.keyCode,d=r.target,s=["ok","cancel","input"],p=l(n,s).map(function(n){return u(n)}),m=void 0;switch(a){case o.ENTER:f(d,n,e,t),r.preventDefault();break;case o.ESC:v(),t();break;case o.TAB:r.shiftKey&&c(n,p),c(n,p),r.preventDefault();break;default:m=["left","right","up","down"].some(function(n){return a===o[n.toUpperCase()]}),m&&i(n,p)}r.stopPropagation()}}function u(n){return n.getAttribute("data-name").replace("js-","")}function i(n,e){var t="",r=document.activeElement,o=u(r),a=/ok|cancel/.test(o),i=e.length-1;"input"!==o&&i&&a&&(t="cancel"===o?"ok":"cancel",l(n,[t]).forEach(function(n){n.focus()}))}function c(n,e){var t=document.activeElement,r=u(t),o=e.length-1,a=e.indexOf(r);a===o?a=0:a1?e-1:0),r=1;r';return o(n,e,u,E,r)},t.confirm=function(n,e,t){return o(n,e,"",E,t)}},{}]},{},["smalltalk"])("smalltalk")}); diff --git a/modules/smalltalk/example/index.html b/modules/smalltalk/example/index.html deleted file mode 100644 index 1bd3e1a4..00000000 --- a/modules/smalltalk/example/index.html +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - diff --git a/modules/smalltalk/lib/smalltalk.js b/modules/smalltalk/lib/smalltalk.js index 3cfd3441..d5c85e5b 100644 --- a/modules/smalltalk/lib/smalltalk.js +++ b/modules/smalltalk/lib/smalltalk.js @@ -1,221 +1,242 @@ 'use strict'; -(function (global) { - 'use strict'; +const remove = bind(removeEl, '.smalltalk'); - if (typeof module !== 'undefined' && module.exports) module.exports = SmallTalk();else global.smalltalk = SmallTalk(); +const BUTTON_OK = ['OK']; +const BUTTON_OK_CANCEL = ['OK', 'Cancel']; + +exports.alert = (title, msg) => { + return showDialog(title, msg, '', BUTTON_OK, {cancel: false}); +}; - function SmallTalk(callback) { - if (!(this instanceof SmallTalk)) return new SmallTalk(callback); +exports.prompt = (title, msg, value, options) => { + const val = value || ''; + const valueStr = ``; + + return showDialog(title, msg, valueStr, BUTTON_OK_CANCEL, options); +}; - var remove = bind(removeEl, '.smalltalk'); +exports.confirm = (title, msg, options) => { + return showDialog(title, msg, '', BUTTON_OK_CANCEL, options); +}; - var BUTTON_OK = ['OK']; - var BUTTON_OK_CANCEL = ['OK', 'Cancel']; - - this.alert = function (title, msg, options) { - return showDialog(title, msg, '', BUTTON_OK, options); - }; - - this.prompt = function (title, msg, value, options) { - var val = value || ''; - var valueStr = ''; - - return showDialog(title, msg, valueStr, BUTTON_OK_CANCEL, options); - }; - - this.confirm = function (title, msg, options) { - return showDialog(title, msg, '', BUTTON_OK_CANCEL, options); - }; - - function getTemplate(title, msg, value, buttons) { - if (!Array.isArray(buttons)) throw Error('buttons should be array!'); - - return '
\n
\n
' + title + '
\n
\n ' + msg + '\n ' + value + '\n
\n
\n
' + buttons.map(function (name, i) { - return ''; - }).join('') + '\n
\n
\n
'; - } - - function showDialog(title, msg, value, buttons, options) { - var dialog = document.createElement('div'), - closeButtons = ['cancel', 'close', 'ok'], - ok = undefined, - cancel = undefined, - promise = new Promise(function (resolve, reject) { - var noCancel = options && !options.cancel; - var empty = function empty() {}; - - ok = resolve; - cancel = reject; - - if (noCancel) cancel = empty; - }), - tmpl = getTemplate(title, msg, value, buttons); - - dialog.innerHTML = tmpl; - dialog.className = 'smalltalk'; - - document.body.appendChild(dialog); - - find(dialog, ['ok', 'input']).forEach(function (el) { - return el.focus(); - }); - - find(dialog, ['input']).forEach(function (el) { - el.setSelectionRange(0, value.length); - }); - - addListeterAll('click', dialog, closeButtons, function (event) { - return closeDialog(event.target, dialog, ok, cancel); - }); - - ['click', 'contextmenu'].forEach(function (event) { - return dialog.addEventListener(event, function () { - return find(dialog, ['ok', 'input']).forEach(function (el) { - return el.focus(); - }); - }); - }); - - dialog.addEventListener('keydown', keyDown(dialog, ok, cancel)); - - return promise; - } - - function keyDown(dialog, ok, cancel) { - return function (event) { - var KEY = { - ENTER: 13, - ESC: 27, - TAB: 9, - LEFT: 37, - UP: 38, - RIGHT: 39, - DOWN: 40 - }; - - var keyCode = event.keyCode, - el = event.target; - - var namesAll = ['ok', 'cancel', 'input'], - names = find(dialog, namesAll).map(function (el) { - return getDataName(el); - }); - - switch (keyCode) { - case KEY.ENTER: - closeDialog(el, dialog, ok, cancel); - event.preventDefault(); - break; - - case KEY.ESC: - remove(); - cancel(); - break; - - case KEY.TAB: - if (event.shiftKey) tab(dialog, names); - - tab(dialog, names); - event.preventDefault(); - break; - - default: - var is = ['left', 'right', 'up', 'down'].some(function (name) { - return keyCode === KEY[name.toUpperCase()]; - }); - - if (is) changeButtonFocus(dialog, names); - - break; - } - - event.stopPropagation(); - }; - } - - function getDataName(el) { - return el.getAttribute('data-name').replace('js-', ''); - } - - function changeButtonFocus(dialog, names) { - var name = '', - active = document.activeElement, - activeName = getDataName(active), - isButton = /ok|cancel/.test(activeName), - count = names.length - 1; - - if (activeName !== 'input' && count && isButton) { - if (activeName === 'cancel') name = 'ok';else name = 'cancel'; - - find(dialog, [name]).forEach(function (el) { - return el.focus(); - }); +function getTemplate(title, msg, value, buttons) { + if (!Array.isArray(buttons)) + throw Error('buttons should be array!'); + + return `
+
+
${ title }
+
+ ${ msg } + ${ value } +
+
+
${ + buttons.map((name, i) => + `` + ).join('') } - } +
+
+
`; +} - function tab(dialog, names) { - var active = document.activeElement, - activeName = getDataName(active), - count = names.length - 1, - index = names.indexOf(activeName); - - if (index === count) index = 0;else if (index < count) ++index; - - var name = names[index]; - - find(dialog, [name]).forEach(function (el) { - return el.focus(); - }); - } - - function closeDialog(el, dialog, ok, cancel) { - var value = undefined, - name = el.getAttribute('data-name').replace('js-', ''); - - if (/close|cancel/.test(name)) { - cancel(); - } else { - value = find(dialog, ['input']).reduce(function (value, el) { - return el.value; - }, null); - - ok(value); - } +function showDialog(title, msg, value, buttons, options) { + let ok, cancel; + const dialog = document.createElement('div'), + + closeButtons = [ + 'cancel', + 'close', + 'ok' + ], + + promise = new Promise((resolve, reject) => { + const noCancel = options && !options.cancel; + const empty = () => {}; + + ok = resolve; + cancel = reject; + + if (noCancel) + cancel = empty; + }), + + tmpl = getTemplate(title, msg, value, buttons); + + dialog.innerHTML = tmpl; + dialog.className = 'smalltalk'; + + document.body.appendChild(dialog); + + find(dialog, ['ok', 'input']).forEach(el => + el.focus() + ); + + find(dialog, ['input']).forEach(el => { + el.setSelectionRange(0, value.length); + }); + + addListeterAll('click', dialog, closeButtons, event => + closeDialog(event.target, dialog, ok, cancel) + ); + + ['click', 'contextmenu'].forEach(event => + dialog.addEventListener(event, () => + find(dialog, ['ok', 'input']).forEach(el => + el.focus() + ) + ) + ); + + dialog.addEventListener('keydown', keyDown(dialog, ok, cancel)); + + return promise; +} +function keyDown(dialog, ok, cancel) { + return event => { + const KEY = { + ENTER : 13, + ESC : 27, + TAB : 9, + LEFT : 37, + UP : 38, + RIGHT : 39, + DOWN : 40 + }; + + const keyCode = event.keyCode; + const el = event.target; + + const namesAll = ['ok', 'cancel', 'input']; + const names = find(dialog, namesAll).map((el) => { + return getDataName(el); + }); + + let is; + + switch(keyCode) { + case KEY.ENTER: + closeDialog(el, dialog, ok, cancel); + event.preventDefault(); + break; + + case KEY.ESC: remove(); - } - - function find(element, names) { - var elements = names.map(function (name) { - return element.querySelector('[data-name="js-' + name + '"]'); - }).filter(function (el) { - return el; + cancel(); + break; + + case KEY.TAB: + if (event.shiftKey) + tab(dialog, names); + + tab(dialog, names); + event.preventDefault(); + break; + + default: + is = ['left', 'right', 'up', 'down'].some((name) => { + return keyCode === KEY[name.toUpperCase()]; }); - - return elements; + + if (is) + changeButtonFocus(dialog, names); + + break; } + + event.stopPropagation(); + }; +} - function addListeterAll(event, parent, elements, fn) { - find(parent, elements).forEach(function (el) { - return el.addEventListener(event, fn); - }); - } +function getDataName(el) { + return el + .getAttribute('data-name') + .replace('js-', ''); +} - function removeEl(name) { - var el = document.querySelector(name); - - el.parentElement.removeChild(el); - } - - function bind(fn) { - for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { - args[_key - 1] = arguments[_key]; - } - - return function () { - return fn.apply(undefined, args); - }; - } +function changeButtonFocus(dialog, names) { + let name = ''; + const active = document.activeElement, + activeName = getDataName(active), + isButton = /ok|cancel/.test(activeName), + count = names.length - 1; + + if (activeName !== 'input' && count && isButton) { + if (activeName === 'cancel') + name = 'ok'; + else + name = 'cancel'; + + find(dialog, [name]).forEach(el => { + el.focus(); + }); } -})(typeof window !== 'undefined' && window); \ No newline at end of file +} + +function tab(dialog, names) { + const active = document.activeElement, + activeName = getDataName(active), + + count = names.length - 1; + let index = names.indexOf(activeName); + + if (index === count) + index = 0; + else if (index < count) + ++index; + + const name = names[index]; + + find(dialog, [name]).forEach(el => + el.focus() + ); +} + +function closeDialog(el, dialog, ok, cancel) { + let value; + const name = el + .getAttribute('data-name') + .replace('js-', ''); + + if (/close|cancel/.test(name)) { + cancel(); + } else { + value = find(dialog, ['input']).reduce((value, el) => { + return el.value; + }, null); + + ok(value); + } + + remove(); +} + +function find(element, names) { + const elements = names.map(name => + element.querySelector(`[data-name="js-${ name }"]`) + ).filter(el => + el + ); + + return elements; +} + +function addListeterAll(event, parent, elements, fn) { + find(parent, elements).forEach(el => + el.addEventListener(event, fn) + ); +} + +function removeEl(name) { + var el = document.querySelector(name); + + el.parentElement.removeChild(el); +} + +function bind(fn, ...args) { + return () => fn(...args); +} + diff --git a/modules/smalltalk/lib/smalltalk.native.js b/modules/smalltalk/lib/smalltalk.native.js index 7db82d57..97d6cfc5 100644 --- a/modules/smalltalk/lib/smalltalk.native.js +++ b/modules/smalltalk/lib/smalltalk.native.js @@ -1,44 +1,41 @@ 'use strict'; -(function (global) { - 'use strict'; +exports.alert = (title, message) => { + const promise = new Promise(function(resolve) { + alert(message); + resolve(); + }); + + return promise; +}; - if (typeof module !== 'undefined' && module.exports) module.exports = Smalltalk();else global.smalltalk = Smalltalk(); +exports.prompt = (title, message, value, options) => { + const o = options, + promise = new Promise(function(resolve, reject) { + const noCancel = o && !o.cancel, + result = prompt(message, value); + + if (result !== null) + resolve(result); + else if (!noCancel) + reject(); + }); + + return promise; +}; - function Smalltalk() { - if (!(this instanceof Smalltalk)) return new Smalltalk(); - - this.alert = function (title, message) { - var promise = new Promise(function (resolve) { - alert(message); +exports.confirm = (title, message, options) => { + const o = options, + noCancel = o && !o.noCancel, + promise = new Promise(function(resolve, reject) { + const is = confirm(message); + + if (is) resolve(); - }); + else if (!noCancel) + reject(); + }); + + return promise; +}; - return promise; - }; - - this.prompt = function (title, message, value, options) { - var o = options, - promise = new Promise(function (resolve, reject) { - var noCancel = o && !o.cancel, - result = prompt(message, value); - - if (result !== null) resolve(result);else if (!noCancel) reject(); - }); - - return promise; - }; - - this.confirm = function (title, message, options) { - var o = options, - noCancel = o && !o.noCancel, - promise = new Promise(function (resolve, reject) { - var is = confirm(message); - - if (is) resolve();else if (!noCancel) reject(); - }); - - return promise; - }; - } -})(typeof window !== 'undefined' && window); \ No newline at end of file diff --git a/modules/smalltalk/package.json b/modules/smalltalk/package.json index 4935ac40..f8b4f9bc 100644 --- a/modules/smalltalk/package.json +++ b/modules/smalltalk/package.json @@ -1,13 +1,13 @@ { "name": "smalltalk", - "version": "1.6.8", + "version": "2.0.0", "description": "Promise-based Alert, Confirm and Prompt replacement", "homepage": "http://github.com/coderaiser/smalltalk", "repository": { "type": "git", "url": "git://github.com/coderaiser/smalltalk.git" }, - "main": "dist/smalltalk.min.js", + "main": "lib/smalltalk.js", "config": { "poly": "node_modules/promise-polyfill/promise.min.js" }, @@ -18,22 +18,27 @@ }, "scripts": { "watch": "watch 'npm run 6to5' dist", - "6to5": "babel -d lib src", + "6to5": "babel -d legacy lib", "minify:css": "minify css/smalltalk.css > dist/smalltalk.min.css", - "minify:js": "minify lib/smalltalk.js > dist/smalltalk.min.js", - "minify:js-native": "minify lib/smalltalk.native.js > dist/smalltalk.native.min.js", - "build:js": "redrun 6to5 minify:js", + "minify:js": "minify dist/smalltalk.js > dist/smalltalk.min.js", + "minify:js-native": "minify dist/smalltalk.native.js > dist/smalltalk.native.min.js", "build:js-poly": "cat $npm_package_config_poly dist/smalltalk.min.js > dist/smalltalk.poly.min.js", "build:js-poly-native": "cat $npm_package_config_poly dist/smalltalk.native.min.js > dist/smalltalk.native.poly.min.js", - "build:js-full": "redrun build:js build:js-poly", - "build:js-native-full": "redrun minify:js-native build:js-poly-native", - "build": "redrun -p minify:css build:js-full build:js-native-full", + "build:js-full": "redrun bundle:js minify:js build:js-poly", + "build:js-native-full": "redrun bundle:js:native minify:js-native build:js-poly-native", + "build": "redrun minify:css 6to5 build:js-full build:js-native-full legacy:index clean", + "bundle:base": "browserify -s smalltalk --ng false", + "bundle:js": "redrun bundle:base -- -r ./legacy/smalltalk.js:smalltalk ./legacy/smalltalk.js -o dist/smalltalk.js", + "bundle:js:native": "redrun bundle:base -- -r ./legacy/smalltalk.native.js:smalltalk ./legacy/smalltalk.native.js -o dist/smalltalk.native.js", + "legacy:index": "echo \"module.exports = require('./smalltalk');\" > legacy/index.js", + "clean": "rimraf dist/smalltalk.js dist/smalltalk.native.js", "bower": "bower", "babel": "babel", "minify": "minify", "wisdom": "npm run build", "lint:css": "stylelint css/*.css", - "lint:js": "jshint src && jscs src", + "lint:js": "jshint lib && jscs lib && eslint lib", + "lint": "redrun lint:*", "test": "redrun lint:*" }, "keywords": [ @@ -50,13 +55,17 @@ "devDependencies": { "babel-cli": "^6.1.1", "babel-preset-es2015": "^6.0.15", + "browserify": "^13.0.1", + "eslint": "^3.0.1", "jscs": "^3.0.3", "jshint": "^2.8.0", "minify": "^2.0.0", "promise-polyfill": "^5.1.0", - "redrun": "^3.0.0", + "redrun": "^5.0.1", + "rimraf": "^2.5.3", "stylelint": "^6.2.2", - "stylelint-config-standard": "^7.0.0", - "watch": "^0.18.0" + "stylelint-config-standard": "^10.0.0", + "systemjs": "^0.19.31", + "watch": "^0.19.1" } } diff --git a/modules/smalltalk/src/smalltalk.js b/modules/smalltalk/src/smalltalk.js deleted file mode 100644 index a5f06b24..00000000 --- a/modules/smalltalk/src/smalltalk.js +++ /dev/null @@ -1,253 +0,0 @@ -(function(global) { - 'use strict'; - - if (typeof module !== 'undefined' && module.exports) - module.exports = SmallTalk(); - else - global.smalltalk = SmallTalk(); - - function SmallTalk(callback) { - if (!(this instanceof SmallTalk)) - return new SmallTalk(callback); - - let remove = bind(removeEl, '.smalltalk'); - - const BUTTON_OK = ['OK']; - const BUTTON_OK_CANCEL = ['OK', 'Cancel']; - - this.alert = (title, msg, options) => { - return showDialog(title, msg, '', BUTTON_OK, options); - }; - - this.prompt = (title, msg, value, options) => { - let val = value || ''; - let valueStr = ``; - - return showDialog(title, msg, valueStr, BUTTON_OK_CANCEL, options); - }; - - this.confirm = (title, msg, options) => { - return showDialog(title, msg, '', BUTTON_OK_CANCEL, options); - }; - - function getTemplate(title, msg, value, buttons) { - if (!Array.isArray(buttons)) - throw Error('buttons should be array!'); - - return `
-
-
${ title }
-
- ${ msg } - ${ value } -
-
-
${ - buttons.map((name, i) => - `` - ).join('') - } -
-
-
`; - } - - function showDialog(title, msg, value, buttons, options) { - let dialog = document.createElement('div'), - - closeButtons = [ - 'cancel', - 'close', - 'ok' - ], - - ok, cancel, - - promise = new Promise((resolve, reject) => { - let noCancel = options && !options.cancel; - let empty = () => {}; - - ok = resolve; - cancel = reject; - - if (noCancel) - cancel = empty; - }), - - tmpl = getTemplate(title, msg, value, buttons); - - dialog.innerHTML = tmpl; - dialog.className = 'smalltalk'; - - document.body.appendChild(dialog); - - find(dialog, ['ok', 'input']).forEach(el => - el.focus() - ); - - find(dialog, ['input']).forEach(el => { - el.setSelectionRange(0, value.length); - }); - - addListeterAll('click', dialog, closeButtons, event => - closeDialog(event.target, dialog, ok, cancel) - ); - - ['click', 'contextmenu'].forEach(event => - dialog.addEventListener(event, () => - find(dialog, ['ok', 'input']).forEach(el => - el.focus() - ) - ) - ); - - dialog.addEventListener('keydown', keyDown(dialog, ok, cancel)); - - return promise; - } - - function keyDown(dialog, ok, cancel) { - return event => { - const KEY = { - ENTER : 13, - ESC : 27, - TAB : 9, - LEFT : 37, - UP : 38, - RIGHT : 39, - DOWN : 40 - }; - - let keyCode = event.keyCode, - el = event.target; - - let namesAll = ['ok', 'cancel', 'input'], - names = find(dialog, namesAll).map(el => - getDataName(el) - ); - - switch(keyCode) { - case KEY.ENTER: - closeDialog(el, dialog, ok, cancel); - event.preventDefault(); - break; - - case KEY.ESC: - remove(); - cancel(); - break; - - case KEY.TAB: - if (event.shiftKey) - tab(dialog, names); - - tab(dialog, names); - event.preventDefault(); - break; - - default: - let is = ['left', 'right', 'up', 'down'].some(name => - keyCode === KEY[name.toUpperCase()] - ); - - if (is) - changeButtonFocus(dialog, names); - - break; - } - - event.stopPropagation(); - }; - } - - function getDataName(el) { - return el - .getAttribute('data-name') - .replace('js-', ''); - } - - function changeButtonFocus(dialog, names) { - let name = '', - active = document.activeElement, - activeName = getDataName(active), - isButton = /ok|cancel/.test(activeName), - count = names.length - 1; - - if (activeName !== 'input' && count && isButton) { - if (activeName === 'cancel') - name = 'ok'; - else - name = 'cancel'; - - find(dialog, [name]).forEach(el => - el.focus() - ); - } - } - - function tab(dialog, names) { - let active = document.activeElement, - activeName = getDataName(active), - - count = names.length - 1, - index = names.indexOf(activeName); - - if (index === count) - index = 0; - else if (index < count) - ++index; - - let name = names[index]; - - find(dialog, [name]).forEach(el => - el.focus() - ); - } - - function closeDialog(el, dialog, ok, cancel) { - let value, - name = el - .getAttribute('data-name') - .replace('js-', ''); - - if (/close|cancel/.test(name)) { - cancel(); - } else { - value = find(dialog, ['input']).reduce((value, el) => { - return el.value; - }, null); - - ok(value); - } - - remove(); - } - - function find(element, names) { - let elements = names.map(name => - element.querySelector(`[data-name="js-${ name }"]`) - ).filter(el => - el - ); - - return elements; - } - - function addListeterAll(event, parent, elements, fn) { - find(parent, elements).forEach(el => - el.addEventListener(event, fn) - ); - } - - function removeEl(name) { - var el = document.querySelector(name); - - el.parentElement.removeChild(el); - } - - function bind(fn, ...args) { - return () => fn(...args); - } - } - -})(typeof window !== 'undefined' && window); diff --git a/modules/smalltalk/src/smalltalk.native.js b/modules/smalltalk/src/smalltalk.native.js deleted file mode 100644 index b6f88faa..00000000 --- a/modules/smalltalk/src/smalltalk.native.js +++ /dev/null @@ -1,54 +0,0 @@ -(function(global) { - 'use strict'; - - if (typeof module !== 'undefined' && module.exports) - module.exports = Smalltalk(); - else - global.smalltalk = Smalltalk(); - - - function Smalltalk() { - if (!(this instanceof Smalltalk)) - return new Smalltalk(); - - this.alert = (title, message) => { - let promise = new Promise(function(resolve) { - alert(message); - resolve(); - }); - - return promise; - }; - - this.prompt = (title, message, value, options) => { - let o = options, - promise = new Promise(function(resolve, reject) { - let noCancel = o && !o.cancel, - result = prompt(message, value); - - if (result !== null) - resolve(result); - else if (!noCancel) - reject(); - }); - - return promise; - }; - - this.confirm = (title, message, options) => { - let o = options, - noCancel = o && !o.noCancel, - promise = new Promise(function(resolve, reject) { - let is = confirm(message); - - if (is) - resolve(); - else if (!noCancel) - reject(); - }); - - return promise; - }; - } - -})(typeof window !== 'undefined' && window);