Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //*********************************
- // From my index.html file
- //*********************************
- <script data-main="js/main" src="js/libs/require/require.js"></script>
- //*********************************
- // Main.js
- //*********************************
- require.config({
- paths:{
- jquery:'libs/jquery/jquery-1.7.2.min',
- underscore:'libs/underscore/underscore-min',
- backbone:'libs/backbone/backbone-min',
- text:'libs/require/text',
- order:'libs/require/order',
- xdomainajax:'libs/jquery/jquery.xdomainajax'
- //templates: '../templates'
- }
- });
- //Loading up the required library dependencies and the app.
- require([
- // Loading the libs
- 'order',
- 'text',
- 'order!jquery',
- 'order!xdomainajax',
- 'order!underscore',
- 'order!backbone'
- ]);
- define([
- // Load our app module and pass it to our definition function
- 'app'
- ], function (App)
- {
- // The "app" dependency is passed in as "App"
- // Again, the other dependencies passed in are not "AMD" therefore don't pass a parameter to this function
- App.initialize();
- }
- );
- //*********************************
- // App.js
- //*********************************
- define(
- [
- "order!ConfigModel",
- "order!router"
- ], function (configModel,Router)
- {
- var dataURL = "http://mysite.com/downloadJson.aspx?config=1&db=prod";
- var init = function ()
- {
- console.log('Loading: ' + dataURL);
- //Commenting the following try loading up the web service from the ConfigModel instead
- //getConfig(dataURL);
- }
- return {
- initialize:init
- };
- function initRouter()
- {
- console.log("Starting Router");
- new Router();
- Backbone.history.start();
- }
- //Load up the JSON here.
- function getConfig(url)
- {
- //NOTE: Was running into a xdomain issue here. Now loading using jquery.xdomainajax.js
- $.ajax({
- url:dataURL,
- type:'GET', //Need to use GET for the xdomainajax plugin to work.
- success:function (data)
- {
- venueAngles.disabled = false;
- venueLayers.disabled = false;
- if (data.responseText)
- {
- data = data.responseText.replace(/<script[^>]*>[\s\S]*?<\/script>/gi, '');
- data = data.replace(/<head[^>]*>[\s\S]*?<\/head>/gi, '');
- data = data.replace(/<body>/gi, "");
- data = data.replace(/<p>/gi, "");
- data = data.replace(/<\/p>/gi, "");
- data = data.replace(/<\/body>/gi, "");
- data = data.replace(/<html>/gi, "");
- data = data.replace(/<\/html>/gi, "");//To do need JSON instead of HTML
- data = jQuery.trim(data)
- data = JSON.parse(data);
- //Creating the ConfigModel and storing the JSON data in it.
- console.log(configModel);
- configModel.set({data:data});
- var modelData=configModel.get("data");
- console.log(modelData);
- //Start the router.
- initRouter();
- }
- }
- });
- }
- });
- //*********************************
- // ConfigModel.js
- //*********************************
- define([
- ], function ()
- {
- var ConfigModel = Backbone.Model.extend(
- {
- defaults:
- {
- data:null
- },
- initialize : function()
- {
- console.log("ConfigModel Initialized!")
- },
- url: "http://myservice.com/downloadJson.aspx?config=1&db=prod",
- parse: function(resp,xhr)
- {
- //Not getting any response here :(
- alert("Response!!");
- }
- });
- //Should I be creating the model here? I need it to be a singleton and exist
- //all through the application.. Also be injected into Views/Controllers
- var configModel = new ConfigModel;
- return configModel;
- }
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement