2013-08-19 54 views
0

我的phonegap應用程序中基本上有兩個頁面,我使用PGB(index.html和main.html)構建,都使用angular.js。 Index.html是應用程序的登錄名,之後重定向到main.html。我所有的插件和phonegap.js都被正確地注入到main中,但是沒有任何內聯JS(doc準備就緒,設備就緒,窗口加載警報)正在觸發,更不用說phonegap.js也被加載了。第二個html頁面上的Phonegap.js

任何意見,將不勝感激。

腳本包括:

<script src="phonegap.js"></script> 
<script src="cdv-plugin-fb-connect.js"></script> 
<script src="facebook-js-sdk.js"></script> <script>alert("inside pg");</script> 
<script src="childbrowser.js"></script> 
<script src="js/jquery.js"></script> 
<script src="js/angular.min.js"></script> 
<script>alert("here");</script> 
<script src="js/controllers.js"></script> 
<script src="js/klass.min.js"></script> 
<script src="js/code.photoswipe.jquery-3.0.5.min.js"></script> 
<script src="js/maskedInput.js" type="text/javascript"></script> 
<script src="js/jquery.joyride.js"></script> 
<script src="js/jquery.fancybox.pack.js"></script> 
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script> 

腳本:

alert("p2 adding") 
document.addEventListener("deviceready", onDeviceReady, false); 

// PhoneGap is loaded and it is now safe to make calls PhoneGap methods 
// 
function onDeviceReady() { 
    alert("main.html: device is ready"); 
} 

$(window).load(function(){ 
    alert("window.load happening"); 
}) 
</script> 

<script> 

    var _gaq = _gaq || []; 
    _gaq.push(['_setAccount', 'UA-42023187-1']); 

    _gaq.push(['_trackPageview']); 

    (function() { 
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; 
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; 
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); 
    })(); 

    (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ 
    (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), 
    m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m) 
    })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); 

    ga('create', 'UA-42023187-1', 'openvino.com'); 
    ga('send', 'pageview'); 

</script> 

<script type="text/javascript"> 
    var objectToLike = window.location; 
    var FBactivated = false; 

    FB.init({ 
     appId  : '659381964079214', // App ID 
     channelURL : '', // Channel File, not required so leave empty 
     status  : true, // check login status 
     cookie  : true, // enable cookies to allow the server to access the session 
     oauth  : true, 
     xfbml  : true // parse XFBML 
    }); 
    FB.Event.subscribe('auth.authResponseChange', function(response) { 
     // Here we specify what we do with the response anytime this event occurs. 
     if (response.status === 'connected') { 
     getFriends(); 
     testAPI(); 
     FBactivated = true; 
     } 
    }); 

    function getFriends() { 
    var fbUserIDs = [] 
    FB.api('/me/friends', function(response) { 
     if(response.data) { 
      $.each(response.data,function(index,friend) { 
       var id = friend.id; 
       fbUserIDs.push(id); 
      }); 
      var dataString = "fbUserIDs="+fbUserIDs.join(); 
      $.ajax({ 
      type: "POST", 
      data: dataString, 
      async: false, 
      url: "http://m.openvino.com/Scripts/faveMatch.php" 
      }).done(function(data){ 
      console.log(data); 
      window.localStorage.setItem("fbFriends", data); 
      console.log("Saved"); 
      }); 
     } else { 
      alert("Error!"); 
     } 
    }); 
    } 

    function testAPI() { 
    FB.api('/me', function(response) { 
     //console.log(response, response.email); 
     var dataString2 = "id=" + response.id; 
     dataString2 += "&first_name=" + response.first_name; 
     dataString2 += "&last_name=" + response.last_name; 
     dataString2 += "&email=" + response.email; 
     console.log(dataString2); 
     $.ajax({ 
     type: "POST", 
     url: "http://m.openvino.com/Scripts/fbconnect.php", 
     data: dataString2 
     }).done(function(data){ 
     var dataJSON = $.parseJSON(data); 
     if (dataJSON[0].STATUS == "FAILURE") { 
      //console.log(dataJSON[0].MESSAGE); 
      return false; 
     } else if (dataJSON[0].STATUS == "SUCCESS") { 
      window.localStorage.setItem('email',dataJSON[0].COOKIE.email); 
      window.localStorage.setItem('password',dataJSON[0].COOKIE.password); 
      window.localStorage.setItem('name_first',dataJSON[0].COOKIE.name_first); 
      window.localStorage.setItem('name_last',dataJSON[0].COOKIE.name_last); 
      window.localStorage.setItem('uID',dataJSON[0].COOKIE.uID); 
      window.localStorage.setItem('phone',dataJSON[0].COOKIE.phone); 
      window.localStorage.setItem('firstTime',dataJSON[0].COOKIE.firstTime); 
     } 
     }); 
    }); 
    } 

    function fbLogout() { 
    if (FBactivated) { 
     try { 
     FB.logout(function(response) { 
      window.location.href = "index.html"; 
     }); 
     } catch (err) { 
     window.location.href = "index.html"; 
     } 
    } else { 
     window.location.href = "index.html"; 
    } 
    } 

    $(document).ready(function() { 
    alert("document.ready loaded"); 

    $("#logmeout").click(function(e){ 
     e.preventDefault(); 
     window.localStorage.clear(); 

     fbLogout(); 
     return false; 
    }); 

    $('.back_btn').click(function(e) { 
     $('.profile_menu').hide(); 
     history.back(); 
    }); 

    $(document).click(function(e) { 
     $('.profile_menu').hide(); 
    }) 

    $('.profile_btn').click(function(e) { 
     $('.profile_menu').slideToggle(); 
     e.stopPropagation(); 
     e.preventDefault(); 
     return false; 
    }); 

    $('.profile_menu a').each(function() { 
     $(this).click(function(e) { 
     $('.profile_menu').hide(); 
     }); 
    }); 
    }); 

HTML:

<body ng-app="OpenVino"> 
<div id="fb-root"></div> 
<div class="header-wrap"> 
    <header> 
    <div ng-show="(page != 'list')" class="back_btn"></div> 
    <a href="#" onclick="launchBrowser(http://facebook.com)"><img src="imgs/logo_only.png" alt="OpenVino" /></a> 
    <div class="profile_btn"></div> 
    </header> 
</div> 
<div class="profile_menu"> 
    <a href="#/users/">My Favorites</a> 
    <a href="#/aboutus/">Contact OpenVino</a> 
    <a href="#/lifestyle/">Images</a> 
    <a href="#" id="logmeout">Logout</a> 
</div> 
<div class="content {{page}}" ng-view></div> 

回答

0

我用一個簡單的固定,但令人沮喪的解決方案:你必須把你的畝ltipage應用程序轉換爲單頁應用程序。不幸的是,phonegap如何宣傳你可以把你的HTML,CSS和JS本地構建起來。在第二頁上加載的所有.js都不會起作用,直到我將登錄名更改爲部分路由並且繞過路由。

相關問題