mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-01-23 18:55:26 +00:00
feature(bower) smalltalk v2.0.0
This commit is contained in:
parent
32a59c0c26
commit
13f27e2597
19 changed files with 334 additions and 613 deletions
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
{
|
||||
"name": "smalltalk",
|
||||
"version": "1.6.8",
|
||||
"homepage": "https://github.com/coderaiser/smalltalk",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -27,15 +27,13 @@ for preventing of handling cancel event.
|
|||
}
|
||||
```
|
||||
|
||||
## smalltalk.alert(title, message [, options])
|
||||
## smalltalk.alert(title, message)
|
||||
|
||||

|
||||
|
||||
```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"
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
{
|
||||
"name": "smalltalk",
|
||||
"version": "1.6.8",
|
||||
"homepage": "https://github.com/coderaiser/smalltalk",
|
||||
"authors": [
|
||||
"coderaiser <mnemonic.enemy@gmail.com>"
|
||||
|
|
@ -20,12 +19,8 @@
|
|||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"modules",
|
||||
"test",
|
||||
"tests",
|
||||
"screen"
|
||||
"screen",
|
||||
"example"
|
||||
],
|
||||
"dependencies": {}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,10 @@
|
|||
|
||||
z-index: 100;
|
||||
}
|
||||
.smalltalk + .smalltalk {
|
||||
transition: ease 1s;
|
||||
display: none;
|
||||
}
|
||||
|
||||
.smalltalk .page {
|
||||
border-radius: 3px;
|
||||
|
|
|
|||
2
modules/smalltalk/dist/smalltalk.min.css
vendored
2
modules/smalltalk/dist/smalltalk.min.css
vendored
|
|
@ -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}
|
||||
|
|
|
|||
2
modules/smalltalk/dist/smalltalk.min.js
vendored
2
modules/smalltalk/dist/smalltalk.min.js
vendored
|
|
@ -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'<div class="page">\n <div data-name="js-close" class="close-button"></div>\n <header>'+n+'</header>\n <div class="content-area">\n '+t+"\n "+e+'\n </div>\n <div class="action-area">\n <div class="button-strip"> '+r.map(function(n,t){return"<button tabindex="+t+' data-name="js-'+n.toLowerCase()+'">'+n+"</button>"}).join("")+"\n </div>\n </div>\n </div>"}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='<input type="text" value="'+o+'" data-name="js-input">';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<r.length;u++)o(r[u]);return o}({smalltalk:[function(n,e,t){"use strict";function r(n,e,t,r){if(!Array.isArray(r))throw Error("buttons should be array!");return'<div class="page">\n <div data-name="js-close" class="close-button"></div>\n <header>'+n+'</header>\n <div class="content-area">\n '+e+"\n "+t+'\n </div>\n <div class="action-area">\n <div class="button-strip"> '+r.map(function(n,e){return"<button tabindex="+e+' data-name="js-'+n.toLowerCase()+'">'+n+"</button>"}).join("")+"\n </div>\n </div>\n </div>"}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:a<o&&++a;var i=e[a];l(n,[i]).forEach(function(n){return n.focus()})}function f(n,e,t,r){var o=void 0,a=n.getAttribute("data-name").replace("js-","");/close|cancel/.test(a)?r():(o=l(e,["input"]).reduce(function(n,e){return e.value},null),t(o)),v()}function l(n,e){var t=e.map(function(e){return n.querySelector('[data-name="js-'+e+'"]')}).filter(function(n){return n});return t}function d(n,e,t,r){l(e,t).forEach(function(e){return e.addEventListener(n,r)})}function s(n){var e=document.querySelector(n);e.parentElement.removeChild(e)}function p(n){for(var e=arguments.length,t=Array(e>1?e-1:0),r=1;r<e;r++)t[r-1]=arguments[r];return function(){return n.apply(void 0,t)}}var v=p(s,".smalltalk"),m=["OK"],E=["OK","Cancel"];t.alert=function(n,e){return o(n,e,"",m,{cancel:!1})},t.prompt=function(n,e,t,r){var a=t||"",u='<input type="text" value="'+a+'" data-name="js-input">';return o(n,e,u,E,r)},t.confirm=function(n,e,t){return o(n,e,"",E,t)}},{}]},{},["smalltalk"])("smalltalk")});
|
||||
|
|
|
|||
|
|
@ -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;i<t.length;i++)o(t[i]);return o}({smalltalk:[function(e,n,r){"use strict";r.alert=function(e,n){var r=new Promise(function(e){alert(n),e()});return r},r.prompt=function(e,n,r,t){var o=t,f=new Promise(function(e,t){var f=o&&!o.cancel,i=prompt(n,r);null!==i?e(i):f||t()});return f},r.confirm=function(e,n,r){var t=r,o=t&&!t.noCancel,f=new Promise(function(e,r){var t=confirm(n);t?e():o||r()});return f}},{}]},{},["smalltalk"])("smalltalk")});
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
!function(e){function t(){}function n(e,t){return function(){e.apply(t,arguments)}}function o(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],s(e,this)}function r(e,t){for(;3===e._state;)e=e._value;return 0===e._state?void e._deferreds.push(t):(e._handled=!0,void a(function(){var n=1===e._state?t.onFulfilled:t.onRejected;if(null===n)return void(1===e._state?i:f)(t.promise,e._value);var o;try{o=n(e._value)}catch(r){return void f(t.promise,r)}i(t.promise,o)}))}function i(e,t){try{if(t===e)throw new TypeError("A promise cannot be resolved with itself.");if(t&&("object"==typeof t||"function"==typeof t)){var r=t.then;if(t instanceof o)return e._state=3,e._value=t,void u(e);if("function"==typeof r)return void s(n(r,t),e)}e._state=1,e._value=t,u(e)}catch(i){f(e,i)}}function f(e,t){e._state=2,e._value=t,u(e)}function u(e){2===e._state&&0===e._deferreds.length&&a(function(){e._handled||d(e._value)},1);for(var t=0,n=e._deferreds.length;n>t;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;i<t.length;i++)o(i,t[i])})},o.resolve=function(e){return e&&"object"==typeof e&&e.constructor===o?e:new o(function(t){t(e)})},o.reject=function(e){return new o(function(t,n){n(e)})},o.race=function(e){return new o(function(t,n){for(var o=0,r=e.length;r>o;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;i<e.length;i++)o(i,e[i])})},o.resolve=function(t){return t&&"object"==typeof t&&t.constructor===o?t:new o(function(e){e(t)})},o.reject=function(t){return new o(function(e,n){n(t)})},o.race=function(t){return new o(function(e,n){for(var o=0,r=t.length;r>o;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;i<t.length;i++)o(t[i]);return o}({smalltalk:[function(e,n,r){"use strict";r.alert=function(e,n){var r=new Promise(function(e){alert(n),e()});return r},r.prompt=function(e,n,r,t){var o=t,f=new Promise(function(e,t){var f=o&&!o.cancel,i=prompt(n,r);null!==i?e(i):f||t()});return f},r.confirm=function(e,n,r){var t=r,o=t&&!t.noCancel,f=new Promise(function(e,r){var t=confirm(n);t?e():o||r()});return f}},{}]},{},["smalltalk"])("smalltalk")});
|
||||
|
|
|
|||
2
modules/smalltalk/dist/smalltalk.poly.min.js
vendored
2
modules/smalltalk/dist/smalltalk.poly.min.js
vendored
File diff suppressed because one or more lines are too long
|
|
@ -1,15 +0,0 @@
|
|||
<!doctype html>
|
||||
<link rel="stylesheet" href="../css/smalltalk.css">
|
||||
<meta content="width=device-width,initial-scale=1" name="viewport">
|
||||
|
||||
<script src="../src/smalltalk.js"></script>
|
||||
<script>
|
||||
window.addEventListener('DOMContentLoaded', function() {
|
||||
smalltalk.prompt('hello', 'world', '2+2').then(function(value) {
|
||||
console.log(value);
|
||||
}, function() {
|
||||
console.log('close');
|
||||
})
|
||||
});
|
||||
|
||||
</script>
|
||||
|
|
@ -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 = `<input type="text" value="${ val }" data-name="js-input">`;
|
||||
|
||||
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 = '<input type="text" value="' + val + '" data-name="js-input">';
|
||||
|
||||
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 '<div class="page">\n <div data-name="js-close" class="close-button"></div>\n <header>' + title + '</header>\n <div class="content-area">\n ' + msg + '\n ' + value + '\n </div>\n <div class="action-area">\n <div class="button-strip"> ' + buttons.map(function (name, i) {
|
||||
return '<button tabindex=' + i + ' data-name="js-' + name.toLowerCase() + '">' + name + '</button>';
|
||||
}).join('') + '\n </div>\n </div>\n </div>';
|
||||
}
|
||||
|
||||
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 `<div class="page">
|
||||
<div data-name="js-close" class="close-button"></div>
|
||||
<header>${ title }</header>
|
||||
<div class="content-area">
|
||||
${ msg }
|
||||
${ value }
|
||||
</div>
|
||||
<div class="action-area">
|
||||
<div class="button-strip"> ${
|
||||
buttons.map((name, i) =>
|
||||
`<button tabindex=${ i } data-name="js-${ name.toLowerCase() }">${ name }</button>`
|
||||
).join('')
|
||||
}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 = `<input type="text" value="${ val }" data-name="js-input">`;
|
||||
|
||||
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 `<div class="page">
|
||||
<div data-name="js-close" class="close-button"></div>
|
||||
<header>${ title }</header>
|
||||
<div class="content-area">
|
||||
${ msg }
|
||||
${ value }
|
||||
</div>
|
||||
<div class="action-area">
|
||||
<div class="button-strip"> ${
|
||||
buttons.map((name, i) =>
|
||||
`<button tabindex=${ i } data-name="js-${ name.toLowerCase() }">${ name }</button>`
|
||||
).join('')
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>`;
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
@ -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);
|
||||
Loading…
Add table
Add a link
Reference in a new issue