New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

app-methods

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

app-methods - npm Package Compare versions

Comparing version 0.0.6 to 0.0.7

991

dist/app.common.js

@@ -1,2 +0,2 @@

/*! app.js v0.0.6 | https://www.npmjs.com/package/app-methods */
/*! app.js v0.0.7 | https://www.npmjs.com/package/app-methods */
'use strict';

@@ -35,310 +35,765 @@

var ua = navigator.userAgent.toLowerCase();
/* eslint-disable */
if (typeof weex === 'object') {
window = {
navigator: {
userAgent: weex.config.env.platform + ' Needle/Weex'
}
};
}
/* global yasuo:false */
/**
* @file 「轩辕」的方法
* @namespace needle
* @version 0.3.0
* @global
* @author hongju.wang@ele.me, jianxiang.jin@ele.me
*/
var callQueue = [];
var eventMap = {};
var stashedEvents = [];
var promise;
/**
* 判断是否是Android平台
* @return {Boolean}
* @function
* @memberof needle
* @return {Boolean}
*/
function isAndroid() {
var ua = window.navigator.userAgent.toLowerCase();
return ua.indexOf('android') > -1
}
function exit$2 () {
promise.then(function () {
yasuo.page.finish();
});
/**
* 判断是否是在 Needle 的WebView 环境
* @return {Boolean}
* @function
* @memberof needle
* @return {Boolean}
*/
function isNeedle() {
var ua = window.navigator.userAgent.toLowerCase();
return ua.indexOf('needle') > -1
}
function hideBar$2 () {
promise.then(function () {
yasuo.page.hideBar();
});
/**
* 判断是否是iOS平台
* @return {Boolean}
* @function
* @memberof needle
* @return {Boolean}
*/
function isIOS() {
var ua = window.navigator.userAgent.toLowerCase();
return ua.indexOf('iphone') > -1
}
function showBar$2 () {
promise.then(function () {
yasuo.page.showBar();
});
/**
* 判断是否是 Weex 环境
* @return {Boolean}
* @function
* @memberof needle
* @return {Boolean}
*/
function isWeex() {
return typeof weex === 'object'
}
function init () {
promise = new Promise(function (resolve) {
document.addEventListener('yasuoReady', resolve);
if (isWeex()) {
var globalEvent = weex.requireModule('globalEvent');
globalEvent.addEventListener('_needleEvent', function(event) {
var eventName = event.eventName;
var eventData = event.data;
if (typeof event.data === 'object') {
eventData = event.data;
} else {
try {
eventData = JSON.parse(event.data);
} catch (e) {}
}
var callback = eventAndCallbackMap[eventName];
setTimeout(function() {
!!callback && callback(eventData);
}, 0);
});
initSDK();
globalEvent.addEventListener('_needleCall', function(event) {
var response = event.data;
if (typeof event.data === 'object') {
response = event.data;
} else {
try {
response = JSON.parse(event.data);
} catch (e) {}
}
var callback = callingAndCallbackMap[response.id];
response = response.result;
setTimeout(function() {
if (!!callback && !!response) {
if (!!response.err) {
callback(response.err, null);
} else {
callback(null, response.res);
}
}
delete callingAndCallbackMap[response.id];
}, 0);
});
}
// 这段初始化的代码是他们开发提供的,见 /external/eve-sdk.js。
// 没有大幅度的删减代码是因为稍微删的多一点就会导致 SDK 失效,原因未知。
function initSDK () {
var isAndroid = ua.indexOf('android') > -1;
var isIOS = ua.indexOf('iphone') > -1;
// For Android only
var uniqueId = 0; //请求调用的 message ID
var callingAndCallbackMap = {}; //调用以及回调的对应关系
var eventAndCallbackMap = {}; //事件名字以及事件回调的对应关系
if (!isWeex()) {
window.__needleBrowserTunnel = {
/**
* read data from Android
* {id, params, result}
*/
read: function(responseString) {
var response = JSON.parse(responseString);
var callback = callingAndCallbackMap[response.id];
response = response.result;
setTimeout(function() {
if (!!callback && !!response) {
if (!!response.err) {
callback(response.err, null);
} else {
callback(null, response.res);
}
}
delete callingAndCallbackMap[response.id];
}, 0);
},
on: function(eventName, data) {
/**
* receive event and event data from Android
*/
var eventData = data;
try {
eventData = JSON.parse(data);
} catch (e) {}
var callback = eventAndCallbackMap[eventName];
setTimeout(function() {
!!callback && callback(eventData);
}, 0);
}
};
}
function callHandler (name, params, callback) {
window.WebViewJavascriptBridge.callHandler(name, params, function (res) {
if (callback) {
var response = isAndroid ? JSON.parse(res) : res;
if (response.err) {
/**
* 根据插件名字调用(简称为名字调用)
* @function
* @memberof needle
* @param {String} name 插件名字(自定义插件名字需要与客户端开发一起协商, 内置插件名字均已 needle 开头,业务自定义插件可添加自定义前缀避免命名冲突)
* @param {Object} params 参数
* @param {function} callback 回调函数, 函数签名callback(err, res),第一个总是 err, 第二个参数是正常 response(与 Node.js 回调类似)
*/
function execute(name, params, callback) {
if (isWeex()) {
var id = 'msg_' + uniqueId++ + '_' + new Date().getTime();
callingAndCallbackMap[id] = callback;
weex
.requireModule('NeedleNativeModule')
.execute({ id: id, name: name, params: params });
return
}
if (isAndroid() && !!window.__needleClientTunnel) {
var id = 'msg_' + uniqueId++ + '_' + new Date().getTime();
callingAndCallbackMap[id] = callback;
window.__needleClientTunnel.read(
JSON.stringify({ id: id, name: name, params: params })
);
} else {
if (!!window.WebViewJavascriptBridge) {
_doCall(name, params, callback);
} else {
callQueue.push({ name: name, params: params, callback: callback });
}
}
}
/**
* 判断是否 ready
* @function
* @memberof needle
* @return {Boolean} true 表示 needle 初始化完毕
*/
function isReady() {
return (
!!window.WebViewJavascriptBridge ||
!!window.__needleClientTunnel ||
isWeex()
)
}
function _doCall(name, params, callback) {
!!window.WebViewJavascriptBridge &&
window.WebViewJavascriptBridge.callHandler(name, params, function(res) {
var response = isAndroid() ? JSON.parse(res) : res;
if (!!callback && !!response) {
if (!!response.err) {
callback(response.err, null);
} else if (response.res) {
} else {
callback(null, response.res);
if (window.__needle__debug) {
console.log(
'Plugin name:',
name,
', Params:',
params,
', Response:',
response
);
}
}
}
});
}
/**
* 注册事件监听
* @function
* @memberof needle
* @param {String} eventName 事件名字
* @param {function} callback 事件发生时的回调
*/
function on(eventName, callback) {
if (isWeex()) {
eventAndCallbackMap[eventName] = callback;
return
}
if (isAndroid() && !!window.__needleClientTunnel) {
eventAndCallbackMap[eventName] = callback;
return
}
eventMap[eventName] = { eventName: eventName, callback: callback };
if (!!window.WebViewJavascriptBridge) {
WebViewJavascriptBridge.registerHandler(eventName, function(data) {
_doFlushEventListeners(eventName, data);
});
} else {
stashedEvents.push({ eventName: eventName, callback: callback });
}
}
function _doFlushEventListeners(eventName, data) {
var event = eventMap[eventName];
if (!!event) {
event.callback(data);
}
}
/**
* 设备相关的 API
*@namespace needle.app
*@memberof needle
*/
var app = {
/**
* 显示 Toast
* 获取设备信息
* @example
## 返回值
{
appId : "me.ele.needle",
appVersion : "1.0",
buildNumber : 1,
deviceId : "2146F58E-97A2-4D94-A18A-3C72B6C68BFB",
platform : enum('Android', 'iOS')
resolution : 640x1136,
systemVersion : "10.1",
networkType : enum('2G', '3G', '4G', 'WIFI', 'UNKNOW'),
userAgent : "Mozilla/5.0 (iP......
sdkVersion: '0.1.12'
}
* @function
* @memberof needle.app
* @param {function} callback 回调函数
*/
getEnvInfo: function(callback) {
execute('needle.app.env', {}, callback);
},
/**
* 探测宿主手机某 APP 是否安装
* @function
* @memberof needle.app
* @param {Object} param - {package: String, schemeUrl: String}, Android id 为 package,iOS 为 schemeUrl
* @param {function} callback 回调函数 - res: {isAppInstalled: Boolean}
*/
function showToast (content, callback) {
var options = {};
options.data = JSON.stringify(content) || '';
callHandler('Toast', JSON.stringify(options), callback);
}
isAppInstalled: function(param, callback) {
execute('needle.app.installation', param, callback);
},
/**
* 页面
*/
var page = {
/**
* 显示导航栏
* 编辑短信到发送短信页面等待用户确认发送
* @example
##调用
var option = {
tel: 13857702077,
message: 'this is a needle sms message.'
};
needle.app.sendSMS(option,function(err, res){
if(!err){
;
}
});
* @function
* @memberof needle.app
* @param {Object} param - {tel: String, message: String}
* @param {function} callback 回调函数
*/
showBar: function showBar () {
callHandler('TitleBar', 'show', null);
},
/**
* 隐藏导航栏
sendSMS: function(param, callback) {
execute('needle.app.sms', param, callback);
},
/**
* 获取定位信息
* @example
* needle.app.getLocation(function(err, res){
* if(!err){
* res = {
"longitude":89.33 ,
"latitude": 101.11
}
* }
* });
* @example
##成功响应
{
"longitude":89.33 ,
"latitude": 101.11
}
* @function
* @memberof needle.app
* @param {function} callback 回调函数
*/
hideBar: function hideBar () {
callHandler('TitleBar', 'hide', null);
},
/**
* 关闭当前页面
getLocation: function(callback) {
execute('needle.app.location', {}, callback);
},
/**
* 在新的 WebView 实例中打开 Uri
* @function
* @example
* //参数
* {
* url: "http://www.google.com"
* external: true
* }
* @memberof needle.app
* @param {Object} param {url: String, external: Boolean}, external 是否使用系统浏览器打开
* @param {function} callback 回调函数
*/
openUri: function(param, callback) {
execute('needle.app.uri', param, callback);
},
/**
* 清除webview缓存
* Added: Android: 0.1.2
* Added: iOS: 0.1.0
* @function
* @memberof needle.app
* @param {function} callback 回调函数
*/
clearWebsiteCache: function(callback) {
execute('needle.app.web.cache.clear', {}, callback);
}
};
/**
* WebView 以及所在容器的一些相关操作
*@namespace needle.container
*@memberof needle
*/
var container = {
/**
* 显示 Toast
* @example
## 调用
{
message: msg,
duration: 1000,
offset: 0
}
* @function
* @memberof needle.container
*/
finish: function finish () {
callHandler('Page', 'finish', null);
},
/**
* 显示 loading
toast: function(param) {
execute('needle.container.toast', param, null);
},
/**
* 关闭当前页面(Native 页面)
* @function
* @memberof needle.container
*/
close: function() {
execute('needle.container.window', { type: 'close' }, null);
},
/**
* reload 网页,可以指定 url
* @function
* @example
## param 示例
{
url: 'http://www.google.com'
}
* @memberof needle.container
* @param {function} callback 回调函数
*/
showLoading: function showLoading (options, callback) {
options = options || {};
options.mode = 'show';
callHandler('Loading', options, callback);
},
/**
* 隐藏 loading
*/
hideLoading: function hideLoading (options, callback) {
options = options || {};
options.mode = 'hide';
callHandler('Loading', options, callback);
}
};
reload: function(param, callback) {
var param = param || {};
param.type = 'reload';
execute('needle.container.window', param, callback);
},
/**
* 时间选择器
* 当前网页回退
* @function
* @memberof needle.container
* @param {function} callback 回调函数
*/
var timePicker = {
/**
* 获取时间
goBack: function(callback) {
execute('needle.container.window', { type: 'back' }, callback);
},
/**
* 显示 loading
* @function
* @memberof needle.container
*/
showLoading: function() {
execute('needle.container.loading', { type: 'show' }, null);
},
/**
* 隐藏 loading
* @function
* @memberof needle.container
*/
hideLoading: function() {
execute('needle.container.loading', { type: 'hide' }, null);
},
/**
* 设置导航栏的标题
* @function
* @example
## param 示例
{
title: ‘导航栏标题'
}
* @memberof needle.container
* @param param 见示例
* @param {function} callback 回调函数
*/
getTime: function getTime (options, callback) {
options = options || {};
options.mode = 'time';
callHandler('TimePicker', options, callback);
},
/**
* 获取日期
setTitle: function(param, callback) {
var param = param || {};
param.type = 'set';
execute('needle.container.title', param, null);
},
/**
* 获取导航栏的标题
* @function
* @example
## callback res
"{
title: '获取到的标题'
"}
* @memberof needle.container
* @param {function} callback 回调函数
*/
getDate: function getDate (options, callback) {
options = options || {};
options.mode = 'date';
callHandler('TimePicker', options, callback);
},
/**
* 获取时间&日期
*/
getTimeDate: function (options, callback) {
options = options || {};
options.mode = 'time_date';
callHandler('TimePicker', options, callback);
}
};
getTitle: function(callback) {
execute('needle.container.title', { type: 'get' }, callback);
},
/**
* 键盘
* 显示原生导航栏
* @function
* @memberof needle.container
* @param {function} callback 回调函数
*/
var keyboard = {
/**
* 隐藏键盘
showTitleBar: function(callback) {
execute('needle.container.titleBar', { type: 'show' }, callback);
},
/**
* 隐藏原生导航栏
* @function
* @memberof needle.container
* @param {function} callback 回调函数
*/
hideTitleBar: function(callback) {
execute('needle.container.titleBar', { type: 'hide' }, callback);
},
/**
* 设置原生导航栏右上角 menu 的icon
* @function
* @example
## param 示例
{
icon: 'http://icon_url' //
}
@example
## 调用示例
needle.container.registerMenu({ icon: 'http://avatar.csdn.net/7/A/A/1_qq_19711823.jpg'}, function () {
toast("Menu clicked:");
});
* @memberof needle.container
* @param {Object} param {icon: String}
* @param {function} onclick menu 点击会触发此 callback
*/
hide: function hide (options, callback) {
options = options || {};
options.mode = 'hide';
callHandler('Keyboard', options, callback);
},
/**
* 显示键盘
registerMenu: function(param, onclick) {
execute('needle.container.menu', param, null);
on('needle.container.menu.onclick', onclick);
},
/**
* 设置底部弹出 menu 的 icon,文字, key
* @function
* @example
## param 示例
menus: [{
icon: '',
text: '',
key: '' // 唯一标识
}]
## callback res 示例
{
icon: '',
text: '',
key: ''
}
* @memberof needle.container
* @param {Object} param - 见示例
* @param {function} callback 回调函数
*/
show: function show (options, callback) {
options = options || {};
options.mode = 'show';
callHandler('Keyboard', options, callback);
}
};
registerBottomMenu: function(param, callback) {
execute('needle.container.bottomMenu', param, null);
on('needle.container.bottomMenu.onclick', callback);
}
};
/**
* 图片选择以及图片预览相关 API
*@namespace needle.image
*@memberof needle
*/
var image = {
/**
* 相机
*/
var camera = {
/**
* 拍照
* 选择图片
* @example
## param 示例
{
type: enum('camera', 'album'),
options: {
maxSize: Number, // b, 比如 1024*50 = 50 Kb
width: Number,
height:Number
}
}
@example
## callback res 示例
{
base64: 'base64 encode'
}
* @function
* @memberof needle.image
* @param {Object} param 见示例
* @param {function} callback 回调函数
*/
getPicture: function getPicture (options, callback) {
options = options || {};
options.mode = 'image';
callHandler('Camera', options, callback);
},
/**
* 选择照片
pick: function(param, callback) {
execute('needle.image.picker', param, callback);
},
/**
* 预览图片
* @function
@example
## param 示例
{ images :[{uri: 'uri'}] }
* @memberof needle.image
* @param {Object} param { images :[{uri: 'url'}] }
* @param {function} callback 回调函数
*/
getAlbum: function getAlbum (options, callback) {
options = options || {};
options.mode = 'album';
callHandler('Camera', options, callback);
}
};
preview: function(param, callback) {
execute('needle.image.previewer', param, callback);
},
var file = {
/**
* 上传文件
/**
* 保存图片到系统相册
* Added: Android 0.1.5
* Added: iOS ?
* @function
@example
## param 示例
{ base64: 'base64 string'}
* @memberof needle.image
* @param {Object} param { base64: String}
* @param {function} callback 回调函数
*/
transfer: function transfer (options, callback) {
callHandler('File', options, callback);
}
};
save: function(param, callback) {
execute('needle.image.save', param, callback);
}
};
var app = {
/**
* 检查更新
/**
* 可多 WebView 共享的 K-V 存储 API)
* 注:不同 HOST 之间无法共享 Cache。例如 needle.ele.me 和 needle.elenet.me 无法共享 Cache。
*@namespace needle.cache
*@memberof needle
*/
var cache = {
/**
* 设置 K-V, 相同的 key 会被覆盖
* @function
* @memberof yasuo.app
* @example
## param 示例
{key: 'key', value: 'value'}
* @memberof needle.cache
* @param {Object} param {key: String, value: String}
* @param {function} callback 回调函数
*/
checkVersion: function checkVersion (callback) {
var options = {};
options.mode = 'checkVersion';
callHandler('App', options, callback);
},
/**
* app 信息
set: function(param, callback) {
var param = param || {};
param.method = 'set';
execute('needle.cache', param, callback);
},
/**
* 获取 key 对应值
* @function
* @example
## param 示例
{key: 'key'}
* @memberof needle.cache
* @param {Object} param {key: String}
* @param {function} callback 回调函数
*/
info: function info (callback) {
var options = {};
options.mode = 'info';
callHandler('App', options, callback);
},
/**
* BD 热更新
get: function(param, callback) {
var param = param || {};
param.method = 'get';
execute('needle.cache', param, callback);
},
/**
* delete key 对应值
* Added: Android 0.1.3
* Added: iOS: 0.1.0
* @function
* @example
## param 示例
{key: 'key'}
* @memberof needle.cache
* @param {Object} param {key: String}
* @param {function} callback 回调函数
*/
hotUpdate: function (callback) {
var options = {};
options.mode = 'hotupdate';
callHandler('App', options, callback);
}
};
delete: function(param, callback) {
var param = param || {};
param.method = 'delete';
execute('needle.cache', param, callback);
},
/**
* 设备信息
* 删除所有 key 对应的值
* Added: Android 0.1.3
* Added: iOS: 0.1.0
* @function
* @memberof needle.cache
* @param {function} callback 回调函数
*/
var device = function (callback) {
callHandler('Device', {}, callback);
};
deleteAll: function(callback) {
var param = param || {};
param.method = 'clear';
execute('needle.cache', param, callback);
}
};
var user = {
/**
* 登出
*/
logout: function logout (callback) {
var options = {};
options.mode = 'logout';
callHandler('User', options, callback);
},
/**
* 清除 token
*/
clearToken: function clearToken (callback) {
var options = {};
options.mode = 'clear';
callHandler('User', options, callback);
}
};
if (!isWeex()) {
if (window.WebViewJavascriptBridge) {
initJS();
} else {
// WebViewJavascriptBridgeReady 事件由宿主 WebView 注入的一段 JavaScript 触发
document.addEventListener('WebViewJavascriptBridgeReady', initJS, false);
}
}
var yasuo = window.yasuo = {
init: function init (messageHandler) {
window.WebViewJavascriptBridge.init(messageHandler);
},
isAndroid: function isAndroid$1 () {
return isAndroid
},
isIOS: function isIOS$1 () {
return isIOS
},
showToast: showToast,
camera: camera,
keyboard: keyboard,
timePicker: timePicker,
page: page,
file: file,
network: function network (callback) {
callHandler('NetworkInfo', {}, callback);
},
app: app,
device: device,
user: user,
version: '0.0.1'
};
function _flushQueue() {
callQueue.forEach(function(item) {
_doCall(item.name, item.params, item.callback);
});
callQueue = [];
}
// yasuo ready event
document.addEventListener('WebViewJavascriptBridgeReady', function () {
var WebViewJavascriptBridge = window.WebViewJavascriptBridge;
if (!WebViewJavascriptBridge) { return }
var yasuoReadyEvent = document.createEvent('Events');
yasuoReadyEvent.initEvent('yasuoReady');
document.dispatchEvent(yasuoReadyEvent);
// init
yasuo.init();
// keyboard hide and show event
var yasuoKeyboardHideEvent = document.createEvent('Events');
yasuoKeyboardHideEvent.initEvent('Keyboard.hide');
var yasuoKeyboardShowEvent = document.createEvent('Events');
yasuoKeyboardShowEvent.initEvent('Keyboard.show');
WebViewJavascriptBridge.registerHandler('Keyboard.hide', function (data, responseCallback) {
document.dispatchEvent(yasuoKeyboardHideEvent);
});
WebViewJavascriptBridge.registerHandler('Keyboard.show', function (data, responseCallback) {
document.dispatchEvent(yasuoKeyboardShowEvent);
});
// screen orientation
var yasuoScreenLandscape = document.createEvent('Events');
yasuoScreenLandscape.initEvent('onLandscapeScreen');
WebViewJavascriptBridge.registerHandler('onLandscapeScreen', function (data, responseCallback) {
document.dispatchEvent(yasuoScreenLandscape);
});
var yasuoScreenPortrait = document.createEvent('Events');
yasuoScreenPortrait.initEvent('onPortraitScreen');
WebViewJavascriptBridge.registerHandler('onPortraitScreen', function (data, responseCallback) {
document.dispatchEvent(yasuoScreenPortrait);
});
// network change
var yasuoNetworkStateChange = document.createEvent('Events');
yasuoNetworkStateChange.initEvent('networkStateChange');
WebViewJavascriptBridge.registerHandler('networkStateChange', function (data, responseCallback) {
yasuoNetworkStateChange.data = data;
document.dispatchEvent(yasuoNetworkStateChange);
});
function _flushEventListener() {
stashedEvents.forEach(function(event) {
!!WebViewJavascriptBridge &&
WebViewJavascriptBridge.registerHandler(event.eventName, function(data) {
_doFlushEventListeners(event.eventName, data);
});
});
stashedEvents = [];
}
function initJS() {
_flushEventListener();
_flushQueue();
var needleReadyEvent = document.createEvent('Events');
needleReadyEvent.initEvent('needleReady');
document.dispatchEvent(needleReadyEvent);
}
var needle = {
version: '0.3.0',
isAndroid: isAndroid,
isIOS: isIOS,
isNeedle: isNeedle,
isWeex: isWeex,
isReady: isReady,
execute: execute,
on: on,
app: app,
container: container,
image: image,
cache: cache
};
/**
* @file 「轩辕」的方法
*/
function exit$2 () {
needle.container.close();
}
function hideBar$2 () {
needle.container.hideTitleBar();
}
function showBar$2 () {
needle.container.showTitleBar();
}
function getToken$1 () {
return new Promise(function (resolve, reject) {
needle.execute('xy.auth', {}, function (err, res) {
if (err) {
reject(err);
} else {
resolve(res.token);
}
});
})
}
var xy = Object.freeze({

@@ -348,3 +803,3 @@ exit: exit$2,

showBar: showBar$2,
init: init
getToken: getToken$1
});

@@ -358,7 +813,7 @@

if (dd) {
var promise$1 = new Promise(function (resolve) {
var promise = new Promise(function (resolve) {
dd.ready(resolve);
});
exit$3 = function () {
promise$1.then(function () {
promise.then(function () {
dd.biz.navigation.close();

@@ -375,29 +830,15 @@ });

var ding = Object.freeze({
hideBar: noop,
showBar: noop,
get exit () { return exit$3; }
});
/**
* @file 其它平台的方法,一般是在网页环境里
*/
var other = Object.freeze({
hideBar: noop,
showBar: noop,
exit: noop
});
var platforms = Object.freeze({
ping: ping,
xy: xy,
ding: ding,
other: other
ding: ding
});
var ua = navigator.userAgent.toLowerCase();
/**

@@ -436,23 +877,24 @@ * @file 这个文件用于保存各种 APP 的 useragent 关键字

var sdk = platforms[platform$1];
if (sdk.init) {
sdk.init();
}
var sdk = platforms[platform$1] || {};
// 由于 Ping 的 user-agent 没有唯一标志符,所以始终尝试调用一下 Ping 的 API
function hideBar () {
sdk.hideBar();
hideBar$1();
return sdk.hideBar && sdk.hideBar()
}
function showBar () {
sdk.showBar();
showBar$1();
return sdk.showBar && sdk.showBar()
}
function exit () {
sdk.exit();
exit$1();
return sdk.exit && sdk.exit()
}
function getToken () {
return sdk.getToken && sdk.getToken()
}
exports.platform = platform$1;

@@ -462,1 +904,2 @@ exports.hideBar = hideBar;

exports.exit = exit;
exports.getToken = getToken;

@@ -1,2 +0,2 @@

/*! app.js v0.0.6 | https://www.npmjs.com/package/app-methods */
/*! app.js v0.0.7 | https://www.npmjs.com/package/app-methods */
/* global App:false */

@@ -31,310 +31,765 @@ /**

var ua = navigator.userAgent.toLowerCase();
/* eslint-disable */
if (typeof weex === 'object') {
window = {
navigator: {
userAgent: weex.config.env.platform + ' Needle/Weex'
}
};
}
/* global yasuo:false */
/**
* @file 「轩辕」的方法
* @namespace needle
* @version 0.3.0
* @global
* @author hongju.wang@ele.me, jianxiang.jin@ele.me
*/
var callQueue = [];
var eventMap = {};
var stashedEvents = [];
var promise;
/**
* 判断是否是Android平台
* @return {Boolean}
* @function
* @memberof needle
* @return {Boolean}
*/
function isAndroid() {
var ua = window.navigator.userAgent.toLowerCase();
return ua.indexOf('android') > -1
}
function exit$2 () {
promise.then(function () {
yasuo.page.finish();
});
/**
* 判断是否是在 Needle 的WebView 环境
* @return {Boolean}
* @function
* @memberof needle
* @return {Boolean}
*/
function isNeedle() {
var ua = window.navigator.userAgent.toLowerCase();
return ua.indexOf('needle') > -1
}
function hideBar$2 () {
promise.then(function () {
yasuo.page.hideBar();
});
/**
* 判断是否是iOS平台
* @return {Boolean}
* @function
* @memberof needle
* @return {Boolean}
*/
function isIOS() {
var ua = window.navigator.userAgent.toLowerCase();
return ua.indexOf('iphone') > -1
}
function showBar$2 () {
promise.then(function () {
yasuo.page.showBar();
});
/**
* 判断是否是 Weex 环境
* @return {Boolean}
* @function
* @memberof needle
* @return {Boolean}
*/
function isWeex() {
return typeof weex === 'object'
}
function init () {
promise = new Promise(function (resolve) {
document.addEventListener('yasuoReady', resolve);
if (isWeex()) {
var globalEvent = weex.requireModule('globalEvent');
globalEvent.addEventListener('_needleEvent', function(event) {
var eventName = event.eventName;
var eventData = event.data;
if (typeof event.data === 'object') {
eventData = event.data;
} else {
try {
eventData = JSON.parse(event.data);
} catch (e) {}
}
var callback = eventAndCallbackMap[eventName];
setTimeout(function() {
!!callback && callback(eventData);
}, 0);
});
initSDK();
globalEvent.addEventListener('_needleCall', function(event) {
var response = event.data;
if (typeof event.data === 'object') {
response = event.data;
} else {
try {
response = JSON.parse(event.data);
} catch (e) {}
}
var callback = callingAndCallbackMap[response.id];
response = response.result;
setTimeout(function() {
if (!!callback && !!response) {
if (!!response.err) {
callback(response.err, null);
} else {
callback(null, response.res);
}
}
delete callingAndCallbackMap[response.id];
}, 0);
});
}
// 这段初始化的代码是他们开发提供的,见 /external/eve-sdk.js。
// 没有大幅度的删减代码是因为稍微删的多一点就会导致 SDK 失效,原因未知。
function initSDK () {
var isAndroid = ua.indexOf('android') > -1;
var isIOS = ua.indexOf('iphone') > -1;
// For Android only
var uniqueId = 0; //请求调用的 message ID
var callingAndCallbackMap = {}; //调用以及回调的对应关系
var eventAndCallbackMap = {}; //事件名字以及事件回调的对应关系
if (!isWeex()) {
window.__needleBrowserTunnel = {
/**
* read data from Android
* {id, params, result}
*/
read: function(responseString) {
var response = JSON.parse(responseString);
var callback = callingAndCallbackMap[response.id];
response = response.result;
setTimeout(function() {
if (!!callback && !!response) {
if (!!response.err) {
callback(response.err, null);
} else {
callback(null, response.res);
}
}
delete callingAndCallbackMap[response.id];
}, 0);
},
on: function(eventName, data) {
/**
* receive event and event data from Android
*/
var eventData = data;
try {
eventData = JSON.parse(data);
} catch (e) {}
var callback = eventAndCallbackMap[eventName];
setTimeout(function() {
!!callback && callback(eventData);
}, 0);
}
};
}
function callHandler (name, params, callback) {
window.WebViewJavascriptBridge.callHandler(name, params, function (res) {
if (callback) {
var response = isAndroid ? JSON.parse(res) : res;
if (response.err) {
/**
* 根据插件名字调用(简称为名字调用)
* @function
* @memberof needle
* @param {String} name 插件名字(自定义插件名字需要与客户端开发一起协商, 内置插件名字均已 needle 开头,业务自定义插件可添加自定义前缀避免命名冲突)
* @param {Object} params 参数
* @param {function} callback 回调函数, 函数签名callback(err, res),第一个总是 err, 第二个参数是正常 response(与 Node.js 回调类似)
*/
function execute(name, params, callback) {
if (isWeex()) {
var id = 'msg_' + uniqueId++ + '_' + new Date().getTime();
callingAndCallbackMap[id] = callback;
weex
.requireModule('NeedleNativeModule')
.execute({ id: id, name: name, params: params });
return
}
if (isAndroid() && !!window.__needleClientTunnel) {
var id = 'msg_' + uniqueId++ + '_' + new Date().getTime();
callingAndCallbackMap[id] = callback;
window.__needleClientTunnel.read(
JSON.stringify({ id: id, name: name, params: params })
);
} else {
if (!!window.WebViewJavascriptBridge) {
_doCall(name, params, callback);
} else {
callQueue.push({ name: name, params: params, callback: callback });
}
}
}
/**
* 判断是否 ready
* @function
* @memberof needle
* @return {Boolean} true 表示 needle 初始化完毕
*/
function isReady() {
return (
!!window.WebViewJavascriptBridge ||
!!window.__needleClientTunnel ||
isWeex()
)
}
function _doCall(name, params, callback) {
!!window.WebViewJavascriptBridge &&
window.WebViewJavascriptBridge.callHandler(name, params, function(res) {
var response = isAndroid() ? JSON.parse(res) : res;
if (!!callback && !!response) {
if (!!response.err) {
callback(response.err, null);
} else if (response.res) {
} else {
callback(null, response.res);
if (window.__needle__debug) {
console.log(
'Plugin name:',
name,
', Params:',
params,
', Response:',
response
);
}
}
}
});
}
/**
* 注册事件监听
* @function
* @memberof needle
* @param {String} eventName 事件名字
* @param {function} callback 事件发生时的回调
*/
function on(eventName, callback) {
if (isWeex()) {
eventAndCallbackMap[eventName] = callback;
return
}
if (isAndroid() && !!window.__needleClientTunnel) {
eventAndCallbackMap[eventName] = callback;
return
}
eventMap[eventName] = { eventName: eventName, callback: callback };
if (!!window.WebViewJavascriptBridge) {
WebViewJavascriptBridge.registerHandler(eventName, function(data) {
_doFlushEventListeners(eventName, data);
});
} else {
stashedEvents.push({ eventName: eventName, callback: callback });
}
}
function _doFlushEventListeners(eventName, data) {
var event = eventMap[eventName];
if (!!event) {
event.callback(data);
}
}
/**
* 设备相关的 API
*@namespace needle.app
*@memberof needle
*/
var app = {
/**
* 显示 Toast
* 获取设备信息
* @example
## 返回值
{
appId : "me.ele.needle",
appVersion : "1.0",
buildNumber : 1,
deviceId : "2146F58E-97A2-4D94-A18A-3C72B6C68BFB",
platform : enum('Android', 'iOS')
resolution : 640x1136,
systemVersion : "10.1",
networkType : enum('2G', '3G', '4G', 'WIFI', 'UNKNOW'),
userAgent : "Mozilla/5.0 (iP......
sdkVersion: '0.1.12'
}
* @function
* @memberof needle.app
* @param {function} callback 回调函数
*/
getEnvInfo: function(callback) {
execute('needle.app.env', {}, callback);
},
/**
* 探测宿主手机某 APP 是否安装
* @function
* @memberof needle.app
* @param {Object} param - {package: String, schemeUrl: String}, Android id 为 package,iOS 为 schemeUrl
* @param {function} callback 回调函数 - res: {isAppInstalled: Boolean}
*/
function showToast (content, callback) {
var options = {};
options.data = JSON.stringify(content) || '';
callHandler('Toast', JSON.stringify(options), callback);
}
isAppInstalled: function(param, callback) {
execute('needle.app.installation', param, callback);
},
/**
* 页面
*/
var page = {
/**
* 显示导航栏
* 编辑短信到发送短信页面等待用户确认发送
* @example
##调用
var option = {
tel: 13857702077,
message: 'this is a needle sms message.'
};
needle.app.sendSMS(option,function(err, res){
if(!err){
;
}
});
* @function
* @memberof needle.app
* @param {Object} param - {tel: String, message: String}
* @param {function} callback 回调函数
*/
showBar: function showBar () {
callHandler('TitleBar', 'show', null);
},
/**
* 隐藏导航栏
sendSMS: function(param, callback) {
execute('needle.app.sms', param, callback);
},
/**
* 获取定位信息
* @example
* needle.app.getLocation(function(err, res){
* if(!err){
* res = {
"longitude":89.33 ,
"latitude": 101.11
}
* }
* });
* @example
##成功响应
{
"longitude":89.33 ,
"latitude": 101.11
}
* @function
* @memberof needle.app
* @param {function} callback 回调函数
*/
hideBar: function hideBar () {
callHandler('TitleBar', 'hide', null);
},
/**
* 关闭当前页面
getLocation: function(callback) {
execute('needle.app.location', {}, callback);
},
/**
* 在新的 WebView 实例中打开 Uri
* @function
* @example
* //参数
* {
* url: "http://www.google.com"
* external: true
* }
* @memberof needle.app
* @param {Object} param {url: String, external: Boolean}, external 是否使用系统浏览器打开
* @param {function} callback 回调函数
*/
openUri: function(param, callback) {
execute('needle.app.uri', param, callback);
},
/**
* 清除webview缓存
* Added: Android: 0.1.2
* Added: iOS: 0.1.0
* @function
* @memberof needle.app
* @param {function} callback 回调函数
*/
clearWebsiteCache: function(callback) {
execute('needle.app.web.cache.clear', {}, callback);
}
};
/**
* WebView 以及所在容器的一些相关操作
*@namespace needle.container
*@memberof needle
*/
var container = {
/**
* 显示 Toast
* @example
## 调用
{
message: msg,
duration: 1000,
offset: 0
}
* @function
* @memberof needle.container
*/
finish: function finish () {
callHandler('Page', 'finish', null);
},
/**
* 显示 loading
toast: function(param) {
execute('needle.container.toast', param, null);
},
/**
* 关闭当前页面(Native 页面)
* @function
* @memberof needle.container
*/
close: function() {
execute('needle.container.window', { type: 'close' }, null);
},
/**
* reload 网页,可以指定 url
* @function
* @example
## param 示例
{
url: 'http://www.google.com'
}
* @memberof needle.container
* @param {function} callback 回调函数
*/
showLoading: function showLoading (options, callback) {
options = options || {};
options.mode = 'show';
callHandler('Loading', options, callback);
},
/**
* 隐藏 loading
*/
hideLoading: function hideLoading (options, callback) {
options = options || {};
options.mode = 'hide';
callHandler('Loading', options, callback);
}
};
reload: function(param, callback) {
var param = param || {};
param.type = 'reload';
execute('needle.container.window', param, callback);
},
/**
* 时间选择器
* 当前网页回退
* @function
* @memberof needle.container
* @param {function} callback 回调函数
*/
var timePicker = {
/**
* 获取时间
goBack: function(callback) {
execute('needle.container.window', { type: 'back' }, callback);
},
/**
* 显示 loading
* @function
* @memberof needle.container
*/
showLoading: function() {
execute('needle.container.loading', { type: 'show' }, null);
},
/**
* 隐藏 loading
* @function
* @memberof needle.container
*/
hideLoading: function() {
execute('needle.container.loading', { type: 'hide' }, null);
},
/**
* 设置导航栏的标题
* @function
* @example
## param 示例
{
title: ‘导航栏标题'
}
* @memberof needle.container
* @param param 见示例
* @param {function} callback 回调函数
*/
getTime: function getTime (options, callback) {
options = options || {};
options.mode = 'time';
callHandler('TimePicker', options, callback);
},
/**
* 获取日期
setTitle: function(param, callback) {
var param = param || {};
param.type = 'set';
execute('needle.container.title', param, null);
},
/**
* 获取导航栏的标题
* @function
* @example
## callback res
"{
title: '获取到的标题'
"}
* @memberof needle.container
* @param {function} callback 回调函数
*/
getDate: function getDate (options, callback) {
options = options || {};
options.mode = 'date';
callHandler('TimePicker', options, callback);
},
/**
* 获取时间&日期
*/
getTimeDate: function (options, callback) {
options = options || {};
options.mode = 'time_date';
callHandler('TimePicker', options, callback);
}
};
getTitle: function(callback) {
execute('needle.container.title', { type: 'get' }, callback);
},
/**
* 键盘
* 显示原生导航栏
* @function
* @memberof needle.container
* @param {function} callback 回调函数
*/
var keyboard = {
/**
* 隐藏键盘
showTitleBar: function(callback) {
execute('needle.container.titleBar', { type: 'show' }, callback);
},
/**
* 隐藏原生导航栏
* @function
* @memberof needle.container
* @param {function} callback 回调函数
*/
hideTitleBar: function(callback) {
execute('needle.container.titleBar', { type: 'hide' }, callback);
},
/**
* 设置原生导航栏右上角 menu 的icon
* @function
* @example
## param 示例
{
icon: 'http://icon_url' //
}
@example
## 调用示例
needle.container.registerMenu({ icon: 'http://avatar.csdn.net/7/A/A/1_qq_19711823.jpg'}, function () {
toast("Menu clicked:");
});
* @memberof needle.container
* @param {Object} param {icon: String}
* @param {function} onclick menu 点击会触发此 callback
*/
hide: function hide (options, callback) {
options = options || {};
options.mode = 'hide';
callHandler('Keyboard', options, callback);
},
/**
* 显示键盘
registerMenu: function(param, onclick) {
execute('needle.container.menu', param, null);
on('needle.container.menu.onclick', onclick);
},
/**
* 设置底部弹出 menu 的 icon,文字, key
* @function
* @example
## param 示例
menus: [{
icon: '',
text: '',
key: '' // 唯一标识
}]
## callback res 示例
{
icon: '',
text: '',
key: ''
}
* @memberof needle.container
* @param {Object} param - 见示例
* @param {function} callback 回调函数
*/
show: function show (options, callback) {
options = options || {};
options.mode = 'show';
callHandler('Keyboard', options, callback);
}
};
registerBottomMenu: function(param, callback) {
execute('needle.container.bottomMenu', param, null);
on('needle.container.bottomMenu.onclick', callback);
}
};
/**
* 图片选择以及图片预览相关 API
*@namespace needle.image
*@memberof needle
*/
var image = {
/**
* 相机
*/
var camera = {
/**
* 拍照
* 选择图片
* @example
## param 示例
{
type: enum('camera', 'album'),
options: {
maxSize: Number, // b, 比如 1024*50 = 50 Kb
width: Number,
height:Number
}
}
@example
## callback res 示例
{
base64: 'base64 encode'
}
* @function
* @memberof needle.image
* @param {Object} param 见示例
* @param {function} callback 回调函数
*/
getPicture: function getPicture (options, callback) {
options = options || {};
options.mode = 'image';
callHandler('Camera', options, callback);
},
/**
* 选择照片
pick: function(param, callback) {
execute('needle.image.picker', param, callback);
},
/**
* 预览图片
* @function
@example
## param 示例
{ images :[{uri: 'uri'}] }
* @memberof needle.image
* @param {Object} param { images :[{uri: 'url'}] }
* @param {function} callback 回调函数
*/
getAlbum: function getAlbum (options, callback) {
options = options || {};
options.mode = 'album';
callHandler('Camera', options, callback);
}
};
preview: function(param, callback) {
execute('needle.image.previewer', param, callback);
},
var file = {
/**
* 上传文件
/**
* 保存图片到系统相册
* Added: Android 0.1.5
* Added: iOS ?
* @function
@example
## param 示例
{ base64: 'base64 string'}
* @memberof needle.image
* @param {Object} param { base64: String}
* @param {function} callback 回调函数
*/
transfer: function transfer (options, callback) {
callHandler('File', options, callback);
}
};
save: function(param, callback) {
execute('needle.image.save', param, callback);
}
};
var app = {
/**
* 检查更新
/**
* 可多 WebView 共享的 K-V 存储 API)
* 注:不同 HOST 之间无法共享 Cache。例如 needle.ele.me 和 needle.elenet.me 无法共享 Cache。
*@namespace needle.cache
*@memberof needle
*/
var cache = {
/**
* 设置 K-V, 相同的 key 会被覆盖
* @function
* @memberof yasuo.app
* @example
## param 示例
{key: 'key', value: 'value'}
* @memberof needle.cache
* @param {Object} param {key: String, value: String}
* @param {function} callback 回调函数
*/
checkVersion: function checkVersion (callback) {
var options = {};
options.mode = 'checkVersion';
callHandler('App', options, callback);
},
/**
* app 信息
set: function(param, callback) {
var param = param || {};
param.method = 'set';
execute('needle.cache', param, callback);
},
/**
* 获取 key 对应值
* @function
* @example
## param 示例
{key: 'key'}
* @memberof needle.cache
* @param {Object} param {key: String}
* @param {function} callback 回调函数
*/
info: function info (callback) {
var options = {};
options.mode = 'info';
callHandler('App', options, callback);
},
/**
* BD 热更新
get: function(param, callback) {
var param = param || {};
param.method = 'get';
execute('needle.cache', param, callback);
},
/**
* delete key 对应值
* Added: Android 0.1.3
* Added: iOS: 0.1.0
* @function
* @example
## param 示例
{key: 'key'}
* @memberof needle.cache
* @param {Object} param {key: String}
* @param {function} callback 回调函数
*/
hotUpdate: function (callback) {
var options = {};
options.mode = 'hotupdate';
callHandler('App', options, callback);
}
};
delete: function(param, callback) {
var param = param || {};
param.method = 'delete';
execute('needle.cache', param, callback);
},
/**
* 设备信息
* 删除所有 key 对应的值
* Added: Android 0.1.3
* Added: iOS: 0.1.0
* @function
* @memberof needle.cache
* @param {function} callback 回调函数
*/
var device = function (callback) {
callHandler('Device', {}, callback);
};
deleteAll: function(callback) {
var param = param || {};
param.method = 'clear';
execute('needle.cache', param, callback);
}
};
var user = {
/**
* 登出
*/
logout: function logout (callback) {
var options = {};
options.mode = 'logout';
callHandler('User', options, callback);
},
/**
* 清除 token
*/
clearToken: function clearToken (callback) {
var options = {};
options.mode = 'clear';
callHandler('User', options, callback);
}
};
if (!isWeex()) {
if (window.WebViewJavascriptBridge) {
initJS();
} else {
// WebViewJavascriptBridgeReady 事件由宿主 WebView 注入的一段 JavaScript 触发
document.addEventListener('WebViewJavascriptBridgeReady', initJS, false);
}
}
var yasuo = window.yasuo = {
init: function init (messageHandler) {
window.WebViewJavascriptBridge.init(messageHandler);
},
isAndroid: function isAndroid$1 () {
return isAndroid
},
isIOS: function isIOS$1 () {
return isIOS
},
showToast: showToast,
camera: camera,
keyboard: keyboard,
timePicker: timePicker,
page: page,
file: file,
network: function network (callback) {
callHandler('NetworkInfo', {}, callback);
},
app: app,
device: device,
user: user,
version: '0.0.1'
};
function _flushQueue() {
callQueue.forEach(function(item) {
_doCall(item.name, item.params, item.callback);
});
callQueue = [];
}
// yasuo ready event
document.addEventListener('WebViewJavascriptBridgeReady', function () {
var WebViewJavascriptBridge = window.WebViewJavascriptBridge;
if (!WebViewJavascriptBridge) { return }
var yasuoReadyEvent = document.createEvent('Events');
yasuoReadyEvent.initEvent('yasuoReady');
document.dispatchEvent(yasuoReadyEvent);
// init
yasuo.init();
// keyboard hide and show event
var yasuoKeyboardHideEvent = document.createEvent('Events');
yasuoKeyboardHideEvent.initEvent('Keyboard.hide');
var yasuoKeyboardShowEvent = document.createEvent('Events');
yasuoKeyboardShowEvent.initEvent('Keyboard.show');
WebViewJavascriptBridge.registerHandler('Keyboard.hide', function (data, responseCallback) {
document.dispatchEvent(yasuoKeyboardHideEvent);
});
WebViewJavascriptBridge.registerHandler('Keyboard.show', function (data, responseCallback) {
document.dispatchEvent(yasuoKeyboardShowEvent);
});
// screen orientation
var yasuoScreenLandscape = document.createEvent('Events');
yasuoScreenLandscape.initEvent('onLandscapeScreen');
WebViewJavascriptBridge.registerHandler('onLandscapeScreen', function (data, responseCallback) {
document.dispatchEvent(yasuoScreenLandscape);
});
var yasuoScreenPortrait = document.createEvent('Events');
yasuoScreenPortrait.initEvent('onPortraitScreen');
WebViewJavascriptBridge.registerHandler('onPortraitScreen', function (data, responseCallback) {
document.dispatchEvent(yasuoScreenPortrait);
});
// network change
var yasuoNetworkStateChange = document.createEvent('Events');
yasuoNetworkStateChange.initEvent('networkStateChange');
WebViewJavascriptBridge.registerHandler('networkStateChange', function (data, responseCallback) {
yasuoNetworkStateChange.data = data;
document.dispatchEvent(yasuoNetworkStateChange);
});
function _flushEventListener() {
stashedEvents.forEach(function(event) {
!!WebViewJavascriptBridge &&
WebViewJavascriptBridge.registerHandler(event.eventName, function(data) {
_doFlushEventListeners(event.eventName, data);
});
});
stashedEvents = [];
}
function initJS() {
_flushEventListener();
_flushQueue();
var needleReadyEvent = document.createEvent('Events');
needleReadyEvent.initEvent('needleReady');
document.dispatchEvent(needleReadyEvent);
}
var needle = {
version: '0.3.0',
isAndroid: isAndroid,
isIOS: isIOS,
isNeedle: isNeedle,
isWeex: isWeex,
isReady: isReady,
execute: execute,
on: on,
app: app,
container: container,
image: image,
cache: cache
};
/**
* @file 「轩辕」的方法
*/
function exit$2 () {
needle.container.close();
}
function hideBar$2 () {
needle.container.hideTitleBar();
}
function showBar$2 () {
needle.container.showTitleBar();
}
function getToken$1 () {
return new Promise(function (resolve, reject) {
needle.execute('xy.auth', {}, function (err, res) {
if (err) {
reject(err);
} else {
resolve(res.token);
}
});
})
}
var xy = Object.freeze({

@@ -344,3 +799,3 @@ exit: exit$2,

showBar: showBar$2,
init: init
getToken: getToken$1
});

@@ -354,7 +809,7 @@

if (dd) {
var promise$1 = new Promise(function (resolve) {
var promise = new Promise(function (resolve) {
dd.ready(resolve);
});
exit$3 = function () {
promise$1.then(function () {
promise.then(function () {
dd.biz.navigation.close();

@@ -371,29 +826,15 @@ });

var ding = Object.freeze({
hideBar: noop,
showBar: noop,
get exit () { return exit$3; }
});
/**
* @file 其它平台的方法,一般是在网页环境里
*/
var other = Object.freeze({
hideBar: noop,
showBar: noop,
exit: noop
});
var platforms = Object.freeze({
ping: ping,
xy: xy,
ding: ding,
other: other
ding: ding
});
var ua = navigator.userAgent.toLowerCase();
/**

@@ -432,23 +873,24 @@ * @file 这个文件用于保存各种 APP 的 useragent 关键字

var sdk = platforms[platform$1];
if (sdk.init) {
sdk.init();
}
var sdk = platforms[platform$1] || {};
// 由于 Ping 的 user-agent 没有唯一标志符,所以始终尝试调用一下 Ping 的 API
function hideBar () {
sdk.hideBar();
hideBar$1();
return sdk.hideBar && sdk.hideBar()
}
function showBar () {
sdk.showBar();
showBar$1();
return sdk.showBar && sdk.showBar()
}
function exit () {
sdk.exit();
exit$1();
return sdk.exit && sdk.exit()
}
export { platform$1 as platform, hideBar, showBar, exit };
function getToken () {
return sdk.getToken && sdk.getToken()
}
export { platform$1 as platform, hideBar, showBar, exit, getToken };

@@ -1,2 +0,2 @@

/*! app.js v0.0.6 | https://www.npmjs.com/package/app-methods */
/*! app.js v0.0.7 | https://www.npmjs.com/package/app-methods */
(function (global, factory) {

@@ -37,310 +37,765 @@ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :

var ua = navigator.userAgent.toLowerCase();
/* eslint-disable */
if (typeof weex === 'object') {
window = {
navigator: {
userAgent: weex.config.env.platform + ' Needle/Weex'
}
};
}
/* global yasuo:false */
/**
* @file 「轩辕」的方法
* @namespace needle
* @version 0.3.0
* @global
* @author hongju.wang@ele.me, jianxiang.jin@ele.me
*/
var callQueue = [];
var eventMap = {};
var stashedEvents = [];
var promise;
/**
* 判断是否是Android平台
* @return {Boolean}
* @function
* @memberof needle
* @return {Boolean}
*/
function isAndroid() {
var ua = window.navigator.userAgent.toLowerCase();
return ua.indexOf('android') > -1
}
function exit$2 () {
promise.then(function () {
yasuo.page.finish();
});
/**
* 判断是否是在 Needle 的WebView 环境
* @return {Boolean}
* @function
* @memberof needle
* @return {Boolean}
*/
function isNeedle() {
var ua = window.navigator.userAgent.toLowerCase();
return ua.indexOf('needle') > -1
}
function hideBar$2 () {
promise.then(function () {
yasuo.page.hideBar();
});
/**
* 判断是否是iOS平台
* @return {Boolean}
* @function
* @memberof needle
* @return {Boolean}
*/
function isIOS() {
var ua = window.navigator.userAgent.toLowerCase();
return ua.indexOf('iphone') > -1
}
function showBar$2 () {
promise.then(function () {
yasuo.page.showBar();
});
/**
* 判断是否是 Weex 环境
* @return {Boolean}
* @function
* @memberof needle
* @return {Boolean}
*/
function isWeex() {
return typeof weex === 'object'
}
function init () {
promise = new Promise(function (resolve) {
document.addEventListener('yasuoReady', resolve);
if (isWeex()) {
var globalEvent = weex.requireModule('globalEvent');
globalEvent.addEventListener('_needleEvent', function(event) {
var eventName = event.eventName;
var eventData = event.data;
if (typeof event.data === 'object') {
eventData = event.data;
} else {
try {
eventData = JSON.parse(event.data);
} catch (e) {}
}
var callback = eventAndCallbackMap[eventName];
setTimeout(function() {
!!callback && callback(eventData);
}, 0);
});
initSDK();
globalEvent.addEventListener('_needleCall', function(event) {
var response = event.data;
if (typeof event.data === 'object') {
response = event.data;
} else {
try {
response = JSON.parse(event.data);
} catch (e) {}
}
var callback = callingAndCallbackMap[response.id];
response = response.result;
setTimeout(function() {
if (!!callback && !!response) {
if (!!response.err) {
callback(response.err, null);
} else {
callback(null, response.res);
}
}
delete callingAndCallbackMap[response.id];
}, 0);
});
}
// 这段初始化的代码是他们开发提供的,见 /external/eve-sdk.js。
// 没有大幅度的删减代码是因为稍微删的多一点就会导致 SDK 失效,原因未知。
function initSDK () {
var isAndroid = ua.indexOf('android') > -1;
var isIOS = ua.indexOf('iphone') > -1;
// For Android only
var uniqueId = 0; //请求调用的 message ID
var callingAndCallbackMap = {}; //调用以及回调的对应关系
var eventAndCallbackMap = {}; //事件名字以及事件回调的对应关系
if (!isWeex()) {
window.__needleBrowserTunnel = {
/**
* read data from Android
* {id, params, result}
*/
read: function(responseString) {
var response = JSON.parse(responseString);
var callback = callingAndCallbackMap[response.id];
response = response.result;
setTimeout(function() {
if (!!callback && !!response) {
if (!!response.err) {
callback(response.err, null);
} else {
callback(null, response.res);
}
}
delete callingAndCallbackMap[response.id];
}, 0);
},
on: function(eventName, data) {
/**
* receive event and event data from Android
*/
var eventData = data;
try {
eventData = JSON.parse(data);
} catch (e) {}
var callback = eventAndCallbackMap[eventName];
setTimeout(function() {
!!callback && callback(eventData);
}, 0);
}
};
}
function callHandler (name, params, callback) {
window.WebViewJavascriptBridge.callHandler(name, params, function (res) {
if (callback) {
var response = isAndroid ? JSON.parse(res) : res;
if (response.err) {
/**
* 根据插件名字调用(简称为名字调用)
* @function
* @memberof needle
* @param {String} name 插件名字(自定义插件名字需要与客户端开发一起协商, 内置插件名字均已 needle 开头,业务自定义插件可添加自定义前缀避免命名冲突)
* @param {Object} params 参数
* @param {function} callback 回调函数, 函数签名callback(err, res),第一个总是 err, 第二个参数是正常 response(与 Node.js 回调类似)
*/
function execute(name, params, callback) {
if (isWeex()) {
var id = 'msg_' + uniqueId++ + '_' + new Date().getTime();
callingAndCallbackMap[id] = callback;
weex
.requireModule('NeedleNativeModule')
.execute({ id: id, name: name, params: params });
return
}
if (isAndroid() && !!window.__needleClientTunnel) {
var id = 'msg_' + uniqueId++ + '_' + new Date().getTime();
callingAndCallbackMap[id] = callback;
window.__needleClientTunnel.read(
JSON.stringify({ id: id, name: name, params: params })
);
} else {
if (!!window.WebViewJavascriptBridge) {
_doCall(name, params, callback);
} else {
callQueue.push({ name: name, params: params, callback: callback });
}
}
}
/**
* 判断是否 ready
* @function
* @memberof needle
* @return {Boolean} true 表示 needle 初始化完毕
*/
function isReady() {
return (
!!window.WebViewJavascriptBridge ||
!!window.__needleClientTunnel ||
isWeex()
)
}
function _doCall(name, params, callback) {
!!window.WebViewJavascriptBridge &&
window.WebViewJavascriptBridge.callHandler(name, params, function(res) {
var response = isAndroid() ? JSON.parse(res) : res;
if (!!callback && !!response) {
if (!!response.err) {
callback(response.err, null);
} else if (response.res) {
} else {
callback(null, response.res);
if (window.__needle__debug) {
console.log(
'Plugin name:',
name,
', Params:',
params,
', Response:',
response
);
}
}
}
});
}
/**
* 注册事件监听
* @function
* @memberof needle
* @param {String} eventName 事件名字
* @param {function} callback 事件发生时的回调
*/
function on(eventName, callback) {
if (isWeex()) {
eventAndCallbackMap[eventName] = callback;
return
}
if (isAndroid() && !!window.__needleClientTunnel) {
eventAndCallbackMap[eventName] = callback;
return
}
eventMap[eventName] = { eventName: eventName, callback: callback };
if (!!window.WebViewJavascriptBridge) {
WebViewJavascriptBridge.registerHandler(eventName, function(data) {
_doFlushEventListeners(eventName, data);
});
} else {
stashedEvents.push({ eventName: eventName, callback: callback });
}
}
function _doFlushEventListeners(eventName, data) {
var event = eventMap[eventName];
if (!!event) {
event.callback(data);
}
}
/**
* 设备相关的 API
*@namespace needle.app
*@memberof needle
*/
var app = {
/**
* 显示 Toast
* 获取设备信息
* @example
## 返回值
{
appId : "me.ele.needle",
appVersion : "1.0",
buildNumber : 1,
deviceId : "2146F58E-97A2-4D94-A18A-3C72B6C68BFB",
platform : enum('Android', 'iOS')
resolution : 640x1136,
systemVersion : "10.1",
networkType : enum('2G', '3G', '4G', 'WIFI', 'UNKNOW'),
userAgent : "Mozilla/5.0 (iP......
sdkVersion: '0.1.12'
}
* @function
* @memberof needle.app
* @param {function} callback 回调函数
*/
getEnvInfo: function(callback) {
execute('needle.app.env', {}, callback);
},
/**
* 探测宿主手机某 APP 是否安装
* @function
* @memberof needle.app
* @param {Object} param - {package: String, schemeUrl: String}, Android id 为 package,iOS 为 schemeUrl
* @param {function} callback 回调函数 - res: {isAppInstalled: Boolean}
*/
function showToast (content, callback) {
var options = {};
options.data = JSON.stringify(content) || '';
callHandler('Toast', JSON.stringify(options), callback);
}
isAppInstalled: function(param, callback) {
execute('needle.app.installation', param, callback);
},
/**
* 页面
*/
var page = {
/**
* 显示导航栏
* 编辑短信到发送短信页面等待用户确认发送
* @example
##调用
var option = {
tel: 13857702077,
message: 'this is a needle sms message.'
};
needle.app.sendSMS(option,function(err, res){
if(!err){
;
}
});
* @function
* @memberof needle.app
* @param {Object} param - {tel: String, message: String}
* @param {function} callback 回调函数
*/
showBar: function showBar () {
callHandler('TitleBar', 'show', null);
},
/**
* 隐藏导航栏
sendSMS: function(param, callback) {
execute('needle.app.sms', param, callback);
},
/**
* 获取定位信息
* @example
* needle.app.getLocation(function(err, res){
* if(!err){
* res = {
"longitude":89.33 ,
"latitude": 101.11
}
* }
* });
* @example
##成功响应
{
"longitude":89.33 ,
"latitude": 101.11
}
* @function
* @memberof needle.app
* @param {function} callback 回调函数
*/
hideBar: function hideBar () {
callHandler('TitleBar', 'hide', null);
},
/**
* 关闭当前页面
getLocation: function(callback) {
execute('needle.app.location', {}, callback);
},
/**
* 在新的 WebView 实例中打开 Uri
* @function
* @example
* //参数
* {
* url: "http://www.google.com"
* external: true
* }
* @memberof needle.app
* @param {Object} param {url: String, external: Boolean}, external 是否使用系统浏览器打开
* @param {function} callback 回调函数
*/
openUri: function(param, callback) {
execute('needle.app.uri', param, callback);
},
/**
* 清除webview缓存
* Added: Android: 0.1.2
* Added: iOS: 0.1.0
* @function
* @memberof needle.app
* @param {function} callback 回调函数
*/
clearWebsiteCache: function(callback) {
execute('needle.app.web.cache.clear', {}, callback);
}
};
/**
* WebView 以及所在容器的一些相关操作
*@namespace needle.container
*@memberof needle
*/
var container = {
/**
* 显示 Toast
* @example
## 调用
{
message: msg,
duration: 1000,
offset: 0
}
* @function
* @memberof needle.container
*/
finish: function finish () {
callHandler('Page', 'finish', null);
},
/**
* 显示 loading
toast: function(param) {
execute('needle.container.toast', param, null);
},
/**
* 关闭当前页面(Native 页面)
* @function
* @memberof needle.container
*/
close: function() {
execute('needle.container.window', { type: 'close' }, null);
},
/**
* reload 网页,可以指定 url
* @function
* @example
## param 示例
{
url: 'http://www.google.com'
}
* @memberof needle.container
* @param {function} callback 回调函数
*/
showLoading: function showLoading (options, callback) {
options = options || {};
options.mode = 'show';
callHandler('Loading', options, callback);
},
/**
* 隐藏 loading
*/
hideLoading: function hideLoading (options, callback) {
options = options || {};
options.mode = 'hide';
callHandler('Loading', options, callback);
}
};
reload: function(param, callback) {
var param = param || {};
param.type = 'reload';
execute('needle.container.window', param, callback);
},
/**
* 时间选择器
* 当前网页回退
* @function
* @memberof needle.container
* @param {function} callback 回调函数
*/
var timePicker = {
/**
* 获取时间
goBack: function(callback) {
execute('needle.container.window', { type: 'back' }, callback);
},
/**
* 显示 loading
* @function
* @memberof needle.container
*/
showLoading: function() {
execute('needle.container.loading', { type: 'show' }, null);
},
/**
* 隐藏 loading
* @function
* @memberof needle.container
*/
hideLoading: function() {
execute('needle.container.loading', { type: 'hide' }, null);
},
/**
* 设置导航栏的标题
* @function
* @example
## param 示例
{
title: ‘导航栏标题'
}
* @memberof needle.container
* @param param 见示例
* @param {function} callback 回调函数
*/
getTime: function getTime (options, callback) {
options = options || {};
options.mode = 'time';
callHandler('TimePicker', options, callback);
},
/**
* 获取日期
setTitle: function(param, callback) {
var param = param || {};
param.type = 'set';
execute('needle.container.title', param, null);
},
/**
* 获取导航栏的标题
* @function
* @example
## callback res
"{
title: '获取到的标题'
"}
* @memberof needle.container
* @param {function} callback 回调函数
*/
getDate: function getDate (options, callback) {
options = options || {};
options.mode = 'date';
callHandler('TimePicker', options, callback);
},
/**
* 获取时间&日期
*/
getTimeDate: function (options, callback) {
options = options || {};
options.mode = 'time_date';
callHandler('TimePicker', options, callback);
}
};
getTitle: function(callback) {
execute('needle.container.title', { type: 'get' }, callback);
},
/**
* 键盘
* 显示原生导航栏
* @function
* @memberof needle.container
* @param {function} callback 回调函数
*/
var keyboard = {
/**
* 隐藏键盘
showTitleBar: function(callback) {
execute('needle.container.titleBar', { type: 'show' }, callback);
},
/**
* 隐藏原生导航栏
* @function
* @memberof needle.container
* @param {function} callback 回调函数
*/
hideTitleBar: function(callback) {
execute('needle.container.titleBar', { type: 'hide' }, callback);
},
/**
* 设置原生导航栏右上角 menu 的icon
* @function
* @example
## param 示例
{
icon: 'http://icon_url' //
}
@example
## 调用示例
needle.container.registerMenu({ icon: 'http://avatar.csdn.net/7/A/A/1_qq_19711823.jpg'}, function () {
toast("Menu clicked:");
});
* @memberof needle.container
* @param {Object} param {icon: String}
* @param {function} onclick menu 点击会触发此 callback
*/
hide: function hide (options, callback) {
options = options || {};
options.mode = 'hide';
callHandler('Keyboard', options, callback);
},
/**
* 显示键盘
registerMenu: function(param, onclick) {
execute('needle.container.menu', param, null);
on('needle.container.menu.onclick', onclick);
},
/**
* 设置底部弹出 menu 的 icon,文字, key
* @function
* @example
## param 示例
menus: [{
icon: '',
text: '',
key: '' // 唯一标识
}]
## callback res 示例
{
icon: '',
text: '',
key: ''
}
* @memberof needle.container
* @param {Object} param - 见示例
* @param {function} callback 回调函数
*/
show: function show (options, callback) {
options = options || {};
options.mode = 'show';
callHandler('Keyboard', options, callback);
}
};
registerBottomMenu: function(param, callback) {
execute('needle.container.bottomMenu', param, null);
on('needle.container.bottomMenu.onclick', callback);
}
};
/**
* 图片选择以及图片预览相关 API
*@namespace needle.image
*@memberof needle
*/
var image = {
/**
* 相机
*/
var camera = {
/**
* 拍照
* 选择图片
* @example
## param 示例
{
type: enum('camera', 'album'),
options: {
maxSize: Number, // b, 比如 1024*50 = 50 Kb
width: Number,
height:Number
}
}
@example
## callback res 示例
{
base64: 'base64 encode'
}
* @function
* @memberof needle.image
* @param {Object} param 见示例
* @param {function} callback 回调函数
*/
getPicture: function getPicture (options, callback) {
options = options || {};
options.mode = 'image';
callHandler('Camera', options, callback);
},
/**
* 选择照片
pick: function(param, callback) {
execute('needle.image.picker', param, callback);
},
/**
* 预览图片
* @function
@example
## param 示例
{ images :[{uri: 'uri'}] }
* @memberof needle.image
* @param {Object} param { images :[{uri: 'url'}] }
* @param {function} callback 回调函数
*/
getAlbum: function getAlbum (options, callback) {
options = options || {};
options.mode = 'album';
callHandler('Camera', options, callback);
}
};
preview: function(param, callback) {
execute('needle.image.previewer', param, callback);
},
var file = {
/**
* 上传文件
/**
* 保存图片到系统相册
* Added: Android 0.1.5
* Added: iOS ?
* @function
@example
## param 示例
{ base64: 'base64 string'}
* @memberof needle.image
* @param {Object} param { base64: String}
* @param {function} callback 回调函数
*/
transfer: function transfer (options, callback) {
callHandler('File', options, callback);
}
};
save: function(param, callback) {
execute('needle.image.save', param, callback);
}
};
var app = {
/**
* 检查更新
/**
* 可多 WebView 共享的 K-V 存储 API)
* 注:不同 HOST 之间无法共享 Cache。例如 needle.ele.me 和 needle.elenet.me 无法共享 Cache。
*@namespace needle.cache
*@memberof needle
*/
var cache = {
/**
* 设置 K-V, 相同的 key 会被覆盖
* @function
* @memberof yasuo.app
* @example
## param 示例
{key: 'key', value: 'value'}
* @memberof needle.cache
* @param {Object} param {key: String, value: String}
* @param {function} callback 回调函数
*/
checkVersion: function checkVersion (callback) {
var options = {};
options.mode = 'checkVersion';
callHandler('App', options, callback);
},
/**
* app 信息
set: function(param, callback) {
var param = param || {};
param.method = 'set';
execute('needle.cache', param, callback);
},
/**
* 获取 key 对应值
* @function
* @example
## param 示例
{key: 'key'}
* @memberof needle.cache
* @param {Object} param {key: String}
* @param {function} callback 回调函数
*/
info: function info (callback) {
var options = {};
options.mode = 'info';
callHandler('App', options, callback);
},
/**
* BD 热更新
get: function(param, callback) {
var param = param || {};
param.method = 'get';
execute('needle.cache', param, callback);
},
/**
* delete key 对应值
* Added: Android 0.1.3
* Added: iOS: 0.1.0
* @function
* @example
## param 示例
{key: 'key'}
* @memberof needle.cache
* @param {Object} param {key: String}
* @param {function} callback 回调函数
*/
hotUpdate: function (callback) {
var options = {};
options.mode = 'hotupdate';
callHandler('App', options, callback);
}
};
delete: function(param, callback) {
var param = param || {};
param.method = 'delete';
execute('needle.cache', param, callback);
},
/**
* 设备信息
* 删除所有 key 对应的值
* Added: Android 0.1.3
* Added: iOS: 0.1.0
* @function
* @memberof needle.cache
* @param {function} callback 回调函数
*/
var device = function (callback) {
callHandler('Device', {}, callback);
};
deleteAll: function(callback) {
var param = param || {};
param.method = 'clear';
execute('needle.cache', param, callback);
}
};
var user = {
/**
* 登出
*/
logout: function logout (callback) {
var options = {};
options.mode = 'logout';
callHandler('User', options, callback);
},
/**
* 清除 token
*/
clearToken: function clearToken (callback) {
var options = {};
options.mode = 'clear';
callHandler('User', options, callback);
}
};
if (!isWeex()) {
if (window.WebViewJavascriptBridge) {
initJS();
} else {
// WebViewJavascriptBridgeReady 事件由宿主 WebView 注入的一段 JavaScript 触发
document.addEventListener('WebViewJavascriptBridgeReady', initJS, false);
}
}
var yasuo = window.yasuo = {
init: function init (messageHandler) {
window.WebViewJavascriptBridge.init(messageHandler);
},
isAndroid: function isAndroid$1 () {
return isAndroid
},
isIOS: function isIOS$1 () {
return isIOS
},
showToast: showToast,
camera: camera,
keyboard: keyboard,
timePicker: timePicker,
page: page,
file: file,
network: function network (callback) {
callHandler('NetworkInfo', {}, callback);
},
app: app,
device: device,
user: user,
version: '0.0.1'
};
function _flushQueue() {
callQueue.forEach(function(item) {
_doCall(item.name, item.params, item.callback);
});
callQueue = [];
}
// yasuo ready event
document.addEventListener('WebViewJavascriptBridgeReady', function () {
var WebViewJavascriptBridge = window.WebViewJavascriptBridge;
if (!WebViewJavascriptBridge) { return }
var yasuoReadyEvent = document.createEvent('Events');
yasuoReadyEvent.initEvent('yasuoReady');
document.dispatchEvent(yasuoReadyEvent);
// init
yasuo.init();
// keyboard hide and show event
var yasuoKeyboardHideEvent = document.createEvent('Events');
yasuoKeyboardHideEvent.initEvent('Keyboard.hide');
var yasuoKeyboardShowEvent = document.createEvent('Events');
yasuoKeyboardShowEvent.initEvent('Keyboard.show');
WebViewJavascriptBridge.registerHandler('Keyboard.hide', function (data, responseCallback) {
document.dispatchEvent(yasuoKeyboardHideEvent);
});
WebViewJavascriptBridge.registerHandler('Keyboard.show', function (data, responseCallback) {
document.dispatchEvent(yasuoKeyboardShowEvent);
});
// screen orientation
var yasuoScreenLandscape = document.createEvent('Events');
yasuoScreenLandscape.initEvent('onLandscapeScreen');
WebViewJavascriptBridge.registerHandler('onLandscapeScreen', function (data, responseCallback) {
document.dispatchEvent(yasuoScreenLandscape);
});
var yasuoScreenPortrait = document.createEvent('Events');
yasuoScreenPortrait.initEvent('onPortraitScreen');
WebViewJavascriptBridge.registerHandler('onPortraitScreen', function (data, responseCallback) {
document.dispatchEvent(yasuoScreenPortrait);
});
// network change
var yasuoNetworkStateChange = document.createEvent('Events');
yasuoNetworkStateChange.initEvent('networkStateChange');
WebViewJavascriptBridge.registerHandler('networkStateChange', function (data, responseCallback) {
yasuoNetworkStateChange.data = data;
document.dispatchEvent(yasuoNetworkStateChange);
});
function _flushEventListener() {
stashedEvents.forEach(function(event) {
!!WebViewJavascriptBridge &&
WebViewJavascriptBridge.registerHandler(event.eventName, function(data) {
_doFlushEventListeners(event.eventName, data);
});
});
stashedEvents = [];
}
function initJS() {
_flushEventListener();
_flushQueue();
var needleReadyEvent = document.createEvent('Events');
needleReadyEvent.initEvent('needleReady');
document.dispatchEvent(needleReadyEvent);
}
var needle = {
version: '0.3.0',
isAndroid: isAndroid,
isIOS: isIOS,
isNeedle: isNeedle,
isWeex: isWeex,
isReady: isReady,
execute: execute,
on: on,
app: app,
container: container,
image: image,
cache: cache
};
/**
* @file 「轩辕」的方法
*/
function exit$2 () {
needle.container.close();
}
function hideBar$2 () {
needle.container.hideTitleBar();
}
function showBar$2 () {
needle.container.showTitleBar();
}
function getToken$1 () {
return new Promise(function (resolve, reject) {
needle.execute('xy.auth', {}, function (err, res) {
if (err) {
reject(err);
} else {
resolve(res.token);
}
});
})
}
var xy = Object.freeze({

@@ -350,3 +805,3 @@ exit: exit$2,

showBar: showBar$2,
init: init
getToken: getToken$1
});

@@ -360,7 +815,7 @@

if (dd) {
var promise$1 = new Promise(function (resolve) {
var promise = new Promise(function (resolve) {
dd.ready(resolve);
});
exit$3 = function () {
promise$1.then(function () {
promise.then(function () {
dd.biz.navigation.close();

@@ -377,29 +832,15 @@ });

var ding = Object.freeze({
hideBar: noop,
showBar: noop,
get exit () { return exit$3; }
});
/**
* @file 其它平台的方法,一般是在网页环境里
*/
var other = Object.freeze({
hideBar: noop,
showBar: noop,
exit: noop
});
var platforms = Object.freeze({
ping: ping,
xy: xy,
ding: ding,
other: other
ding: ding
});
var ua = navigator.userAgent.toLowerCase();
/**

@@ -438,23 +879,24 @@ * @file 这个文件用于保存各种 APP 的 useragent 关键字

var sdk = platforms[platform$1];
if (sdk.init) {
sdk.init();
}
var sdk = platforms[platform$1] || {};
// 由于 Ping 的 user-agent 没有唯一标志符,所以始终尝试调用一下 Ping 的 API
function hideBar () {
sdk.hideBar();
hideBar$1();
return sdk.hideBar && sdk.hideBar()
}
function showBar () {
sdk.showBar();
showBar$1();
return sdk.showBar && sdk.showBar()
}
function exit () {
sdk.exit();
exit$1();
return sdk.exit && sdk.exit()
}
function getToken () {
return sdk.getToken && sdk.getToken()
}
exports.platform = platform$1;

@@ -464,2 +906,3 @@ exports.hideBar = hideBar;

exports.exit = exit;
exports.getToken = getToken;

@@ -466,0 +909,0 @@ Object.defineProperty(exports, '__esModule', { value: true });

@@ -1,2 +0,2 @@

/*! app.js v0.0.6 | https://www.npmjs.com/package/app-methods */
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.app=e.app||{})}(this,function(e){"use strict";function n(){try{App.hideBar()}catch(e){}}function t(){try{App.showBar()}catch(e){}}function i(){try{App.close()}catch(e){}}function o(){h.then(function(){yasuo.page.finish()})}function r(){h.then(function(){yasuo.page.hideBar()})}function a(){h.then(function(){yasuo.page.showBar()})}function c(){h=new Promise(function(e){document.addEventListener("yasuoReady",e)}),d()}function d(){function e(e,n,i){window.WebViewJavascriptBridge.callHandler(e,n,function(e){if(i){var n=t?JSON.parse(e):e;n.err?i(n.err,null):n.res&&i(null,n.res)}})}function n(n,t){var i={};i.data=JSON.stringify(n)||"",e("Toast",JSON.stringify(i),t)}var t=m.indexOf("android")>-1,i=m.indexOf("iphone")>-1,o={showBar:function(){e("TitleBar","show",null)},hideBar:function(){e("TitleBar","hide",null)},finish:function(){e("Page","finish",null)},showLoading:function(n,t){n=n||{},n.mode="show",e("Loading",n,t)},hideLoading:function(n,t){n=n||{},n.mode="hide",e("Loading",n,t)}},r={getTime:function(n,t){n=n||{},n.mode="time",e("TimePicker",n,t)},getDate:function(n,t){n=n||{},n.mode="date",e("TimePicker",n,t)},getTimeDate:function(n,t){n=n||{},n.mode="time_date",e("TimePicker",n,t)}},a={hide:function(n,t){n=n||{},n.mode="hide",e("Keyboard",n,t)},show:function(n,t){n=n||{},n.mode="show",e("Keyboard",n,t)}},c={getPicture:function(n,t){n=n||{},n.mode="image",e("Camera",n,t)},getAlbum:function(n,t){n=n||{},n.mode="album",e("Camera",n,t)}},d={transfer:function(n,t){e("File",n,t)}},u={checkVersion:function(n){var t={};t.mode="checkVersion",e("App",t,n)},info:function(n){var t={};t.mode="info",e("App",t,n)},hotUpdate:function(n){var t={};t.mode="hotupdate",e("App",t,n)}},f=function(n){e("Device",{},n)},s={logout:function(n){var t={};t.mode="logout",e("User",t,n)},clearToken:function(n){var t={};t.mode="clear",e("User",t,n)}},h=window.yasuo={init:function(e){window.WebViewJavascriptBridge.init(e)},isAndroid:function(){return t},isIOS:function(){return i},showToast:n,camera:c,keyboard:a,timePicker:r,page:o,file:d,network:function(n){e("NetworkInfo",{},n)},app:u,device:f,user:s,version:"0.0.1"};document.addEventListener("WebViewJavascriptBridgeReady",function(){var e=window.WebViewJavascriptBridge;if(e){var n=document.createEvent("Events");n.initEvent("yasuoReady"),document.dispatchEvent(n),h.init();var t=document.createEvent("Events");t.initEvent("Keyboard.hide");var i=document.createEvent("Events");i.initEvent("Keyboard.show"),e.registerHandler("Keyboard.hide",function(e,n){document.dispatchEvent(t)}),e.registerHandler("Keyboard.show",function(e,n){document.dispatchEvent(i)});var o=document.createEvent("Events");o.initEvent("onLandscapeScreen"),e.registerHandler("onLandscapeScreen",function(e,n){document.dispatchEvent(o)});var r=document.createEvent("Events");r.initEvent("onPortraitScreen"),e.registerHandler("onPortraitScreen",function(e,n){document.dispatchEvent(r)});var a=document.createEvent("Events");a.initEvent("networkStateChange"),e.registerHandler("networkStateChange",function(e,n){a.data=e,document.dispatchEvent(a)})}})}function u(){j.hideBar(),n()}function f(){j.showBar(),t()}function s(){j.exit(),i()}var h,v,p=Object.freeze({hideBar:n,showBar:t,exit:i}),m=navigator.userAgent.toLowerCase(),w=Object.freeze({exit:o,hideBar:r,showBar:a,init:c}),g=function(){},l=window.dd;if(l){var y=new Promise(function(e){l.ready(e)});v=function(){y.then(function(){l.biz.navigation.close()})}}else v=g;var E,b=Object.freeze({hideBar:g,showBar:g,get exit(){return v}}),B=Object.freeze({hideBar:g,showBar:g,exit:g}),O=Object.freeze({ping:p,xy:w,ding:b,other:B}),k={xy:"eve",ping:"qichat",ding:"dingtalk"},x=Object.prototype.hasOwnProperty;for(var P in k)if(x.call(k,P)&&m.indexOf(k[P])>=0){E=P;break}E||window.App&&window.App.hideBar&&(E="ping");var A=E||"other",j=O[A];j.init&&j.init(),e.platform=A,e.hideBar=u,e.showBar=f,e.exit=s,Object.defineProperty(e,"__esModule",{value:!0})});
/*! app.js v0.0.7 | https://www.npmjs.com/package/app-methods */
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.app=e.app||{})}(this,function(e){"use strict";function n(){try{App.hideBar()}catch(e){}}function t(){try{App.showBar()}catch(e){}}function i(){try{App.close()}catch(e){}}function a(){return window.navigator.userAgent.toLowerCase().indexOf("android")>-1}function o(){return window.navigator.userAgent.toLowerCase().indexOf("needle")>-1}function r(){return window.navigator.userAgent.toLowerCase().indexOf("iphone")>-1}function c(){return"object"==typeof weex}function d(e,n,t){if(c()){var i="msg_"+j+++"_"+(new Date).getTime();return A[i]=t,void weex.requireModule("NeedleNativeModule").execute({id:i,name:e,params:n})}if(a()&&window.__needleClientTunnel){var i="msg_"+j+++"_"+(new Date).getTime();A[i]=t,window.__needleClientTunnel.read(JSON.stringify({id:i,name:e,params:n}))}else window.WebViewJavascriptBridge?u(e,n,t):O.push({name:e,params:n,callback:t})}function l(){return!!window.WebViewJavascriptBridge||!!window.__needleClientTunnel||c()}function u(e,n,t){!!window.WebViewJavascriptBridge&&window.WebViewJavascriptBridge.callHandler(e,n,function(i){var o=a()?JSON.parse(i):i;t&&o&&(o.err?t(o.err,null):(t(null,o.res),window.__needle__debug&&console.log("Plugin name:",e,", Params:",n,", Response:",o)))})}function s(e,n){return c()?void(W[e]=n):a()&&window.__needleClientTunnel?void(W[e]=n):(k[e]={eventName:e,callback:n},void(window.WebViewJavascriptBridge?WebViewJavascriptBridge.registerHandler(e,function(n){f(e,n)}):J.push({eventName:e,callback:n})))}function f(e,n){var t=k[e];t&&t.callback(n)}function p(){O.forEach(function(e){u(e.name,e.params,e.callback)}),O=[]}function w(){J.forEach(function(e){!!WebViewJavascriptBridge&&WebViewJavascriptBridge.registerHandler(e.eventName,function(n){f(e.eventName,n)})}),J=[]}function v(){w(),p();var e=document.createEvent("Events");e.initEvent("needleReady"),document.dispatchEvent(e)}function g(){S.container.close()}function h(){S.container.hideTitleBar()}function m(){S.container.showTitleBar()}function b(){return new Promise(function(e,n){S.execute("xy.auth",{},function(t,i){t?n(t):e(i.token)})})}function y(){return n(),X.hideBar&&X.hideBar()}function B(){return t(),X.showBar&&X.showBar()}function x(){return i(),X.exit&&X.exit()}function _(){return X.getToken&&X.getToken()}var T=Object.freeze({hideBar:n,showBar:t,exit:i});"object"==typeof weex&&(window={navigator:{userAgent:weex.config.env.platform+" Needle/Weex"}});var O=[],k={},J=[];if(c()){var N=weex.requireModule("globalEvent");N.addEventListener("_needleEvent",function(e){var n=e.eventName,t=e.data;if("object"==typeof e.data)t=e.data;else try{t=JSON.parse(e.data)}catch(e){}var i=W[n];setTimeout(function(){!!i&&i(t)},0)}),N.addEventListener("_needleCall",function(e){var n=e.data;if("object"==typeof e.data)n=e.data;else try{n=JSON.parse(e.data)}catch(e){}var t=A[n.id];n=n.result,setTimeout(function(){t&&n&&(n.err?t(n.err,null):t(null,n.res)),delete A[n.id]},0)})}var j=0,A={},W={};c()||(window.__needleBrowserTunnel={read:function(e){var n=JSON.parse(e),t=A[n.id];n=n.result,setTimeout(function(){t&&n&&(n.err?t(n.err,null):t(null,n.res)),delete A[n.id]},0)},on:function(e,n){var t=n;try{t=JSON.parse(n)}catch(e){}var i=W[e];setTimeout(function(){!!i&&i(t)},0)}});var E={getEnvInfo:function(e){d("needle.app.env",{},e)},isAppInstalled:function(e,n){d("needle.app.installation",e,n)},sendSMS:function(e,n){d("needle.app.sms",e,n)},getLocation:function(e){d("needle.app.location",{},e)},openUri:function(e,n){d("needle.app.uri",e,n)},clearWebsiteCache:function(e){d("needle.app.web.cache.clear",{},e)}},C={toast:function(e){d("needle.container.toast",e,null)},close:function(){d("needle.container.window",{type:"close"},null)},reload:function(e,n){var e=e||{};e.type="reload",d("needle.container.window",e,n)},goBack:function(e){d("needle.container.window",{type:"back"},e)},showLoading:function(){d("needle.container.loading",{type:"show"},null)},hideLoading:function(){d("needle.container.loading",{type:"hide"},null)},setTitle:function(e,n){var e=e||{};e.type="set",d("needle.container.title",e,null)},getTitle:function(e){d("needle.container.title",{type:"get"},e)},showTitleBar:function(e){d("needle.container.titleBar",{type:"show"},e)},hideTitleBar:function(e){d("needle.container.titleBar",{type:"hide"},e)},registerMenu:function(e,n){d("needle.container.menu",e,null),s("needle.container.menu.onclick",n)},registerBottomMenu:function(e,n){d("needle.container.bottomMenu",e,null),s("needle.container.bottomMenu.onclick",n)}},L={pick:function(e,n){d("needle.image.picker",e,n)},preview:function(e,n){d("needle.image.previewer",e,n)},save:function(e,n){d("needle.image.save",e,n)}},V={set:function(e,n){var e=e||{};e.method="set",d("needle.cache",e,n)},get:function(e,n){var e=e||{};e.method="get",d("needle.cache",e,n)},delete:function(e,n){var e=e||{};e.method="delete",d("needle.cache",e,n)},deleteAll:function(e){var n=n||{};n.method="clear",d("needle.cache",n,e)}};c()||(window.WebViewJavascriptBridge?v():document.addEventListener("WebViewJavascriptBridgeReady",v,!1));var M,S={version:"0.3.0",isAndroid:a,isIOS:r,isNeedle:o,isWeex:c,isReady:l,execute:d,on:s,app:E,container:C,image:L,cache:V},P=Object.freeze({exit:g,hideBar:h,showBar:m,getToken:b}),z=function(){},R=window.dd;if(R){var q=new Promise(function(e){R.ready(e)});M=function(){q.then(function(){R.biz.navigation.close()})}}else M=z;var H,I=Object.freeze({get exit(){return M}}),D=Object.freeze({ping:T,xy:P,ding:I}),U=navigator.userAgent.toLowerCase(),F={xy:"eve",ping:"qichat",ding:"dingtalk"},G=Object.prototype.hasOwnProperty;for(var K in F)if(G.call(F,K)&&U.indexOf(F[K])>=0){H=K;break}H||window.App&&window.App.hideBar&&(H="ping");var Q=H||"other",X=D[Q]||{};e.platform=Q,e.hideBar=y,e.showBar=B,e.exit=x,e.getToken=_,Object.defineProperty(e,"__esModule",{value:!0})});
{
"name": "app-methods",
"version": "0.0.6",
"version": "0.0.7",
"main": "dist/app.common.js",

@@ -5,0 +5,0 @@ "module": "dist/app.esm.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc