Skip to content

Commit

Permalink
release 0.1.3
Browse files Browse the repository at this point in the history
modal, fetch available for web
  • Loading branch information
acathur committed Nov 17, 2017
1 parent c69e9e4 commit b232107
Show file tree
Hide file tree
Showing 13 changed files with 622 additions and 286 deletions.
115 changes: 58 additions & 57 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,59 +1,60 @@
{
"env": {
"browser": true,
"node": true,
"es6": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 8
},
"rules": {
"no-cond-assign": 2,
"no-irregular-whitespace": 2,
"no-unexpected-multiline": 2,
"no-caller": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-native-reassign": 2,
"no-new-wrappers": 2,
"no-new-symbol": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-var": 2,
"no-with": 2,
"no-unused-vars": [2, {"args": "none"}],
"no-array-constructor": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multiple-empty-lines": [2, {"max": 2}],
"no-trailing-spaces": 2,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"arrow-parens": [2, "always"],
"arrow-spacing": 2,
"comma-dangle": [1,"only-multiline"],
"comma-style": 2,
"constructor-super": 2,
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, "after"],
"indent": [2, "tab"],
"object-curly-spacing": 2,
"quotes": [2, "single"],
"semi": [2, "never"],
"semi-spacing": 2,
"space-before-blocks": 2,
"space-before-function-paren": [2, "never"],
"use-isnan": 2
},
"globals": {
"module": true,
"weex": true,
"__weex_define__": true,
"__weex_require__": true
}
"env": {
"browser": true,
"node": true,
"es6": true
},
"extends": "eslint:recommended",
"parser": "babel-eslint",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 8
},
"rules": {
"no-cond-assign": 2,
"no-irregular-whitespace": 2,
"no-unexpected-multiline": 2,
"no-caller": 2,
"no-extend-native": 2,
"no-extra-bind": 2,
"no-multi-spaces": 2,
"no-multi-str": 2,
"no-native-reassign": 2,
"no-new-wrappers": 2,
"no-new-symbol": 2,
"no-this-before-super": 2,
"no-throw-literal": 2,
"no-var": 2,
"no-with": 2,
"no-unused-vars": [2, {"args": "none"}],
"no-array-constructor": 2,
"no-mixed-spaces-and-tabs": 2,
"no-multiple-empty-lines": [2, {"max": 2}],
"no-trailing-spaces": 2,
"no-dupe-args": 2,
"no-dupe-keys": 2,
"no-duplicate-case": 2,
"arrow-parens": [2, "always"],
"arrow-spacing": 2,
"comma-dangle": [1,"only-multiline"],
"comma-style": 2,
"constructor-super": 2,
"eol-last": 2,
"eqeqeq": [2, "allow-null"],
"generator-star-spacing": [2, "after"],
"indent": [2, "tab"],
"object-curly-spacing": [2, "always"],
"quotes": [2, "single"],
"semi": [2, "never"],
"semi-spacing": 2,
"space-before-blocks": 2,
"space-before-function-paren": [2, "never"],
"use-isnan": 2
},
"globals": {
"module": true,
"weex": true,
"__weex_define__": true,
"__weex_require__": true
}
}
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ if (weex && weex.requireModule || typeof __weex_define__ === 'function') {
var network = require('./network');
var sensor = require('./sensor');
var device = require('./device');
var Navigator = require('./navigator');
var alipay = require('./third-party/alipay');
var navigator = require('./navigator');

// camera
if (camera) {
Expand Down Expand Up @@ -77,8 +77,8 @@ if (weex && weex.requireModule || typeof __weex_define__ === 'function') {
}

// navigator
if (navigator) {
Nat.navigator = navigator;
if (Navigator) {
Nat.navigator = Navigator;
}

// alipay
Expand Down
177 changes: 101 additions & 76 deletions lib/modal/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict';

var _utils = require('../utils');

var modal = void 0;

if (weex && weex.requireModule) {
Expand All @@ -9,10 +11,9 @@ if (weex && weex.requireModule) {
modal = __weex_require__('@weex-module/nat/modal');
});
}

// alert

var alert = function alert(opts, cb) {
var Alert = function Alert(opts, cb) {
return new Promise(function (resolve, reject) {
if (typeof opts === 'string') {
opts = {
Expand All @@ -22,27 +23,32 @@ var alert = function alert(opts, cb) {

opts = opts || {};

modal.alert({
title: opts.title || '',
message: opts.message || '',
okButton: opts.okButton || 'OK'
}, function (ret) {
ret = ret || {};

if (ret.error) {
reject(ret.error);
if (typeof cb === 'function') cb(ret.error, null);
} else {
resolve();
if (typeof cb === 'function') cb(null);
}
});
if (_utils.isNative) {
modal.alert({
title: opts.title || '',
message: opts.message || '',
okButton: opts.okButton || 'OK'
}, function (ret) {
ret = ret || {};

if (ret.error) {
reject(ret.error);
if (typeof cb === 'function') cb(ret.error, null);
} else {
resolve();
if (typeof cb === 'function') cb(null);
}
});
} else {
window.alert(opts.message);
resolve();
}
});
};

// confirm

var confirm = function confirm(opts, cb) {
var Confirm = function Confirm(opts, cb) {
return new Promise(function (resolve, reject) {
if (typeof opts === 'string') {
opts = {
Expand All @@ -52,32 +58,37 @@ var confirm = function confirm(opts, cb) {

opts = opts || {};

modal.confirm({
title: opts.title || '',
message: opts.message || '',
okButton: opts.okButton || 'OK',
cancelButton: opts.cancelButton || 'Cancel'
}, function (ret) {
if (typeof ret === 'undefined') {
ret = {
error: 'unknow error, please report to natjs team'
};
}

if (ret.error) {
reject(ret.error);
if (typeof cb === 'function') cb(ret.error, null);
} else {
resolve(ret);
if (typeof cb === 'function') cb(null, ret);
}
});
if (_utils.isNative) {
modal.confirm({
title: opts.title || '',
message: opts.message || '',
okButton: opts.okButton || 'OK',
cancelButton: opts.cancelButton || 'Cancel'
}, function (ret) {
if (typeof ret === 'undefined') {
ret = {
error: 'unknow error, please report to natjs team'
};
}

if (ret.error) {
reject(ret.error);
if (typeof cb === 'function') cb(ret.error, null);
} else {
resolve(ret);
if (typeof cb === 'function') cb(null, ret);
}
});
} else {
var c = window.confirm(opts.message);
resolve(c);
}
});
};

// prompt

var prompt = function prompt(opts, cb) {
var Prompt = function Prompt(opts, cb) {
return new Promise(function (resolve, reject) {
if (typeof opts === 'string') {
opts = {
Expand All @@ -87,29 +98,38 @@ var prompt = function prompt(opts, cb) {

opts = opts || {};

modal.prompt({
title: opts.title || '',
message: opts.message || '',
text: opts.text || '',
okButton: opts.okButton || 'OK',
cancelButton: opts.cancelButton || 'Cancel'
}, function (ret) {
ret = ret || {};

if (ret.error) {
reject(ret.error);
if (typeof cb === 'function') cb(ret.error, null);
} else {
resolve(ret);
if (typeof cb === 'function') cb(null, ret);
}
});
if (_utils.isNative) {
modal.prompt({
title: opts.title || '',
message: opts.message || '',
text: opts.text || '',
okButton: opts.okButton || 'OK',
cancelButton: opts.cancelButton || 'Cancel'
}, function (ret) {
ret = ret || {};

if (ret.error) {
reject(ret.error);
if (typeof cb === 'function') cb(ret.error, null);
} else {
resolve(ret);
if (typeof cb === 'function') cb(null, ret);
}
});
} else {
var p = window.prompt(opts.message || '', opts.text || '');

resolve({
result: p && p.length,
data: p
});
}
});
};

// toast

var toast = function toast(opts, cb) {
var Toast = function Toast(opts, cb) {
return new Promise(function (resolve, reject) {
if (typeof opts === 'string') {
opts = {
Expand All @@ -124,27 +144,32 @@ var toast = function toast(opts, cb) {
opts.position = 'bottom';
}

modal.toast({
message: opts.message || '',
duration: opts.duration || 3000,
position: opts.position
}, function (ret) {
ret = ret || {};

if (ret.error) {
reject(ret.error);
if (typeof cb === 'function') cb(ret.error, null);
} else {
resolve();
if (typeof cb === 'function') cb(null);
}
});
if (_utils.isNative) {
modal.toast({
message: opts.message || '',
duration: opts.duration || 3000,
position: opts.position
}, function (ret) {
ret = ret || {};

if (ret.error) {
reject(ret.error);
if (typeof cb === 'function') cb(ret.error, null);
} else {
resolve();
if (typeof cb === 'function') cb(null);
}
});
} else {
window.alert(opts.message);
resolve();
}
});
};

module.exports = {
alert: alert,
confirm: confirm,
prompt: prompt,
toast: toast
alert: Alert,
confirm: Confirm,
prompt: Prompt,
toast: Toast
};
Loading

0 comments on commit b232107

Please sign in to comment.