Skip to content
Permalink
Browse files

wb: Allow for specific directory paths via data attrs.

  • Loading branch information...
Andre D
Andre D committed Nov 25, 2015
1 parent 764c4b6 commit 1802d85a48893fe5d786bf432e3b41226fddfa89
Showing with 38 additions and 31 deletions.
  1. +38 −31 src/core/wb.js
@@ -57,7 +57,7 @@ var getUrlParts = function( url ) {
* @variable $src
* @return {jQuery Element} of wb script element
*/
$src = $( "script[src*='wet-boew.js'],script[src*='wet-boew.min.js']" )
$src = $( "script[src*='wet-boew.js'],script[src*='wet-boew.min.js'],script[data-wb-core]" )
.last(),

/**
@@ -66,27 +66,34 @@ var getUrlParts = function( url ) {
*/
lang = document.documentElement.lang,

/**
* @variable $homepath
* @return {string} of version current path to JS directory
*/
$homepath = $src.prop( "src" )
.split( "?" )[ 0 ].split( "/" )
.slice( 0, -1 )
.join( "/" ),

/**
* @variable $homecss
* @return {string} of version current path to CSS directory
*/
$homecss = $homepath.substring( 0, $homepath.length - 2 ) + "css",
paths = ( function( ele ) {
var paths = {};

paths.home = ele.prop( "src" )
.split( "?" )[ 0 ].split( "/" )
.slice( 0, -1 )
.join( "/" );
paths.assets = paths.home + "/../assets",
paths.template = paths.home + "/assets/templates";
paths.dep = paths.home + "/deps";
paths.js = paths.home;
paths.css = paths.home.substring( 0, paths.home.length - 2 ) + "css";
paths.mode = ele.prop( "src" ).indexOf( ".min" ) < 0 ? "" : ".min";

if ( ele[ 0 ].hasAttribute( "data-wb-core" ) ) {
$.extend( paths, {
home: ele.attr( "data-home" ),
asset: ele.attr( "data-asset" ),
template: ele.attr( "data-template" ),
dep: ele.attr( "data-dep" ),
js: ele.attr( "data-js" ),
css: ele.attr( "data-css" ),
mode: ele.attr( "data-mode" )
} );
}

/**
* @variable $mode
* @return {string} of version of JS [development or production]
*/
$mode = $src.prop( "src" )
.indexOf( ".min" ) < 0 ? "" : ".min",
return paths;
}( $src ) ),

/**
* @variable oldie
@@ -133,12 +140,12 @@ var getUrlParts = function( url ) {
*-----------------------------
*/
wb = {
"/": $homepath,
"/assets": $homepath + "/../assets",
"/templates": $homepath + "/assets/templates",
"/deps": $homepath + "/deps",
"/": paths.home,
"/assets": paths.asset,
"/templates": paths.template,
"/deps": paths.dep,
lang: lang,
mode: $mode,
mode: paths.mode,
doc: $( document ),
win: $( window ),
html: $( "html" ),
@@ -408,7 +415,7 @@ window.wb = wb;
* @prefix: site! - adds the root js directory of yepnope resources
*/
yepnope.addPrefix( "site", function( resourceObj ) {
resourceObj.url = $homepath + "/" + resourceObj.url;
resourceObj.url = paths.js + "/" + resourceObj.url;
return resourceObj;
} );

@@ -421,15 +428,15 @@ yepnope.addPrefix( "plyfll", function( resourceObj ) {

if ( disabled && url.indexOf( "svg" ) === -1 ) {
resourceObj.bypass = true;
} else if ( !$mode ) {
} else if ( !paths.mode ) {
url = url.replace( ".min", "" );
}

if ( url.indexOf( ".css" ) !== -1 ) {
resourceObj.forceCSS = true;
path = $homecss;
path = paths.css;
} else {
path = $homepath;
path = paths.js;
}
resourceObj.url = path + "/polyfills/" + url;

@@ -440,7 +447,7 @@ yepnope.addPrefix( "plyfll", function( resourceObj ) {
* @prefix: i18n! - adds the correct document language for our i18n library
*/
yepnope.addPrefix( "i18n", function( resourceObj ) {
resourceObj.url = $homepath + "/" + resourceObj.url + lang + $mode + ".js";
resourceObj.url = paths.js + "/" + resourceObj.url + lang + paths.mode + ".js";
return resourceObj;
} );

0 comments on commit 1802d85

Please sign in to comment.
You can’t perform that action at this time.