0

我的 phonegap 应用程序中基本上有两个页面,我正在使用 PGB(index.html 和 main.html)构建它们,它们都使用 angular.js。Index.html 是应用程序的登录名,之后会重定向到 main.html。我所有的插件和 phonegap.js 都被很好地注入到 main 中,但是没有一个内联 JS(文档就绪、设备就绪、窗口加载的警报)被触发,更不用说加载 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>

4

1 回答 1

0

我用一个简单但令人沮丧的解决方案修复了它:您必须将多页应用程序变成单页应用程序。不幸的是,phonegap 如何宣传您可以使用 HTML、CSS 和 JS 并在本地构建它。在我将登录名更改为部分登录并愚弄路由之前,第二页上加载的所有 .js 都无法正常工作。

于 2013-08-20T18:06:42.710 回答