Permalink
Browse files

Merge remote-tracking branch 'origin/master' into docs-fixes

Conflicts:
	www/_includes/nav-docs.md
  • Loading branch information...
2 parents e115273 + 87e6019 commit fcf48199224b2d423ad1802e9731857452b134e7 @noahadams noahadams committed Jan 7, 2013
View
@@ -310,7 +310,7 @@ var $ = Mobify.$
resource = resources[i];
if (resource.status == 'ready') {
save = true;
- httpCache.set(resource.url, resource)
+ httpCache.set(encodeURI(resource.url), resource)
}
}
View
@@ -10,16 +10,13 @@ var $ = Mobify.$
// A regex for detecting http(s) URLs.
, httpRe = /^https?/
- // A protocol relative URL for the host ir0.mobify.com.
- , PROTOCOL_AND_HOST = '//ir0.mobify.com'
-
/**
* Returns a URL suitable for use with the 'ir' service.
- */
+ */
, getImageURL = Mobify.getImageURL = function(url, options) {
options = options || {}
- var bits = [PROTOCOL_AND_HOST];
+ var bits = [defaults.host];
if (defaults.projectName) {
var projectId = "project-" + defaults.projectName;
@@ -44,11 +41,11 @@ var $ = Mobify.$
/**
* Searches the collection for image elements and modifies them to use
- * the Image Resize service. Pass `options` to modify how the images are
- * resized.
+ * the Image Resize service. Pass `options` to modify how the images are
+ * resized. Returns the collection of images that were modified.
*/
, resizeImages = $.fn.resizeImages = function(options) {
- var opts = $.extend(defaults, typeof options == 'object' && options)
+ var opts = $.extend({}, defaults, typeof options == 'object' && options)
, dpr = window.devicePixelRatio
, $imgs = this.filter(opts.selector).add(this.find(opts.selector))
, attr;
@@ -67,21 +64,23 @@ var $ = Mobify.$
}
}
- return $imgs.each(function() {
+ return $imgs.filter(function() {
if (attr = this.getAttribute(opts.attribute)) {
absolutify.href = attr;
var url = absolutify.href;
if (httpRe.test(url)) {
this.setAttribute('x-src', getImageURL(url, opts));
+ return true
}
}
});
}
, defaults = resizeImages.defaults = {
- selector: 'img[x-src]'
+ host: '//ir0.mobify.com'
+ , selector: 'img[x-src]'
, attribute: 'x-src'
, projectName: Mobify.config.projectName || ''
}
-})(this, Mobify, Math);
+})(this, Mobify, Math);
View
@@ -0,0 +1,113 @@
+/**
+ * Exposes the `Mobify.urlmatch`.
+ */
+(function() {
+
+/**
+ * Returns an escaped string that when passed to the regular expression
+ * contructor will match the literal contents of the string.
+ */
+var reEscape = function (str) {
+ return str.replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1");
+};
+
+var declareUrlMatch = function(window, Mobify) {
+
+ /**
+ * Given a a path expression `expr`, returns a RegExp that can be
+ * used to match a URL's path.
+ */
+ var getExpressionRegExp = function(expr) {
+ if (expr == "/*") {
+ return /.*/;
+ }
+
+ // # Expr Split RE
+ // A / [""] /^\/+$/
+ // B /*/ ["", "*", ""] /^\/+[^\/]+\/*$/
+ // C /a/ ["", "a", ""] /^\/+a\/*$/
+ // D /a ["", "a"] /^\/+a\/*$/
+ // E /a/* ["", "a", "*"] /^\/+a\/+.+$/
+ // F /a/b ["", "a", "b"] /^\/+a\/+b\/*$/
+ // G /a/b/ ["", "a", "b", ""] /^\/+a\/+b\/*$/
+ // H /a/b/* ["", "a", "b", "*"] /^\/+a\/+b\/+.+$/
+
+ var EMPTY = "";
+ var WILD = "*";
+ // Merge slashes.
+ var SLASH = "\\/+";
+
+ var bits = expr.slice(1).split("/");
+ var reStr = EMPTY;
+ var bit;
+
+ while (bits.length) {
+ bit = bits.shift();
+ if (bits.length) {
+ reStr += SLASH + ((bit == WILD) ? "[^\\/]+" : reEscape(bit));
+ } else {
+ // E
+ if (bit == WILD) {
+ reStr += ".+"
+ } else {
+ // D
+ if (bit != EMPTY) {
+ reStr += SLASH + reEscape(bit)
+ }
+ reStr += '\\/*';
+ }
+ }
+ }
+
+ var re = RegExp("^" + reStr + "$", "i");
+ return re
+ };
+
+ /**
+ * Given a path expression `expr`, or a regular expression, returns a
+ * function that can be used to match against the current window's path,
+ * `window.location.pathname`.
+ */
+ var urlmatch = function(expr) {
+ var exprIsRegExp, exprIsString, re;
+
+ exprIsRegExp = expr instanceof RegExp;
+ exprIsString = (typeof expr === 'string');
+
+ if (!(exprIsRegExp || exprIsString)) {
+ return false;
+ }
+ if (exprIsRegExp) {
+ re = expr;
+ } else {
+ re = getExpressionRegExp(expr);
+ }
+ return function() {
+ // Note, window is the closed-overarguemnt to the parent function,
+ // not necessarily the global window
+ return re.test(window.location.pathname) ? expr : false;
+ };
+ };
+
+ /**
+ * Allow the local variable `window` to be overridden. Useful for testing.
+ */
+ urlmatch.setWindow = function (newWindow) {
+ window = newWindow;
+ };
+
+ return urlmatch;
+};
+
+// Conditional loading using `define`, or adding to `Mobify`.
+if ((typeof define !== "undefined" && define !== null) && 'function' === typeof define) {
+ define([], function() {
+ return declareUrlMatch;
+ });
+}
+if ((typeof Mobify !== "undefined" && Mobify !== null) && 'object' === typeof Mobify &&
+ Mobify.urlmatch === undefined) {
+ Mobify.urlmatch = declareUrlMatch(window, Mobify);
+}
+
+})();
View
@@ -55,6 +55,9 @@
{>"/base/api/main.js"/}
{>"/base/api/resizeImages.js"/}
+{! Mobify Studio Compatible Url Matching !}
+{>"/base/api/urlmatch.js"/}
+
{+tmpl}
{>"/base/tmpl/*.tmpl"/}
{>"tmpl/*.tmpl"/}
Oops, something went wrong.

0 comments on commit fcf4819

Please sign in to comment.