dbiele / TypeScript-Cordova-SystemJS-Angular2-beta

VS2015 project created using TypeScript, Cordova, SystemJS, Angular beta
28 stars 14 forks source link

Question about the cordova.js #5

Closed sunshineo closed 8 years ago

sunshineo commented 8 years ago

In your index.html

I'm also serving the www folder to the web for browsers, and after added this, it gives me 404 all the time (of course it does). How to dynamically include this file based on platform? Or if possible, I would prefer to add this when I do cordova build. Is this possible?

Thank you very much!

DeanB2015 commented 8 years ago

@sunshineo I just saw you message. I'll be able to look into this later today, but wanted to ask a few questions to clarify:

Thanks, Dean

sunshineo commented 8 years ago

I'm looking for something like this. This uses jquery mobile to detect and decide if include cordova.js or not https://gist.github.com/dhavaln/2886774 But I don't like that it uses jquery mobile

DeanB2015 commented 8 years ago

@sunshineo Thanks for the link and the clarification. I believe a modification to \scripts\index.ts will provide the solution to your feature request.

/**
 * Waits for Cordova or if not on a device and cordova is not needed, don't wait and call onDeviceReady.
 */
function initializeCordova(): void {
    if (!window.cordova) {
//Add your web browser code here.
        onDeviceReady();
    } else {
        document.addEventListener('deviceready', onDeviceReady, false);
    }
}

the if (!window.cordova) { detects if window.cordova exists. window.cordova only exists when on a mobile device. Adding code in this if statement will run in a web browser.

Does this answer your questions? I hope this helps.

Thanks

Dean

sunshineo commented 8 years ago

What about the script tag <script src="cordova.js"></script> ?

Should I place cordova.js also for my web, so it does not create a 404?

DeanB2015 commented 8 years ago

@sunshineo The 404 are appearing for the cordova.js and scripts/platformOverrides.js. Both of the files are generated when building the project as a mobile app in VS2015. However, if the code is run in a browser, the files don't exist.
404-errors

I just updated the repo to include placeholder cordova.js and scripts/platformOverrides.js files. The files only contains comments to clarify their purpose. I think this solves the 404 problem?

Let me know what you think.

Dean

sunshineo commented 8 years ago

I think it's a good idea!

On Wednesday, March 9, 2016, DeanB2015 notifications@github.com wrote:

The 404 are appearing for the cordova.js and scripts/platformOverrides.js. Both of the files are generated when building the project as a mobile app in VS2015. However, if the code is run in a browser, the files don't exist.

[image: 404-errors] https://cloud.githubusercontent.com/assets/10567383/13657683/0fec46f6-e63f-11e5-9806-3530cd1fb255.PNG

I just updated the repo to include placeholder cordova.js and scripts/platformOverrides.js files. The files only contains comments to clarify their purpose. I think this solves the 404 problem?

Let me know what you think.

Dean

— Reply to this email directly or view it on GitHub https://github.com/dbiele/TypeScript-Cordova-SystemJS-Angular2-beta/issues/5#issuecomment-194630585 .