Created
June 15, 2011 17:51
-
-
Save lsmith/1027653 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Y.config.base = YUI.config.base || Y.Env.getBase(Y.Env._BASE_RE); | |
// Regex in English: | |
// I'll start at the \b(simpleyui). | |
// 1. Look in the test string for "simpleyui" or "yui" or | |
// "yui-base" or "yui-rls" or "yui-foobar" that comes after a word break. That is, it | |
// can't match "foyui" or "i_heart_simpleyui". This can be anywhere in the string. | |
// 2. After #1 must come a forward slash followed by the string matched in #1, so | |
// "yui-base/yui-base" or "simpleyui/simpleyui" or "yui-pants/yui-pants". | |
// 3. The second occurence of the #1 token can optionally be followed by "-debug" or "-min", | |
// so "yui/yui-min", "yui/yui-debug", "yui-base/yui-base-debug". NOT "yui/yui-tshirt". | |
// 4. This is followed by ".js", so "yui/yui.js", "simpleyui/simpleyui-min.js" | |
// 0. Going back to the beginning, now. If all that stuff in 1-4 comes after a "?" in the string, | |
// then capture the junk between the LAST "&" and the string in 1-4. So | |
// "blah?foo/yui/yui.js" will capture "foo/" and "blah?some/thing.js&3.3.0/build/yui-rls/yui-rls.js" | |
// will capture "3.3.0/build/" | |
// | |
// Regex Exploded: | |
// (?:\? Find a ? | |
// (?:[^&]*&) followed by 0..n characters followed by an & | |
// * in fact, find as many sets of characters followed by a & as you can | |
// ([^&]*) capture the stuff after the last & in \1 | |
// )? but it's ok if all this ?junk&more_junk stuff isn't even there | |
// \b(simpleyui| after a word break find either the string "simpleyui" or | |
// yui(?:-\w+)? the string "yui" optionally followed by a -, then more characters | |
// ) and store the simpleyui or yui-* string in \2 | |
// \/\2 then comes a / followed by the simpleyui or yui-* string in \2 | |
// (?:-(min|debug))? optionally followed by "-min" or "-debug" | |
// .js and ending in ".js" | |
Y.Env._BASE_RE = /(?:\?(?:[^&]*&)*([^&]*))?\b(simpleyui|yui(?:-\w+)?)\/\2(?:-(min|debug))?\.js/; | |
... | |
getBase: G_ENV && G_ENV.getBase || | |
function(pattern) { | |
var nodes (doc && doc.getElementsByTagName('script')) || [], | |
path = Env.cdn, | |
i, len, src, match; | |
for (i = 0, len = nodes.length; i < len; ++i) { | |
src = nodes[i].src; | |
if (src) { | |
match = src.match(pattern); | |
if (match) { | |
path = RegExp.leftContext || src.slice(0, src.indexOf(match[0])); | |
// this is to set up the path to the loader. The file | |
// filter for loader should match the yui include. | |
filter = match[3]; | |
// extract correct path for mixed combo urls | |
// http://yuilibrary.com/projects/yui3/ticket/2528423 | |
if (match[1]) { | |
path += '?' + match[1]; | |
} | |
break; | |
} | |
} | |
} | |
// use CDN default | |
return path; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment