javascript - Using Require.js in a Cordova HTML ons-page -


i lost on how use require.js within html tag of "ons-button" html tag item (login.html). able use long embed code inside require statement (index.html). there no way use directly in html file isn't html. have tried using <script src=""></script> not know how access functions "returned" require.js. or direction great.

background: pretty new require.js. have got working somewhat, still having major problem. have login cordova app launched loginmain.html, keep code organized , in different files when possible. main page cordova app login.html. trying access functions store in auth.js.

the files available in zip: http://www.filedropper.com/requirejsquestion


code believe relevant:

loginmain.html (not working)

<!doctype html> <html > <head>     <!-- imports -->     <script>         ons.bootstrap();     </script> </head> <body>     <ons-navigator var="app.login" page="login.html">     </ons-navigator>           <script type="text/javascript">         require.config({    baseurl: "js/"   });         require(['auth'], function(auth)  {             ons.ready(function() {});         });     </script> </body> </html> 

login.html (not working)

<ons-page>      <ons-toolbar>         <div class="center">log in</div>         <div class="right"><ons-toolbar-button></ons-toolbar-button></div>       </ons-toolbar>             <div class="login-form">         <!-- other code -->             <ons-button modifier="quiet" id="googleplus" onclick="auth.googlereq()">                 sign in google             </ons-button>             <br>         <!-- other code -->       </div>  </ons-page> 

i tried (loginmain.html) in <body></body>

<body>     <script type="text/javascript">         var html = '<ons-navigator var="app.login" page="login.html"> \         </ons-navigator> \';          require.config({    baseurl: "js/"   });         require(['auth'], function(auth)  {             document.write(html);             ons.ready(function() {});         });     </script> </body> 

auth.js (believed correct)

define(function(require) {     //initialize oauth     oauth.initialize('mykey');      return {         //more functions         googlereq: function()       {             token = "none";              oauth.popup('google', {                 cache: true             })             .done(function(result) {               //use result.access_token in api request                //or use result.get|post|put|del|patch|me methods (see below)               token = result.access_token;               return token;              })             .fail(function (err) {               //handle error err               return token;             });         }          //more functions     }; }); 


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -