ccos-cli
Version:
This is a command line interface toolkit. It is used for generating and managing example code for CoocaaOS running on Skyworth/Coocaa TV webos API.
137 lines (134 loc) • 3.73 kB
JavaScript
var app = {
canonical_uri: function (src, base_path) {
var root_page = /^[^?#]*\//.exec(location.href)[0],
root_domain = /^\w+\:\/\/\/?[^\/]+/.exec(root_page)[0],
absolute_regex = /^\w+\:\/\//;
if (/^\/\/\/?/.test(src)) {
src = location.protocol + src;
} else if (!absolute_regex.test(src) && src.charAt(0) != "/") {
src = (base_path || "") + src;
}
return absolute_regex.test(src) ? src : ((src.charAt(0) == "/" ? root_domain : root_page) + src);
},
rel_html_imgpath: function (iconurl) {
return app.canonical_uri(iconurl.replace(/.*\/([^\/]+\/[^\/]+)$/, '$1'));
},
// 请使用编译函数 __uri(path) 来定位资源
cc_uri: function (path) {
return __uri(path).replace("../", "");
},
initialize: function () {
console.log("initialize");
ccDebug.setDeviceInfo({ chip: "aaa" });
this.bindEvents();
},
bindEvents: function () {
console.log("bindEvents");
ccApp.deviceReady({
onReceive: app.onDeviceReady,
success: function () {
console.log('deviceReady success')
}
});
ccApp.bindEvent({
eventName: 'resume',
onReceive: function () {
console.log('resume');
}
});
ccApp.bindEvent({
eventName: 'pause',
onReceive: function () {
console.log('pause');
}
});
ccApp.bindEvent({
eventName: 'backbutton',
onReceive: function () {
console.log('backbuttonup');
ccApp.exitPage();
}
});
ccApp.bindEvent({
eventName: 'backbuttondown',
onReceive: function () {
console.log('backbuttondown');
},
success: function () {
console.log('backbuttondown bind success')
}
});
ccApp.bindEvent({
eventName: 'menubutton',
onReceive: function () {
console.log('menubutton');
}
});
ccApp.bindEvent({
eventName: 'homebutton',
onReceive: function () {
console.log('homebutton');
}
});
},
onDeviceReady: function () {
console.log('deviceReady');
// 使用ccmap插件,初始化
ccmap.init(".coocaa_btn", "#second", "btn-focus");
$("#first,#second,#third").unbind("focus").bind("focus", function () {
console.log('触发focus事件');
});
$("#first").unbind("itemClick").bind("itemClick", function () {
console.log('first click');
//获取设备信息
ccApp.getDeviceInfo({
success: function (result) {
console.log('getDeviceInfo result = ' + JSON.stringify(result))
},
fail: function (result) {
console.log('getDeviceInfo error = ' + JSON.stringify(result))
},
complete: function () {
console.log('getDeviceInfo complete')
}
})
});
$("#second").unbind("itemClick").bind("itemClick", function () {
console.log('second click');
//启动设置页面
ccApp.startTVSetting({
success: function (msg) {
console.log(JSON.stringify(msg))
}
})
});
$("#third").unbind("itemClick").bind("itemClick", function () {
console.log('third click');
//获取用户信息
ccApp.getUserInfo({
success: function (result) {
console.log('getUserInfo result = ' + JSON.stringify(result))
},
fail: function (result) {
console.log('getUserInfo error = ' + JSON.stringify(result))
},
complete: function () {
console.log('getUserInfo complete')
}
})
});
//获取token
ccApp.getUserAccessToken({
success: function (result) {
console.log('getUserAccessToken result = ' + JSON.stringify(result))
},
fail: function (result) {
console.log('getUserAccessToken error = ' + JSON.stringify(result))
},
complete: function () {
console.log('getUserAccessToken complete')
}
})
}
};
app.initialize();