Restructuring of scripts to mimic Charcoal's autoload concept
This commit is contained in:
@@ -19,7 +19,8 @@
|
||||
<body>
|
||||
|
||||
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
|
||||
<script>window.jQuery || document.write('<script src="modules/boilerplate/assets/scripts/src/vendors/jquery-1.11.2.min.js"><\/script>')</script>
|
||||
<script src="modules/boilerplate/assets/scripts/dist/main.js"></script>
|
||||
<script>window.jQuery || document.write('<script src="modules/boilerplate/assets/scripts/dist/jquery-1.11.2.min.js"><\/script>')</script>
|
||||
<script src="modules/boilerplate/assets/scripts/dist/vendors.js"></script>
|
||||
<script src="modules/boilerplate/assets/scripts/dist/app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
45
www/modules/boilerplate/assets/scripts/src/app.js
Normal file
45
www/modules/boilerplate/assets/scripts/src/app.js
Normal file
@@ -0,0 +1,45 @@
|
||||
// App object
|
||||
var app = window.app || {};
|
||||
|
||||
// Initialize app
|
||||
app.init = function(){
|
||||
|
||||
'use strict';
|
||||
|
||||
var self = this;
|
||||
|
||||
self.params = {
|
||||
|
||||
};
|
||||
|
||||
self.elements = {
|
||||
html : document.documentElement,
|
||||
body : document.body
|
||||
};
|
||||
|
||||
// Init as empty and / or build
|
||||
self.templates = self.templates || {};
|
||||
|
||||
/* Template scripts pseudo loader
|
||||
========================================================================== */
|
||||
|
||||
// Identify the template we're using
|
||||
self.params.current_template = self.elements.body.getAttribute('data-template');
|
||||
|
||||
// Run the template script only if it's found
|
||||
if( typeof self.templates[ self.params.current_template ] === 'object' ){
|
||||
self.templates[ self.params.current_template ].init();
|
||||
}
|
||||
|
||||
/* Execute global site scripts
|
||||
========================================================================== */
|
||||
if( typeof self.Globals === 'object' ){
|
||||
self.Globals.init();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
// On doc ready, init your app
|
||||
$(function(){
|
||||
app.init();
|
||||
});
|
||||
@@ -0,0 +1,29 @@
|
||||
var app = window.app || {};
|
||||
|
||||
app.Globals = {
|
||||
|
||||
init : function(){
|
||||
|
||||
'use strict';
|
||||
|
||||
var self = this;
|
||||
|
||||
/* Site wide binds go here
|
||||
========================================================================== */
|
||||
if( $('.js-boilerplate-toggle').length ){
|
||||
|
||||
$('.js-boilerplate-toggle').on('click',function(event) {
|
||||
// toggle toggle
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
/* When all content has loaded, not just DOM
|
||||
========================================================================== */
|
||||
window.onload = function() {
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -1,3 +0,0 @@
|
||||
/* ==========================================================================
|
||||
Main
|
||||
========================================================================== */
|
||||
@@ -0,0 +1,17 @@
|
||||
// App object
|
||||
var app = window.app || {};
|
||||
// Templates object
|
||||
app.templates = app.templates || {};
|
||||
|
||||
/* ==========================================================================
|
||||
Generic template scripts
|
||||
============================================================================= */
|
||||
app.templates.generic = {
|
||||
|
||||
init:function(){
|
||||
|
||||
// Template specific code
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
@@ -86,7 +86,7 @@ class Boilerplate_Template_Controller extends Charcoal_Template_Controller
|
||||
* Read the documentation on `\Charcoal\Object_Loader` for more details.
|
||||
* In short, it allows to call the objects with `->texts()->ident;` // `{{sections.ident}}` to return (and load on-the-fly, if required)
|
||||
* the `CMS_Text` object with the `ident` "ident".
|
||||
*
|
||||
*
|
||||
* @return \Charcoal\Object_Loader
|
||||
* @see CMS_Section
|
||||
*/
|
||||
@@ -109,7 +109,7 @@ class Boilerplate_Template_Controller extends Charcoal_Template_Controller
|
||||
* Read the documentation on `\Charcoal\Object_Loader` for more details.
|
||||
* In short, it allows to call the objects with `->sections()->ident;` to return (and load on-the-fly, if required)
|
||||
* the `CMS_Section` object with the `ident` "ident".
|
||||
*
|
||||
*
|
||||
* @return \Charcoal\Object_Loader
|
||||
* @see CMS_Text
|
||||
*/
|
||||
@@ -187,7 +187,7 @@ class Boilerplate_Template_Controller extends Charcoal_Template_Controller
|
||||
* @see \Charcoal\Asset
|
||||
*/
|
||||
public function assets($asset_mode='url')
|
||||
{
|
||||
{
|
||||
$ret = [
|
||||
'images' => function($txt) use ($asset_mode) {
|
||||
return new \Charcoal\Asset('images', $txt, $asset_mode);
|
||||
@@ -208,4 +208,29 @@ class Boilerplate_Template_Controller extends Charcoal_Template_Controller
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the proper name of the template, usable for css class.
|
||||
*
|
||||
* (Replace invalid characters, such as a dot.)
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function template_class()
|
||||
{
|
||||
$token = $this->section()->template;
|
||||
$search = ["boilerplate_"];
|
||||
$replace = [""];
|
||||
$token = str_replace(".", "_", $token);
|
||||
|
||||
if ( is_numeric($token) ) {
|
||||
$token = preg_replace('/\D+/', '', $token);
|
||||
}
|
||||
else {
|
||||
$token = str_replace($search, $replace,$token);
|
||||
$token = preg_replace('/[^\w-]/', '', strtolower($token));
|
||||
}
|
||||
|
||||
return $token;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,18 @@
|
||||
module.exports = {
|
||||
main: {
|
||||
|
||||
app: {
|
||||
src: [
|
||||
'assets/scripts/src/main.js'
|
||||
'assets/scripts/src/app/*.js',
|
||||
'assets/scripts/src/templates/*.js',
|
||||
'assets/scripts/src/app.js'
|
||||
],
|
||||
dest: 'assets/scripts/dist/main.js',
|
||||
}
|
||||
}
|
||||
dest: 'assets/scripts/dist/app.js'
|
||||
},
|
||||
vendors: {
|
||||
src: [
|
||||
'assets/scripts/src/vendors/*.js'
|
||||
],
|
||||
dest: 'assets/scripts/dist/vendors.js'
|
||||
}
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user