adaptivejs
Advanced tools
Comparing version 0.1.14 to 0.1.15
@@ -99,4 +99,3 @@ define(['dust-core', 'adaptivejs/utils'], function(dust, Utils){ | ||
dust.helpers.getUrl = function(chunk, context, bodies, params) { | ||
var baseUrl = params.baseUrl !== undefined ? params.baseUrl : context.get('config.buildDirectory'); | ||
var url = Utils.getAssetUrl(baseUrl, params.path); | ||
var url = Utils.getAssetUrl(params.path, params.baseUrl, params.cacheBreaker); | ||
return chunk.write(url); | ||
@@ -103,0 +102,0 @@ }; |
{ | ||
"name": "adaptivejs", | ||
"version": "0.1.14", | ||
"version": "0.1.15", | ||
"description": "A framework for creating adaptive websites.", | ||
@@ -5,0 +5,0 @@ "author": { |
@@ -75,4 +75,5 @@ define(['adaptivejs/context', | ||
if (capturing) { | ||
// Setup the logger and initialize the start time | ||
Logger.init(Mobify.points[0]); | ||
Logger.init(Mobify.points[0], Utils.isDebug()); | ||
@@ -79,0 +80,0 @@ // Grab reference to a newly created document |
@@ -1,2 +0,5 @@ | ||
define(['text!package'], function(package) { | ||
define([ | ||
'adaptivejs/utils', | ||
'text!package' | ||
], function(Utils, package) { | ||
@@ -6,3 +9,3 @@ var projectName; | ||
try { | ||
packageInfo = JSON.parse(package); | ||
var packageInfo = JSON.parse(package); | ||
projectName = packageInfo.name; | ||
@@ -17,21 +20,11 @@ } catch (e) { | ||
*/ | ||
function getContext(doc) { | ||
function getContext() { | ||
var defaultContext = {}; | ||
var config = {}; | ||
var match = /mobify-path=([^&;]*)/g.exec(doc.cookie); | ||
config.projectName = projectName; | ||
config.buildDirectory = '//localhost:8080/'; | ||
config.isDebug = Utils.isDebug; | ||
config.adaptiveBuild = Utils.getAdaptiveBuild(); | ||
config.buildOrigin = Utils.getBuildOrigin(); | ||
// If the mobify-path cookie is present, then we are in debug mode | ||
config.isDebug = (match ? 1 : 0); | ||
try { | ||
var adaptiveBuildSrc = doc.querySelectorAll('script[src]')[0]; | ||
config.adaptiveBuild = adaptiveBuildSrc ? adaptiveBuildSrc.src : ''; | ||
config.buildDirectory = config.adaptiveBuild.replace(/\/[^\/]*$/, '/'); | ||
} catch (e) { | ||
console.error('Couldn\'t determine adaptivejs build file used. The mobify-tag may be placed incorrectly.'); | ||
} | ||
defaultContext.config = config; | ||
@@ -38,0 +31,0 @@ return defaultContext; |
define([ | ||
'adaptivejs/defaults', | ||
'adaptivejs/utils' | ||
], function(defaults, Utils) { | ||
], function(Utils) { | ||
@@ -42,3 +41,3 @@ var Logger = {}; | ||
// we will have to change this, too. | ||
debug = debug !== undefined ? debug : !!defaults.getContext(document).config.isDebug; | ||
debug = debug !== undefined ? debug : false; | ||
start = start || +new Date(); | ||
@@ -45,0 +44,0 @@ |
define([ | ||
'adaptivejs/selectorEngine', | ||
'mobifyjs/utils', | ||
'buildConfig' | ||
], function(Utils, buildConfig) { | ||
], function($, Utils, buildConfig) { | ||
@@ -64,6 +65,37 @@ var AdaptiveUtils = {}; | ||
/** | ||
* Returns the url of the adaptive.js build file and caches it | ||
*/ | ||
var cachedBuildScript; | ||
AdaptiveUtils.getAdaptiveBuild = function() { | ||
try { | ||
cachedBuildScript = cachedBuildScript || $('script[x-src]')[0].getAttribute('x-src') || ''; | ||
return cachedBuildScript; | ||
} catch (e) { | ||
console.error('Couldn\'t determine adaptivejs build file used. The mobify-tag may be placed incorrectly.'); | ||
} | ||
}; | ||
/** | ||
* Grabs the location of the build so we can reference assets | ||
* with absolute urls | ||
*/ | ||
AdaptiveUtils.getBuildOrigin = function() { | ||
var buildOrigin = '//localhost:8080/'; | ||
try { | ||
var adaptiveBuild = this.getAdaptiveBuild(); | ||
buildOrigin = adaptiveBuild.replace(/\/[^\/]*$/, '/'); | ||
} catch (e) { | ||
console.error('Couldn\'t determine adaptivejs build file used. The mobify-tag may be placed incorrectly.'); | ||
} | ||
return buildOrigin; | ||
}; | ||
/** | ||
* Returns the full url for the provided asset path | ||
* including a cache breaker | ||
* including a cache breaker. | ||
* basePath and cacheBreaker arguments are optional | ||
*/ | ||
AdaptiveUtils.getAssetUrl = function(basePath, path, cacheBreaker) { | ||
AdaptiveUtils.getAssetUrl = function(path, baseUrl, cacheBreaker) { | ||
var hash = buildConfig.cacheHashManifest[path]; | ||
@@ -75,7 +107,17 @@ | ||
} | ||
return basePath + path + '?' + cacheBreaker; | ||
return (baseUrl || this.getBuildOrigin()) + path + '?' + cacheBreaker; | ||
}; | ||
/** | ||
* If the mobify-path cookie is present, then we are in debug mode | ||
*/ | ||
AdaptiveUtils.isDebug = function() { | ||
var match = /mobify-path=([^&;]*)/g.exec(document.cookie); | ||
return (match ? 1 : 0); | ||
}; | ||
return AdaptiveUtils; | ||
}); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
140310
32
3113