UNPKG

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.

93 lines (86 loc) 2.7 kB
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(app.onDeviceReady); ccApp.bindEvent('resume', function () { console.log('resume'); }); ccApp.bindEvent('pause', function () { console.log('pause'); }); ccApp.bindEvent('backbutton', function () { console.log('backbuttonup'); ccApp.exitPage(); }); ccApp.bindEvent('backbuttondown', function () { console.log('backbuttondown'); }); // ccApp.bindEvent('homebutton', function() { // console.log('homebutton'); // }); // ccApp.bindEvent('menubutton', function() { // console.log('menubutton'); // }); }, onDeviceReady: function () { console.log('deviceReady'); // 使用ccmap插件,初始化 ccmap.init(".coocaa_btn", "#second", "btn-focus"); $("#first,#second,#third").unbind("focus").bind("focus", function () { console.log('触发focus事件'); }); $("#second").unbind("itemClick").bind("itemClick", function () { console.log('跳转应用圈'); ccApp.startAppStore(function () { console.log('success!!!') }, function () { console.log('error') }); }); $("#first").trigger("itemClick"); //获取设备信息 ccApp.getDeviceInfo(function (msg) { console.log(JSON.stringify(msg)); }, function (err) { console.log(err); }) // 获取用户信息 ccApp.getUserInfo(function (msg) { console.log(JSON.stringify(msg)); }, function (err) { console.log(err); }) //获取登录状态 ccApp.hasCoocaaUserLogin(function (msg) { console.log(JSON.stringify(msg)); }, function (err) { console.log(err); }) //获取AccessToken ccApp.getUserAccessToken(function (msg) { console.log(JSON.stringify(msg)); }, function (err) { console.log(err); }) } }; app.initialize();