Created
September 17, 2012 14:24
-
-
Save k33g/3737644 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
yepnope.addPrefix('tpl', function(resourceObj){ | |
function load (url, callback) { | |
var xhr, tpl; | |
xhr = window.ActiveXObject ? new window.ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest(); | |
xhr.open('GET', url, true); | |
if ('overrideMimeType' in xhr) { | |
xhr.overrideMimeType('text/plain'); | |
} | |
xhr.onreadystatechange = function() { | |
var _ref; | |
if (xhr.readyState === 4) { | |
if ((_ref = xhr.status) === 0 || _ref === 200) { | |
tpl = xhr.responseText; | |
} else { | |
throw new Error("Could not load " + url); | |
} | |
if (callback) { | |
return callback(tpl); | |
} | |
} | |
}; | |
return xhr.send(null); | |
}; | |
resourceObj.noexec = true; | |
var idOfTemplate = resourceObj.url.split("/").slice(-1)[0].split(".tpl")[0]; | |
idOfTemplate = "tpl_"+idOfTemplate; | |
yepnope.injectJs(null,function(){},{type: "text/template", id:idOfTemplate}); | |
load(resourceObj.url, function(template) { | |
document.querySelector("#"+idOfTemplate).innerHTML = template; | |
}); | |
return resourceObj; | |
}); | |
yepnope({ | |
load: { | |
//Vendors | |
jquery : 'libs/vendors/jquery-1.7.2.js', | |
underscore : 'libs/vendors/underscore.js', | |
backbone : 'libs/vendors/backbone.js', | |
mustache : 'libs/vendors/mustache.js', | |
//NameSpace | |
blog : 'Blog.js', | |
//Models | |
posts : 'models/post.js', | |
//Controllers | |
sidebarview : 'views/SidebarView.js', | |
postslistviews : 'views/PostsListView.js', | |
mainview : 'views/MainView.js', | |
loginview : 'views/LoginView.js', | |
postview : 'views/PostView.js', | |
//Templates | |
tpl_loginview : 'tpl!views/LoginView.tpl', | |
tpl_sidebarview : 'tpl!views/SidebarView.tpl', | |
tpl_postslistviews : 'tpl!views/PostsListView.tpl', | |
tpl_postview : 'tpl!views/PostView.tpl', | |
//Routes | |
routes : 'routes.js' | |
}, | |
callback : { | |
}, | |
complete : function () { | |
$(function (){ | |
console.log("Lauching application ..."); | |
window.blogPosts = new Blog.Collections.Posts(); | |
window.mainView = new Blog.Views.MainView({collection : blogPosts}); | |
/*======= Authentification =======*/ | |
window.loginView = new Blog.Views.LoginView(); | |
/*======= Fin authentification =======*/ | |
window.postView = new Blog.Views.PostView(); | |
window.router = new Blog.Router.RoutesManager({collection:blogPosts}); | |
//Backbone.history.start({pushState: true}); | |
Backbone.history.start(); | |
}); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment