From 9c5f2546d54b26f570a46edb946aaf6500d05f42 Mon Sep 17 00:00:00 2001 From: Richard de Wit Date: Tue, 5 May 2015 11:52:03 +0200 Subject: [PATCH] Optional Bootstrap and FontAwesome lazyloading This makes Bootstrap and FontAwesome lasyloading possible, for if you don't want to use both/either of those to be used in the entire project, but just in the Admin interface. Usage: ```coffeescript @AdminConfig = # ... lazyLoad: { bootstrap: true fontawesome: true } ``` --- lib/both/router.coffee | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/both/router.coffee b/lib/both/router.coffee index 1bfc57b..6c9e0e6 100644 --- a/lib/both/router.coffee +++ b/lib/both/router.coffee @@ -1,3 +1,7 @@ +if Meteor.isClient + Session.set 'admin_bootstrap_loaded', false + Session.set 'admin_fontawesome_loaded', false + @AdminController = RouteController.extend layoutTemplate: 'AdminLayout' waitOn: -> @@ -22,6 +26,22 @@ if typeof AdminConfig?.nonAdminRedirectRoute == 'string' Router.go AdminConfig.nonAdminRedirectRoute + if AdminConfig.lazyLoad?.bootstrap and not Session.get('admin_bootstrap_loaded') + $("", { + rel: "stylesheet" + type: "text/css" + href: "//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" + }).appendTo('head') + Session.set 'admin_bootstrap_loaded', true + + if AdminConfig.lazyLoad?.fontawesome and not Session.get('admin_fontawesome_loaded') + $("", { + rel: "stylesheet" + type: "text/css" + href: "//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" + }).appendTo('head') + Session.set 'admin_fontawesome_loaded', true + @next() @@ -109,4 +129,4 @@ Router.route "adminDashboardEdit", Session.set 'admin_id', parseID(@params._id) Session.set 'admin_doc', adminCollectionObject(@params.collection).findOne _id : parseID(@params._id) data: -> - admin_collection: adminCollectionObject @params.collection \ No newline at end of file + admin_collection: adminCollectionObject @params.collection