Authored by ccbikai(👎🏻🍜)

跳转 App

... ... @@ -12,22 +12,21 @@ var $ = require('yoho-jquery');
var tip = require('./plugin/tip');
/* 空方法 */
var emptyFn = function () { };
var emptyFn = function() { };
/* 提示信息 */
var tipInfo = '暂不支持,请在YOHO!BUY应用中打开';
var qs = window.queryString;
var yoho, $appLink, $appButton;
var yoho, $appLink;
$appLink = $('#yoho-app-link');
if (!$appLink.length) {
$('body').append('<a id="yoho-app-link" href="javascript:;" style="display:none !important;"><span></span></a>');
$('body').append('<a id="yoho-app-link" href="javascript:;" style="display:none !important;"></a>');
$appLink = $('#yoho-app-link');
}
$appButton = $appLink.find('span');
yoho = {
/**
... ... @@ -42,7 +41,7 @@ yoho = {
*/
data: window.yohoInterfaceData,
ready: function (callback) {
ready: function(callback) {
if (this.isApp) {
document.addEventListener('deviceready', callback);
} else {
... ... @@ -57,7 +56,7 @@ yoho = {
* @param success 调用成功的回调方法
* @param fail 调用失败的回调方法
*/
invokeMethod: function (method, args, success, fail) {
invokeMethod: function(method, args, success, fail) {
var appInterface = window.yohoInterface;
if (this.isApp && appInterface) {
... ... @@ -75,18 +74,18 @@ yoho = {
* @param name 方法名
* @param callback 回调
*/
addNativeMethod: function (name, callback) {
addNativeMethod: function(name, callback) {
var appInterface = window.yohoInterface;
// 延迟 500ms 注入
setTimeout(function () {
setTimeout(function() {
if (appInterface) {
appInterface[name] = callback;
}
}, 500);
},
parseUrl: function (url) {
parseUrl: function(url) {
var query = {},
hashs,
hash,
... ... @@ -98,7 +97,7 @@ yoho = {
if (hashs && hashs.length) {
for (i = 0; i < hashs.length; i++) {
hash = hashs[i].split('=');
console.log(hashs[i])
console.log(hashs[i]);
query[hash[0]] = hash[1];
}
}
... ... @@ -109,7 +108,7 @@ yoho = {
};
},
getUid: function () {
getUid: function() {
if (yoho.isApp) {
return qs.uid;
}
... ... @@ -117,7 +116,7 @@ yoho = {
return window.gitUid();
},
goLogin: function (refer, data) {
goLogin: function(refer, data) {
var url;
url = 'http://m.yohobuy.com/signin.html?refer=' + encodeURIComponent(refer);
... ... @@ -133,15 +132,15 @@ yoho = {
param: refer.query
}
}
}))
}));
}
$appLink.attr('href', url);
$appButton.click();
$appLink[0].click();
return false;
},
goH5: function (link, data) {
goH5: function(link, data) {
var url = link;
if (!link) {
... ... @@ -159,11 +158,11 @@ yoho = {
url: link.path,
param: link.query
}
}))
}));
}
$appLink.attr('href', url);
$appButton.click();
$appLink[0].click();
return false;
}
};
... ...