此BlackBerry Web App Javascript代码的作用是什么?

此BlackBerry Web App Javascript代码的作用是什么?,javascript,mobile,blackberry,Javascript,Mobile,Blackberry,我熟悉几种编程语言,但我很难理解Javascript及其在移动应用程序中的应用。我正在为BlackBerry和一款使用BlackBerry 10 jQuery移动主题的手机开发。我正在查看示例中的App.js,对App对象是什么感到困惑 App = {}; App.init = function () { console.log("App Init"); App.utils.metaHack(); $("#activity").live("pageinit", func

我熟悉几种编程语言,但我很难理解Javascript及其在移动应用程序中的应用。我正在为BlackBerry和一款使用BlackBerry 10 jQuery移动主题的手机开发。我正在查看示例中的App.js,对App对象是什么感到困惑

App = {};

App.init = function () {
    console.log("App Init");
    App.utils.metaHack();
    $("#activity").live("pageinit", function(){
        App.page.activity.init();
    });
    $("#bb_activity").live("pageinit", function(){
        App.page.bb_activity.init();
    });
    $("#progressPage").live("pageinit", function(){
        App.page.progress.init();
    });
    $("#sliderPage, #sliderPageDark").live("pageinit", function(){
        App.page.slider.init();
    });
    $("#togglePage, #togglePageDark").live("pageinit", function(){
        App.page.toggle.init();
    });
    $("#actionBarSample").live("pageinit", function() {
        App.page.actionBarSample.init();
    });
    $('#applicationMenu').live("pageinit", function() {
        App.page.applicationMenu.init();
    });
}

App.utils = {
    metaHack: function () {
        var meta = document.createElement("meta");
        meta.setAttribute('name','viewport');
        meta.setAttribute('content','initial-scale='+ (1/window.devicePixelRatio) + ',user-scalable=no');
        document.getElementsByTagName('head')[0].appendChild(meta);
    }
}

App.page = {
    activity: {},
    bb_activity: {},
    progress: {},
    slider: {},
    toggle: {},
    actionBarSample: {},
    applicationMenu: {}
}

App.page.activity.init = function() {
    $('#show').on('click', function () {
            $.mobile.loading('show');
    });
    $('#text').on('click', function() {
        $.mobile.loading('show', {
            text: 'Loading',
            textVisible: true,
            textonly: true,
            theme: 'a'
        });
    });
    $('#swatch-a').on('click', function() {
        $.mobile.loading( 'show', {
            text: 'Loading',
            textVisible: true,
            theme: 'a'
        });
    });
    $('#swatch-a-notext').on('click', function() {
        $.mobile.loading( 'show', {
            theme: 'a'
        });
    });
    $('#swatch-c').on('click', function() {
        $.mobile.loading( 'show', {
            text: 'Loading',
            textVisible: true,
            theme: 'c'
        });
    });
    $('#swatch-c-notext').on('click', function() {
        $.mobile.loading( 'show', {
            theme: 'c'
        });
    });
    $('#hide').on('click', function () {
        $.mobile.loading('hide');
    });
}

App.page.bb_activity.init = function() {
    console.log("bb_activity");
    $('#throttle').on('change', function () {
        console.log("throttle");
        var speed = $('#throttle').val();
        $('#speedTest').activityindicator('speed', speed+'s');
    });
}

App.page.progress.init = function() {
    var p = 0;
    var error = pause = false;

    function watchProgress() {
        if( p > 100 || error || pause) {
            return;
        }
        $('#rogress').progressbar("setValue", p);
        p+= 4;
        setTimeout(watchProgress, 100);
    }


    $('#start').on('vclick', function () {
        error = false;
        watchProgress();
    });

    $('#error').on('vclick', function () {
        $('#rogress').progressbar("setError", error = !error);
    });

    $('#pause').on('vclick', function () {
        $('#rogress').progressbar("pause", pause = !pause);
    });

    $('#reset').on('vclick', function () {
        p = 0;
        error = pause = false;
        $('#rogress').progressbar("setValue", p);
    });
}

App.page.slider.init = function() {
    $('#slider-disabled').slider('disable');
    $('#slider-disabled-highlight').slider('disable');
}

App.page.toggle.init = function() {
    console.log("toggle init");
    $('#flip-disabled').slider('disable');
}

App.page.actionBarSample.init = function() {

    var $tabo = $("#tover"),
    overflowState = $tabo.hasClass("noContent");

    $("#left").on("panelbeforeopen", function() {
        //Save the state of the overflow button
        overflowState = $tabo.hasClass("noContent");
        $tabo.addClass("noContent");
    })
    .on("panelbeforeclose", function() {
        //Put the overflow button into the correct state
        if(!overflowState) {
            $tabo.removeClass("noContent");
        }
    });

    //Handle overflow menu clicks
    $(".bb10-panel").bind("vclick", function() {
        //Close the panel
        $(this).panel("close");
    });

    $("#left li").bind("vclick", function() {
        //Clear the active state from any other buttons that may have been set to active
        $(this).siblings().removeClass("ui-btn-active");
        //Add the active state to the selected button
        $(this).addClass("ui-btn-active");
        //Clear the contents of the tab overflow button
        //Add class to put the tab overflow icon in the correct position
        //Clear the active state from all tab buttons in action bar
        $('[data-role="tab"], [data-role="tab-overflow"]').removeClass("active");
    });

    $(".inBar").bind("vclick", function() {
        //Set the active state to the tab in the actionbar
        $('#' + this.id.slice(0, 2)).addClass("active");
        $tabo.addClass("noContent").empty();
        overflowState = true;
    });

    $(".notInBar").bind("vclick", function() {
        //Set the active state to the tab overflow button
        $tabo.empty()
        .addClass("active")
        .html('<img src="img/generic_81_81_placeholder.png" alt=""><p>' + $(this).text() + '</p>')
        .removeClass("noContent");
        overflowState = false;
    });

    $("[data-role='tab']").bind("vclick", function() {
        //Change page on tab click
        if($(this).data("href")) {
            $.mobile.changePage( $(this).data("href"), { transition: "slideup"} );
        }
    });
}

App.page.applicationMenu.init = function() {
    if(typeof blackberry != 'undefined'){
        blackberry.event.addEventListener('swipedown', function(){
            $('#top').panel("open");
        });
        $('#menuBtn').css('display','none');
    }
    else{
        $('#simulInst').css('display','none');
    }
}

App.init();
App={};
App.init=函数(){
console.log(“appinit”);
App.utils.metaHack();
$(“#活动”).live(“pageinit”,function(){
App.page.activity.init();
});
$(“#bb_活动”).live(“pageinit”,function(){
App.page.bb_activity.init();
});
$(“#progressPage”).live(“pageinit”,function(){
App.page.progress.init();
});
$(“#sliderPage,#sliderPageDark”).live(“pageinit”,function(){
App.page.slider.init();
});
$(“#togglePage,#togglePageDark”).live(“pageinit”,function(){
App.page.toggle.init();
});
$(“#actionBarSample”).live(“pageinit”,function(){
App.page.actionBarSample.init();
});
$('#applicationMenu').live(“pageinit”,function(){
App.page.applicationMenu.init();
});
}
App.utils={
metaHack:函数(){
var meta=document.createElement(“meta”);
setAttribute('name','viewport');
setAttribute('content','initial-scale='+(1/window.devicePixelRatio)+',user scalable=no');
document.getElementsByTagName('head')[0].appendChild(meta);
}
}
App.page={
活动:{},
bb_活动:{},
进展:{},
滑块:{},
切换:{},
actionBarSample:{},
应用程序菜单:{}
}
App.page.activity.init=函数(){
$('#show')。在('click',函数(){
$.mobile.load('show');
});
$('#text')。在('单击',函数()上){
$.mobile.loading('show'{
文本:“正在加载”,
textVisible:对,
纯文本:是的,
主题:“a”
});
});
$(“#样本-a”)。在('click',function()上{
$.mobile.loading('show'{
文本:“正在加载”,
textVisible:对,
主题:“a”
});
});
$(#swatch-a-notext')。在('click',function()上{
$.mobile.loading('show'{
主题:“a”
});
});
$(“#样本-c”)。在('click',function()上{
$.mobile.loading('show'{
文本:“正在加载”,
textVisible:对,
主题:“c”
});
});
$(#swatch-c-notext')。在('click',function()上{
$.mobile.loading('show'{
主题:“c”
});
});
$('#hide')。在('click',函数(){
$.mobile.load('hide');
});
}
App.page.bb_activity.init=函数(){
控制台日志(“bb_活动”);
$('#throttle')。打开('change',函数(){
控制台日志(“油门”);
变量速度=$(“#油门”).val();
$('speedTest')。活动指示器('speed',speed+'s');
});
}
App.page.progress.init=函数(){
var p=0;
var错误=暂停=错误;
函数watchProgress(){
如果(p>100 | |错误| |暂停){
返回;
}
$('rogress').progressbar(“设置值”,p);
p+=4;
setTimeout(watchProgress,100);
}
$('#start')。在('vclick',函数(){
错误=错误;
观察进展();
});
$('#error')。在('vclick',函数(){
$('#rogress').progressbar(“setError”,error=!error);
});
$('#pause')。on('vclick',function(){
$('#rogress').progressbar(“暂停”,暂停=!暂停);
});
$('#reset')。打开('vclick',函数(){
p=0;
错误=暂停=错误;
$('rogress').progressbar(“设置值”,p);
});
}
App.page.slider.init=函数(){
$(“#滑块已禁用”)。滑块(“禁用”);
$(“#滑块禁用高亮显示”)。滑块(“禁用”);
}
App.page.toggle.init=函数(){
log(“toggle init”);
$(“#翻转禁用”)。滑块(“禁用”);
}
App.page.actionBarSample.init=函数(){
变量$tabo=$(“#tover”),
overflowState=$tabo.hasClass(“无内容”);
$(“#左”)。在(“panelbeforeopen”,function()上{
//保存溢出按钮的状态
overflowState=$tabo.hasClass(“无内容”);
$tabo.addClass(“无内容”);
})
.on(“panelbeforeclose”,函数(){
//将溢出按钮置于正确的状态
如果(!overflowState){
$tabo.removeClass(“无内容”);
}
});
//句柄溢出菜单单击
$(“.bb10 panel”).bind(“vclick”,function(){
//关闭面板
美元(本)。面板(“关闭”);
});
$(“#左li”).bind(“vclick”,function(){
//清除可能已设置为活动的任何其他按钮的活动状态
$(this.sibles().removeClass(“ui btn活动”);
//将活动状态添加到所选按钮
$(此).addClass(“ui btn活动”);
//清除选项卡溢出按钮的内容
//添加类以将选项卡溢出图标置于正确位置
//清除操作栏中所有选项卡按钮的活动状态
$('[data role=“tab”],[data role=“tab overflow”]')。removeClass(“活动”);
});
$(“.inBar”).bind(“vclick”,function(){
//将活动状态设置为actionbar中的选项卡
$('#'+this.id.slice(0,2)).addClass(“活动”);
$tabo.addClass(“noContent”).empty();
overflowState=true;
});
$(“.notInBar”).bind(“vclick”,function(){
//将活动状态设置为选项卡溢出按钮
$tabo.empty()
.addClass(“活动”)
.html(''+$(this).text()+'

') .removeClass(“无内容”); overflowState=false; }); $(“[data role='tab']”)。绑定(“vclick”,function(){ //单击选项卡上的更改页面 if($(this.data(“href”)){ $.mobile.changePage($(this.data(“href”),{transition:“slideup”}); } }); } App.page.applicationMenu.init=函数(){ 如果(类型)