ajaxlibs 0.1.11 → 0.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,5 @@
1
+ // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2
+ // Use of this source code is governed by a BSD-style license that can be
3
+ // found in the LICENSE file.
4
+
5
+ (function(e){if(!e.CFInstall){var f=function(a,b){return typeof a=="string"?(b||document).getElementById(a):a},h=function(){if(e.CFInstall._force)return e.CFInstall._forceValue;if(navigator.userAgent.toLowerCase().indexOf("chromeframe")>=0)return true;if(typeof window.ActiveXObject!="undefined")try{if(new ActiveXObject("ChromeTab.ChromeFrame"))return true}catch(a){}return false},i=function(a){try{var b=document.createElement("style");b.setAttribute("type","text/css");if(b.styleSheet)b.styleSheet.cssText=a;else b.appendChild(document.createTextNode(a));var c=document.getElementsByTagName("head")[0];c.insertBefore(b,c.firstChild)}catch(g){}},j=false,k=false,n=function(){if(!j){i('.chromeFrameInstallDefaultStyle {width: 800px;height: 600px;position: absolute;left: 50%;top: 50%;margin-left: -400px;margin-top: -300px;}.chromeFrameOverlayContent {position: absolute;margin-left: -400px;margin-top: -300px;left: 50%;top: 50%;border: 1px solid #93B4D9;background-color: white;z-index: 2001;}.chromeFrameOverlayContent iframe {width: 800px;height: 600px;border: none;}.chromeFrameOverlayCloseBar {height: 1em;text-align: right;background-color: #CADEF4;}.chromeFrameOverlayUnderlay {position: absolute;width: 100%;height: 100%;background-color: white;opacity: 0.5;-moz-opacity: 0.5;-webkit-opacity: 0.5;-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=50)";filter: alpha(opacity=50);z-index: 2000;}');j=true}},l=function(){if(!k){i(".chromeFrameOverlayContent { display: none; }.chromeFrameOverlayUnderlay { display: none; }");document.cookie="disableGCFCheck=1;path=/;max-age=31536000000";k=true}},o=function(a,b){var c=f(b.node);a.id=b.id||(c?c.id||getUid(c):"");a.style.cssText=" "+(b.cssText||"");a.className=b.className||"";a.src=b.src||"about:blank";c&&c.parentNode.replaceChild(a,c)},m=function(a){var b=document.createElement("iframe");b.setAttribute("frameborder","0");b.setAttribute("border","0");o(b,a);return b},p=function(a){a.className="chromeFrameInstallDefaultStyle "+(a.className||"");a=m(a);a.parentNode||document.body.insertBefore(a,document.body.firstChild)},q=function(a){if(!f("chromeFrameOverlayContent")){var b=document.createElement("span");b.innerHTML='<div class="chromeFrameOverlayUnderlay"></div><table class="chromeFrameOverlayContent"id="chromeFrameOverlayContent"cellpadding="0" cellspacing="0"><tr class="chromeFrameOverlayCloseBar"><td><button id="chromeFrameCloseButton">close</button></td></tr><tr><td id="chromeFrameIframeHolder"></td></tr></table>';for(var c=document.body;b.firstChild;)c.insertBefore(b.lastChild,c.firstChild);a=m(a);f("chromeFrameIframeHolder").appendChild(a);f("chromeFrameCloseButton").onclick=l}},d={};d.check=function(a){a=a||{};var b=navigator.userAgent,c=/MSIE (\S+); Windows NT/,g=false;if(c.test(b)){if(parseFloat(c.exec(b)[1])<6&&b.indexOf("SV1")<0)g=true}else g=true;if(!g){n();document.cookie.indexOf("disableGCFCheck=1")>=0&&l();b=(document.location.protocol=="https:"?"https:":"http:")+"//www.google.com/chromeframe";if(!h()){a.onmissing&&a.onmissing();a.src=a.url||b;b=a.mode||"inline";if(!(a.preventPrompt||0))if(b=="inline")p(a);else b=="overlay"?q(a):window.open(a.src);if(!a.preventInstallDetection)var r=setInterval(function(){if(h()){a.oninstall&&a.oninstall();clearInterval(r);window.location=a.destination||window.location}},2E3)}}};d._force=false;d._forceValue=false;d.isAvailable=h;e.CFInstall=d}})(this.ChromeFrameInstallScope||this);
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright 2010 Small Batch, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ * use this file except in compliance with the License. You may obtain a copy of
6
+ * the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ * License for the specific language governing permissions and limitations under
14
+ * the License.
15
+ */
16
+ ;(function(window,document,undefined){
17
+ webfont={};webfont.Q=function(a,b){var c=arguments.length>2?Array.prototype.slice.call(arguments,2):[];return function(){c.push.apply(c,arguments);return b.apply(a,c)}};webfont.z=function(a){this.R=a};webfont.z.prototype.createElement=function(a,b,c){a=this.R.createElement(a);if(b)for(var d in b)b.hasOwnProperty(d)&&a.setAttribute(d,b[d]);c&&a.appendChild(this.R.createTextNode(c));return a};function i(a,b,c){a=a.R.getElementsByTagName(b)[0];if(!a)a=document.documentElement;if(a&&a.lastChild){a.insertBefore(c,a.lastChild);return true}return false}function m(a,b){function c(){document.body?b():setTimeout(c,0)}c()}
18
+ function n(a,b){if(b.parentNode){b.parentNode.removeChild(b);return true}return false}function o(a,b){return a.createElement("link",{rel:"stylesheet",href:b})}function p(a,b,c){a=b.className.split(/\s+/);for(var d=0,e=a.length;d<e;d++)if(a[d]==c)return;a.push(c);b.className=a.join(" ").replace(/^\s+/,"")}function q(a,b,c){a=b.className.split(/\s+/);for(var d=[],e=0,f=a.length;e<f;e++)a[e]!=c&&d.push(a[e]);b.className=d.join(" ").replace(/^\s+/,"").replace(/\s+$/,"")};webfont.o=function(a,b,c,d,e,f){this.Aa=a;this.Ga=b;this.Fa=c;this.Ea=d;this.Ca=e;this.Z=f};webfont.o.prototype.getName=function(){return this.Aa};webfont.e=function(a){this.a=a};webfont.e.f="Unknown";webfont.e.sa=new webfont.o(webfont.e.f,webfont.e.f,webfont.e.f,false);webfont.e.prototype.parse=function(){return this.a.indexOf("MSIE")!=-1?r(this):this.a.indexOf("Opera")!=-1?s(this):this.a.indexOf("AppleWebKit")!=-1?t(this):this.a.indexOf("Gecko")!=-1?u(this):webfont.e.sa};
19
+ function v(a){var b=w(a,a.a,/(iPod|iPad|iPhone|Android)/);if(b!="")return b;a=w(a,a.a,/(Linux|Mac_PowerPC|Macintosh|Windows)/);if(a!=""){if(a=="Mac_PowerPC")a="Macintosh";return a}return webfont.e.f}function r(a){var b=w(a,a.a,/(MSIE [\d\w\.]+)/);if(b!=""){var c=b.split(" ");b=c[0];c=c[1];return new webfont.o(b,c,b,c,v(a),x(a,c)>=6)}return new webfont.o("MSIE",webfont.e.f,"MSIE",webfont.e.f,v(a),false)}
20
+ function s(a){var b=webfont.e.f,c=webfont.e.f,d=w(a,a.a,/(Presto\/[\d\w\.]+)/);if(d!=""){c=d.split("/");b=c[0];c=c[1]}else{if(a.a.indexOf("Gecko")!=-1)b="Gecko";d=w(a,a.a,/rv:([^\)]+)/);if(d!="")c=d}if(a.a.indexOf("Version/")!=-1){d=w(a,a.a,/Version\/([\d\.]+)/);if(d!="")return new webfont.o("Opera",d,b,c,v(a),x(a,d)>=10)}d=w(a,a.a,/Opera[\/ ]([\d\.]+)/);if(d!="")return new webfont.o("Opera",d,b,c,v(a),x(a,d)>=10);return new webfont.o("Opera",webfont.e.f,b,c,v(a),false)}
21
+ function t(a){var b=v(a),c=w(a,a.a,/AppleWebKit\/([\d\.\+]+)/);if(c=="")c=webfont.e.f;var d=webfont.e.f;if(a.a.indexOf("Chrome")!=-1)d="Chrome";else if(a.a.indexOf("Safari")!=-1)d="Safari";var e=webfont.e.f;if(a.a.indexOf("Version/")!=-1)e=w(a,a.a,/Version\/([\d\.\w]+)/);else if(d=="Chrome")e=w(a,a.a,/Chrome\/([\d\.]+)/);var f=w(a,c,/\d+\.(\d+)/);return new webfont.o(d,e,"AppleWebKit",c,b,x(a,c)>=526||x(a,c)>=525&&parseInt(f)>=13)}
22
+ function u(a){var b=webfont.e.f,c=webfont.e.f,d=false;if(a.a.indexOf("Firefox")!=-1){b="Firefox";var e=w(a,a.a,/Firefox\/([\d\w\.]+)/);if(e!=""){d=w(a,e,/\d+\.(\d+)/);c=e;d=e!=""&&x(a,e)>=3&&parseInt(d)>=5}}else if(a.a.indexOf("Mozilla")!=-1)b="Mozilla";e=w(a,a.a,/rv:([^\)]+)/);if(e=="")e=webfont.e.f;else if(!d){d=x(a,e);var f=parseInt(w(a,e,/\d+\.(\d+)/)),h=parseInt(w(a,e,/\d+\.\d+\.(\d+)/));d=d>1||d==1&&f>9||d==1&&f==9&&h>=2||e.match(/1\.9\.1b[123]/)!=null||e.match(/1\.9\.1\.[\d\.]+/)!=null}return new webfont.o(b,
23
+ c,"Gecko",e,v(a),d)}function x(a,b){a=w(a,b,/(\d+)/);if(a!="")return parseInt(a);return-1}function w(a,b,c){if((a=b.match(c))&&a[1])return a[1];return""};webfont.d=function(a,b,c,d){this.c=a;this.j=b;this.ba=c;this.q=d||webfont.d.oa;this.p=new webfont.F("-")};webfont.d.oa="wf";webfont.d.u="loading";webfont.d.D="active";webfont.d.I="inactive";webfont.d.O="font";function y(a){p(a.c,a.j,a.p.h(a.q,webfont.d.u));A(a,webfont.d.u)}function B(a,b,c){q(a.c,a.j,a.p.h(a.q,b,c,webfont.d.u));p(a.c,a.j,a.p.h(a.q,b,c,webfont.d.D));A(a,webfont.d.O+webfont.d.D,b,c)}function C(a){p(a.c,a.j,a.p.h(a.q,webfont.d.I));A(a,webfont.d.I)}
24
+ function D(a){q(a.c,a.j,a.p.h(a.q,webfont.d.u));p(a.c,a.j,a.p.h(a.q,webfont.d.D));A(a,webfont.d.D)}function A(a,b,c,d){a.ba[b]&&a.ba[b](c,d)};webfont.qa=function(){this.ia={}};function E(a,b){var c=[];for(var d in b)if(b.hasOwnProperty(d)){var e=a.ia[d];e&&c.push(e(b[d]))}return c};webfont.t=function(a,b,c,d,e){this.c=a;this.v=b;this.S=c;this.L=d;this.fa=e;this.ca=0;this.X=this.ha=false;this.za=new webfont.$;this.M=new webfont.g};webfont.t.aa="DEFAULT_FONT";webfont.t.pa="n4";
25
+ webfont.t.prototype.watch=function(a,b,c){for(var d=a.length,e=0;e<d;e++){var f=a[e];b[f]||(b[f]=[webfont.t.pa]);this.ca+=b[f].length}if(c)this.ha=c;for(e=0;e<d;e++){f=a[e];c=b[f];for(var h=0,k=c.length;h<k;h++){var g=c[h],j=F(this,webfont.t.aa,g),z=this.S.T(j);n(this.c,j);j=f;var l=this.v;p(l.c,l.j,l.p.h(l.q,j,g,webfont.d.u));A(l,webfont.d.O+webfont.d.u,j,g);l=F(this,j,g);if(z!=this.S.T(l)){n(this.c,l);B(this.v,j,g);this.X=true;G(this)}else H(this,this.fa(),z,l,j,g)}}};
26
+ function G(a){if(--a.ca==0&&a.ha)a.X?D(a.v):C(a.v)}webfont.t.prototype.wa=function(a,b,c,d,e){if(b!=this.S.T(c)){n(this.c,c);B(this.v,d,e);this.X=true;G(this)}else if(this.fa()-a<5E3)H(this,a,b,c,d,e);else{n(this.c,c);a=this.v;q(a.c,a.j,a.p.h(a.q,d,e,webfont.d.u));p(a.c,a.j,a.p.h(a.q,d,e,webfont.d.I));A(a,webfont.d.O+webfont.d.I,d,e);G(this)}};function H(a,b,c,d,e,f){a.L(function(h,k){return function(){k.call(h,b,c,d,e,f)}}(a,a.wa),50)}
27
+ function F(a,b,c){b=a.za.quote(b);c=a.M.expand(c);c=a.c.createElement("span",{style:"position:absolute;top:-999px;font-size:300px;font-family:"+b+","+webfont.t.aa+";"+c},"Mm");i(a.c,"html",c);return c};webfont.C=function(a,b,c,d,e){this.c=a;this.da=b;this.j=c;this.L=d;this.a=e;this.V=this.W=0};webfont.C.prototype.K=function(a,b){this.da.ia[a]=b};webfont.C.prototype.load=function(a){var b=new webfont.d(this.c,this.j,a);this.a.Z?I(this,b,a):C(b)};webfont.C.prototype.xa=function(a,b,c,d){if(d)a.load(webfont.Q(this,this.Ba,b,c));else{a=--this.W==0;this.V--;if(a)this.V==0?C(b):y(b);c.watch([],{},a)}};
28
+ webfont.C.prototype.Ba=function(a,b,c,d){var e=--this.W==0;e&&y(a);this.L(webfont.Q(this,function(f,h,k,g){f.watch(h,k||{},g)},b,c,d,e))};function I(a,b,c){c=E(a.da,c);a.V=a.W=c.length;for(var d=new webfont.t(a.c,b,{T:function(k){return k.offsetWidth}},a.L,function(){return+new Date}),e=0,f=c.length;e<f;e++){var h=c[e];h.Y(a.a,webfont.Q(a,a.xa,h,b,d))}};webfont.F=function(a){this.ya=a||webfont.F.na};webfont.F.na="-";webfont.F.prototype.h=function(){for(var a=[],b=0;b<arguments.length;b++)a.push(arguments[b].replace(/[\W_]+/g,"").toLowerCase());return a.join(this.ya)};webfont.$=function(){this.ka='"'};webfont.$.prototype.quote=function(a){var b=[];a=a.split(/,\s*/);for(var c=0;c<a.length;c++){var d=a[c].replace(/['"]/g,"");d.indexOf(" ")==-1?b.push(d):b.push(this.ka+d+this.ka)}return b.join(",")};webfont.g=function(){this.N=webfont.g.ra;this.s=webfont.g.ta};webfont.g.ra=["font-style","font-weight"];webfont.g.ta={"font-style":[["n","normal"],["i","italic"],["o","oblique"]],"font-weight":[["1","100"],["2","200"],["3","300"],["4","400"],["5","500"],["6","600"],["7","700"],["8","800"],["9","900"],["4","normal"],["7","bold"]]};webfont.g.J=function(a,b,c){this.ga=a;this.Da=b;this.s=c};
29
+ webfont.g.J.prototype.compact=function(a,b){for(var c=0;c<this.s.length;c++)if(b==this.s[c][1]){a[this.ga]=this.s[c][0];return}};webfont.g.J.prototype.expand=function(a,b){for(var c=0;c<this.s.length;c++)if(b==this.s[c][0]){a[this.ga]=this.Da+":"+this.s[c][1];return}};
30
+ webfont.g.prototype.compact=function(a){var b=["n","4"];a=a.split(";");for(var c=0,d=a.length;c<d;c++){var e=a[c].replace(/\s+/g,"").split(":");if(e.length==2){var f=e[1];a:{e=e[0];for(var h=0;h<this.N.length;h++)if(e==this.N[h]){e=new webfont.g.J(h,e,this.s[e]);break a}e=null}e&&e.compact(b,f)}}return b.join("")};
31
+ webfont.g.prototype.expand=function(a){if(a.length!=2)return null;for(var b=[null,null],c=0,d=this.N.length;c<d;c++){var e=this.N[c],f=a.substr(c,1);(new webfont.g.J(c,e,this.s[e])).expand(b,f)}return b[0]&&b[1]?b.join(";")+";":null};window.WebFont=function(){var a=new webfont.z(document),b=(new webfont.e(navigator.userAgent)).parse();return new webfont.C(a,new webfont.qa,document.documentElement,function(c,d){setTimeout(c,d)},b)}();window.WebFont.load=window.WebFont.load;window.WebFont.addModule=window.WebFont.K;webfont.H=function(a){this.va=a||webfont.H.ma;this.m=null};webfont.H.ma="//fonts.googleapis.com/css";webfont.H.prototype.h=function(){if(!this.m)throw new Error("No fonts to load !");for(var a=this.m.length,b=[],c=0;c<a;c++)b.push(this.m[c].replace(/ /g,"+"));return this.va+"?family="+b.join("%7C")};webfont.G=function(a){this.m=a;this.ja=[];this.la={};this.M=new webfont.g};webfont.G.ua={ultralight:"n2",light:"n3",regular:"i4",bold:"i7",italic:"i4",bolditalic:"i7",ul:"n2",l:"n3",r:"n4",b:"n7",i:"i4",bi:"i7"};
32
+ webfont.G.prototype.parse=function(){for(var a=this.m.length,b=0;b<a;b++){var c=this.m[b].split(":"),d=c[0],e=null;if(c.length==2){var f=[];c=c[1].split(",");for(var h=c.length,k=0;k<h;k++){var g;g=c[k];if(g.match(/^[\w ]+$/)){var j=webfont.G.ua[g];if(j)g=j;else{j=g.match(/^(\d*)(\w*)$/);g=j[1];j=j[2];g=(g=this.M.expand([j?j:"n",g?g.substr(0,1):"4"].join("")))?this.M.compact(g):null}}else g="";g&&f.push(g)}if(f.length>0)e=f}else e=["n4"];this.ja.push(d);this.la[d]=e}};webfont.A=function(a,b,c){this.a=a;this.c=b;this.k=c};webfont.A.B="google";webfont.A.prototype.Y=function(a,b){a.Ca.match(/iPad|iPod|iPhone/)!=null&&b(false);return b(a.Z)};webfont.A.prototype.load=function(a){var b=new webfont.H(this.k.api),c=this.k.families,d=this.c,e=this.a.getName()=="MSIE"&&this.k.blocking!=true;b.m=c;e?m(d,function(){i(d,"head",o(d,b.h()))}):i(d,"head",o(d,b.h()));c=new webfont.G(c);c.parse();a(c.ja,c.la)};
33
+ WebFont.K(webfont.A.B,function(a){var b=(new webfont.e(navigator.userAgent)).parse();return new webfont.A(b,new webfont.z(document),a)});webfont.w=function(a,b){this.c=a;this.k=b};webfont.w.B="custom";webfont.w.prototype.load=function(a){for(var b=this.k.urls||[],c=this.k.families||[],d=0,e=b.length;d<e;d++)i(this.c,"head",o(this.c,b[d]));a(c)};webfont.w.prototype.Y=function(a,b){return b(a.Z)};WebFont.K(webfont.w.B,function(a){return new webfont.w(new webfont.z(document),a)});webfont.n=function(a,b,c){this.U=a;this.c=b;this.k=c;this.m=[];this.ea={}};webfont.n.B="typekit";webfont.n.P="__webfonttypekitmodule__";webfont.n.prototype.Y=function(a,b){var c=this.k.id,d=this.k,e=this;if(c){this.U[webfont.n.P]||(this.U[webfont.n.P]={});this.U[webfont.n.P][c]=function(f){f(a,d,function(h,k,g){e.m=k;e.ea=g;b(h)})};i(this.c,"head",this.c.createElement("script",{src:(this.k.api||"http://use.typekit.com")+"/"+c+".js"}))}else b(true)};webfont.n.prototype.load=function(a){a(this.m,this.ea)};
34
+ WebFont.K(webfont.n.B,function(a){return new webfont.n(window,new webfont.z(document),a)});
35
+ })(this,document);
@@ -0,0 +1,1092 @@
1
+ /*
2
+ * Copyright 2010 Small Batch, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5
+ * use this file except in compliance with the License. You may obtain a copy of
6
+ * the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13
+ * License for the specific language governing permissions and limitations under
14
+ * the License.
15
+ */
16
+ webfont = {};
17
+
18
+ webfont.bind = function(context, func, opt_args) {
19
+ var args = arguments.length > 2 ?
20
+ Array.prototype.slice.call(arguments, 2) : [];
21
+
22
+ return function() {
23
+ args.push.apply(args, arguments);
24
+ return func.apply(context, args);
25
+ };
26
+ };
27
+
28
+ webfont.DomHelper = function(doc) {
29
+ this.document_ = doc;
30
+ };
31
+
32
+ webfont.DomHelper.prototype.createElement = function(elem, opt_attr,
33
+ opt_innerHtml) {
34
+ var domElement = this.document_.createElement(elem);
35
+
36
+ if (opt_attr) {
37
+ for (var attr in opt_attr) {
38
+ // protect against native prototype augmentations
39
+ if (opt_attr.hasOwnProperty(attr)) {
40
+ domElement.setAttribute(attr, opt_attr[attr]);
41
+ }
42
+ }
43
+ }
44
+ if (opt_innerHtml) {
45
+ domElement.appendChild(this.document_.createTextNode(opt_innerHtml));
46
+ }
47
+ return domElement;
48
+ };
49
+
50
+ webfont.DomHelper.prototype.insertInto = function(tagName, e) {
51
+ var t = this.document_.getElementsByTagName(tagName)[0];
52
+
53
+ if (!t) { // opera allows documents without a head
54
+ t = document.documentElement;
55
+ }
56
+
57
+ if (t && t.lastChild) {
58
+ // This is safer than appendChild in IE. appendChild causes random
59
+ // JS errors in IE. Sometimes errors in other JS exectution, sometimes
60
+ // complete 'This page cannot be displayed' errors. For our purposes,
61
+ // it's equivalent because we don't need to insert at any specific
62
+ // location.
63
+ t.insertBefore(e, t.lastChild);
64
+ return true;
65
+ }
66
+ return false;
67
+ };
68
+
69
+ webfont.DomHelper.prototype.whenBodyExists = function(callback) {
70
+ var check = function() {
71
+ if (document.body) {
72
+ callback();
73
+ } else {
74
+ setTimeout(check, 0);
75
+ }
76
+ }
77
+ check();
78
+ };
79
+
80
+ webfont.DomHelper.prototype.removeElement = function(node) {
81
+ if (node.parentNode) {
82
+ node.parentNode.removeChild(node);
83
+ return true;
84
+ }
85
+ return false;
86
+ };
87
+
88
+ webfont.DomHelper.prototype.createCssLink = function(src) {
89
+ return this.createElement('link', {
90
+ 'rel': 'stylesheet',
91
+ 'href': src
92
+ });
93
+ };
94
+
95
+ webfont.DomHelper.prototype.createScriptSrc = function(src) {
96
+ return this.createElement('script', {
97
+ 'src': src
98
+ });
99
+ };
100
+
101
+ webfont.DomHelper.prototype.appendClassName = function(e, name) {
102
+ var classes = e.className.split(/\s+/);
103
+ for (var i = 0, len = classes.length; i < len; i++) {
104
+ if (classes[i] == name) {
105
+ return;
106
+ }
107
+ }
108
+ classes.push(name);
109
+ e.className = classes.join(' ').replace(/^\s+/, '');
110
+ };
111
+
112
+ webfont.DomHelper.prototype.removeClassName = function(e, name) {
113
+ var classes = e.className.split(/\s+/);
114
+ var remainingClasses = [];
115
+ for (var i = 0, len = classes.length; i < len; i++) {
116
+ if (classes[i] != name) {
117
+ remainingClasses.push(classes[i]);
118
+ }
119
+ }
120
+ e.className = remainingClasses.join(' ').replace(/^\s+/, '')
121
+ .replace(/\s+$/, '');
122
+ };
123
+
124
+ webfont.UserAgent = function(name, version, engine, engineVersion, platform,
125
+ webFontSupport) {
126
+ this.name_ = name;
127
+ this.version_ = version;
128
+ this.engine_ = engine;
129
+ this.engineVersion_ = engineVersion;
130
+ this.platform_ = platform;
131
+ this.webFontSupport_ = webFontSupport;
132
+ };
133
+
134
+ webfont.UserAgent.prototype.getName = function() {
135
+ return this.name_;
136
+ };
137
+
138
+ webfont.UserAgent.prototype.getVersion = function() {
139
+ return this.version_;
140
+ };
141
+
142
+ webfont.UserAgent.prototype.getEngine = function() {
143
+ return this.engine_;
144
+ };
145
+
146
+ webfont.UserAgent.prototype.getEngineVersion = function() {
147
+ return this.engineVersion_;
148
+ };
149
+
150
+ webfont.UserAgent.prototype.getPlatform = function() {
151
+ return this.platform_;
152
+ };
153
+
154
+ webfont.UserAgent.prototype.isSupportingWebFont = function() {
155
+ return this.webFontSupport_;
156
+ };
157
+
158
+ webfont.UserAgentParser = function(userAgent) {
159
+ this.userAgent_ = userAgent;
160
+ };
161
+
162
+ webfont.UserAgentParser.UNKNOWN = "Unknown";
163
+
164
+ webfont.UserAgentParser.UNKNOWN_USER_AGENT = new webfont.UserAgent(webfont.UserAgentParser.UNKNOWN,
165
+ webfont.UserAgentParser.UNKNOWN, webfont.UserAgentParser.UNKNOWN, false);
166
+
167
+ webfont.UserAgentParser.prototype.parse = function() {
168
+ if (this.isIe_()) {
169
+ return this.parseIeUserAgentString_();
170
+ } else if (this.isOpera_()) {
171
+ return this.parseOperaUserAgentString_();
172
+ } else if (this.isWebKit_()) {
173
+ return this.parseWebKitUserAgentString_();
174
+ } else if (this.isGecko_()) {
175
+ return this.parseGeckoUserAgentString_();
176
+ } else {
177
+ return webfont.UserAgentParser.UNKNOWN_USER_AGENT;
178
+ }
179
+ };
180
+
181
+ webfont.UserAgentParser.prototype.getPlatform_ = function() {
182
+ var mobileOs = this.getFirstMatchingGroup_(this.userAgent_,
183
+ /(iPod|iPad|iPhone|Android)/);
184
+
185
+ if (mobileOs != "") {
186
+ return mobileOs;
187
+ }
188
+ var os = this.getFirstMatchingGroup_(this.userAgent_,
189
+ /(Linux|Mac_PowerPC|Macintosh|Windows)/);
190
+
191
+ if (os != "") {
192
+ if (os == "Mac_PowerPC") {
193
+ os = "Macintosh";
194
+ }
195
+ return os;
196
+ }
197
+ return webfont.UserAgentParser.UNKNOWN;
198
+ };
199
+
200
+ webfont.UserAgentParser.prototype.isIe_ = function() {
201
+ return this.userAgent_.indexOf("MSIE") != -1;
202
+ };
203
+
204
+ webfont.UserAgentParser.prototype.parseIeUserAgentString_ = function() {
205
+ var browser = this.getFirstMatchingGroup_(this.userAgent_, /(MSIE [\d\w\.]+)/);
206
+ var engineName = webfont.UserAgentParser.UNKNOWN;
207
+ var engineVersion = webfont.UserAgentParser.UNKNOWN;
208
+
209
+ if (browser != "") {
210
+ var pair = browser.split(' ');
211
+ var name = pair[0];
212
+ var version = pair[1];
213
+
214
+ // For IE we give MSIE as the engine name and the version of IE
215
+ // instead of the specific Trident engine name and version
216
+ return new webfont.UserAgent(name, version, name, version,
217
+ this.getPlatform_(), this.getMajorVersion_(version) >= 6);
218
+ }
219
+ return new webfont.UserAgent("MSIE", webfont.UserAgentParser.UNKNOWN,
220
+ "MSIE", webfont.UserAgentParser.UNKNOWN, this.getPlatform_(), false);
221
+ };
222
+
223
+ webfont.UserAgentParser.prototype.isOpera_ = function() {
224
+ return this.userAgent_.indexOf("Opera") != -1;
225
+ };
226
+
227
+ webfont.UserAgentParser.prototype.parseOperaUserAgentString_ = function() {
228
+ var engineName = webfont.UserAgentParser.UNKNOWN;
229
+ var engineVersion = webfont.UserAgentParser.UNKNOWN;
230
+ var enginePair = this.getFirstMatchingGroup_(this.userAgent_,
231
+ /(Presto\/[\d\w\.]+)/);
232
+
233
+ if (enginePair != "") {
234
+ var splittedEnginePair = enginePair.split('/');
235
+
236
+ engineName = splittedEnginePair[0];
237
+ engineVersion = splittedEnginePair[1];
238
+ } else {
239
+ if (this.userAgent_.indexOf("Gecko") != -1) {
240
+ engineName = "Gecko";
241
+ }
242
+ var geckoVersion = this.getFirstMatchingGroup_(this.userAgent_, /rv:([^\)]+)/);
243
+
244
+ if (geckoVersion != "") {
245
+ engineVersion = geckoVersion;
246
+ }
247
+ }
248
+ if (this.userAgent_.indexOf("Version/") != -1) {
249
+ var version = this.getFirstMatchingGroup_(this.userAgent_, /Version\/([\d\.]+)/);
250
+
251
+ if (version != "") {
252
+ return new webfont.UserAgent("Opera", version, engineName, engineVersion,
253
+ this.getPlatform_(), this.getMajorVersion_(version) >= 10);
254
+ }
255
+ }
256
+ var version = this.getFirstMatchingGroup_(this.userAgent_, /Opera[\/ ]([\d\.]+)/);
257
+
258
+ if (version != "") {
259
+ return new webfont.UserAgent("Opera", version, engineName, engineVersion,
260
+ this.getPlatform_(), this.getMajorVersion_(version) >= 10);
261
+ }
262
+ return new webfont.UserAgent("Opera", webfont.UserAgentParser.UNKNOWN,
263
+ engineName, engineVersion, this.getPlatform_(), false);
264
+ };
265
+
266
+ webfont.UserAgentParser.prototype.isWebKit_ = function() {
267
+ return this.userAgent_.indexOf("AppleWebKit") != -1;
268
+ };
269
+
270
+ webfont.UserAgentParser.prototype.parseWebKitUserAgentString_ = function() {
271
+ var platform = this.getPlatform_();
272
+ var webKitVersion = this.getFirstMatchingGroup_(this.userAgent_,
273
+ /AppleWebKit\/([\d\.\+]+)/);
274
+
275
+ if (webKitVersion == "") {
276
+ webKitVersion = webfont.UserAgentParser.UNKNOWN;
277
+ }
278
+ var name = webfont.UserAgentParser.UNKNOWN;
279
+
280
+ if (this.userAgent_.indexOf("Chrome") != -1) {
281
+ name = "Chrome";
282
+ } else if (this.userAgent_.indexOf("Safari") != -1) {
283
+ name = "Safari";
284
+ }
285
+ var version = webfont.UserAgentParser.UNKNOWN;
286
+
287
+ if (this.userAgent_.indexOf("Version/") != -1) {
288
+ version = this.getFirstMatchingGroup_(this.userAgent_,
289
+ /Version\/([\d\.\w]+)/);
290
+ } else if (name == "Chrome") {
291
+ version = this.getFirstMatchingGroup_(this.userAgent_,
292
+ /Chrome\/([\d\.]+)/);
293
+ }
294
+ var minor = this.getFirstMatchingGroup_(webKitVersion, /\d+\.(\d+)/);
295
+
296
+ return new webfont.UserAgent(name, version, "AppleWebKit", webKitVersion,
297
+ platform, this.getMajorVersion_(webKitVersion) >= 526 ||
298
+ this.getMajorVersion_(webKitVersion) >= 525 && parseInt(minor) >= 13);
299
+ };
300
+
301
+ webfont.UserAgentParser.prototype.isGecko_ = function() {
302
+ return this.userAgent_.indexOf("Gecko") != -1;
303
+ };
304
+
305
+ webfont.UserAgentParser.prototype.parseGeckoUserAgentString_ = function() {
306
+ var name = webfont.UserAgentParser.UNKNOWN;
307
+ var version = webfont.UserAgentParser.UNKNOWN;
308
+ var supportWebFont = false;
309
+
310
+ if (this.userAgent_.indexOf("Firefox") != -1) {
311
+ name = "Firefox";
312
+ var versionNum = this.getFirstMatchingGroup_(this.userAgent_,
313
+ /Firefox\/([\d\w\.]+)/);
314
+
315
+ if (versionNum != "") {
316
+ var minor = this.getFirstMatchingGroup_(versionNum, /\d+\.(\d+)/);
317
+
318
+ version = versionNum;
319
+ supportWebFont = versionNum != "" && this.getMajorVersion_(versionNum) >= 3 &&
320
+ parseInt(minor) >= 5;
321
+ }
322
+ } else if (this.userAgent_.indexOf("Mozilla") != -1) {
323
+ name = "Mozilla";
324
+ }
325
+ var geckoVersion = this.getFirstMatchingGroup_(this.userAgent_, /rv:([^\)]+)/);
326
+
327
+ if (geckoVersion == "") {
328
+ geckoVersion = webfont.UserAgentParser.UNKNOWN;
329
+ } else {
330
+ if (!supportWebFont) {
331
+ var majorVersion = this.getMajorVersion_(geckoVersion);
332
+ var intMinorVersion = parseInt(this.getFirstMatchingGroup_(geckoVersion, /\d+\.(\d+)/));
333
+ var subVersion = parseInt(this.getFirstMatchingGroup_(geckoVersion, /\d+\.\d+\.(\d+)/));
334
+
335
+ supportWebFont = majorVersion > 1 ||
336
+ majorVersion == 1 && intMinorVersion > 9 ||
337
+ majorVersion == 1 && intMinorVersion == 9 && subVersion >= 2 ||
338
+ geckoVersion.match(/1\.9\.1b[123]/) != null ||
339
+ geckoVersion.match(/1\.9\.1\.[\d\.]+/) != null;
340
+ }
341
+ }
342
+ return new webfont.UserAgent(name, version, "Gecko", geckoVersion,
343
+ this.getPlatform_(), supportWebFont);
344
+ };
345
+
346
+ webfont.UserAgentParser.prototype.getMajorVersion_ = function(version) {
347
+ var majorVersion = this.getFirstMatchingGroup_(version, /(\d+)/);
348
+
349
+ if (majorVersion != "") {
350
+ return parseInt(majorVersion);
351
+ }
352
+ return -1;
353
+ };
354
+
355
+ webfont.UserAgentParser.prototype.getFirstMatchingGroup_ = function(str,
356
+ regexp) {
357
+ var groups = str.match(regexp);
358
+
359
+ if (groups && groups[1]) {
360
+ return groups[1];
361
+ }
362
+ return "";
363
+ };
364
+
365
+ webfont.EventDispatcher = function(domHelper, htmlElement, callbacks,
366
+ opt_namespace) {
367
+ this.domHelper_ = domHelper;
368
+ this.htmlElement_ = htmlElement;
369
+ this.callbacks_ = callbacks;
370
+ this.namespace_ = opt_namespace || webfont.EventDispatcher.DEFAULT_NAMESPACE;
371
+ this.cssClassName_ = new webfont.CssClassName('-');
372
+ };
373
+
374
+ webfont.EventDispatcher.DEFAULT_NAMESPACE = 'wf';
375
+ webfont.EventDispatcher.LOADING = 'loading';
376
+ webfont.EventDispatcher.ACTIVE = 'active';
377
+ webfont.EventDispatcher.INACTIVE = 'inactive';
378
+ webfont.EventDispatcher.FONT = 'font';
379
+
380
+ webfont.EventDispatcher.prototype.dispatchLoading = function() {
381
+ this.domHelper_.appendClassName(this.htmlElement_,
382
+ this.cssClassName_.build(
383
+ this.namespace_, webfont.EventDispatcher.LOADING));
384
+ this.dispatch_(webfont.EventDispatcher.LOADING);
385
+ };
386
+
387
+ webfont.EventDispatcher.prototype.dispatchFontLoading = function(fontFamily, fontDescription) {
388
+ this.domHelper_.appendClassName(this.htmlElement_,
389
+ this.cssClassName_.build(
390
+ this.namespace_, fontFamily, fontDescription, webfont.EventDispatcher.LOADING));
391
+ this.dispatch_(
392
+ webfont.EventDispatcher.FONT + webfont.EventDispatcher.LOADING, fontFamily, fontDescription);
393
+ };
394
+
395
+ webfont.EventDispatcher.prototype.dispatchFontActive = function(fontFamily, fontDescription) {
396
+ this.domHelper_.removeClassName(this.htmlElement_,
397
+ this.cssClassName_.build(
398
+ this.namespace_, fontFamily, fontDescription, webfont.EventDispatcher.LOADING));
399
+ this.domHelper_.appendClassName(this.htmlElement_,
400
+ this.cssClassName_.build(
401
+ this.namespace_, fontFamily, fontDescription, webfont.EventDispatcher.ACTIVE));
402
+ this.dispatch_(
403
+ webfont.EventDispatcher.FONT + webfont.EventDispatcher.ACTIVE, fontFamily, fontDescription);
404
+ };
405
+
406
+ webfont.EventDispatcher.prototype.dispatchFontInactive = function(fontFamily, fontDescription) {
407
+ this.domHelper_.removeClassName(this.htmlElement_,
408
+ this.cssClassName_.build(
409
+ this.namespace_, fontFamily, fontDescription, webfont.EventDispatcher.LOADING));
410
+ this.domHelper_.appendClassName(this.htmlElement_,
411
+ this.cssClassName_.build(
412
+ this.namespace_, fontFamily, fontDescription, webfont.EventDispatcher.INACTIVE));
413
+ this.dispatch_(
414
+ webfont.EventDispatcher.FONT + webfont.EventDispatcher.INACTIVE, fontFamily, fontDescription);
415
+ };
416
+
417
+ webfont.EventDispatcher.prototype.dispatchInactive = function() {
418
+ this.domHelper_.appendClassName(this.htmlElement_,
419
+ this.cssClassName_.build(
420
+ this.namespace_, webfont.EventDispatcher.INACTIVE));
421
+ this.dispatch_(webfont.EventDispatcher.INACTIVE);
422
+ };
423
+
424
+ webfont.EventDispatcher.prototype.dispatchActive = function() {
425
+ // what about inactive? maybe if all fonts failed to load?
426
+ this.domHelper_.removeClassName(this.htmlElement_,
427
+ this.cssClassName_.build(
428
+ this.namespace_, webfont.EventDispatcher.LOADING));
429
+ this.domHelper_.appendClassName(this.htmlElement_,
430
+ this.cssClassName_.build(
431
+ this.namespace_, webfont.EventDispatcher.ACTIVE));
432
+ this.dispatch_(webfont.EventDispatcher.ACTIVE);
433
+ };
434
+
435
+ webfont.EventDispatcher.prototype.dispatch_ = function(event, opt_arg1, opt_arg2) {
436
+ if (this.callbacks_[event]) {
437
+ this.callbacks_[event](opt_arg1, opt_arg2);
438
+ }
439
+ };
440
+
441
+ webfont.FontModuleLoader = function() {
442
+ this.modules_ = {};
443
+ };
444
+
445
+ webfont.FontModuleLoader.prototype.addModuleFactory = function(name, factory) {
446
+ this.modules_[name] = factory;
447
+ };
448
+
449
+ webfont.FontModuleLoader.prototype.getModules = function(configuration) {
450
+ var modules = [];
451
+
452
+ for (var key in configuration) {
453
+ if (configuration.hasOwnProperty(key)) {
454
+ var moduleFactory = this.modules_[key];
455
+
456
+ if (moduleFactory) {
457
+ modules.push(moduleFactory(configuration[key]));
458
+ }
459
+ }
460
+ }
461
+ return modules;
462
+ };
463
+
464
+ webfont.FontWatcher = function(domHelper, eventDispatcher, fontSizer,
465
+ asyncCall, getTime) {
466
+ this.domHelper_ = domHelper;
467
+ this.eventDispatcher_ = eventDispatcher;
468
+ this.fontSizer_ = fontSizer;
469
+ this.asyncCall_ = asyncCall;
470
+ this.getTime_ = getTime;
471
+ this.currentlyWatched_ = 0;
472
+ this.last_ = false;
473
+ this.success_ = false;
474
+ this.nameHelper_ = new webfont.CssFontFamilyName();
475
+ this.fvd_ = new webfont.FontVariationDescription();
476
+ };
477
+
478
+ webfont.FontWatcher.DEFAULT_FONT = 'DEFAULT_FONT';
479
+ webfont.FontWatcher.DEFAULT_VARIATION = 'n4';
480
+
481
+ webfont.FontWatcher.prototype.watch = function(fontFamilies, fontDescriptions, last) {
482
+ var length = fontFamilies.length;
483
+
484
+ for (var i = 0; i < length; i++) {
485
+ var fontFamily = fontFamilies[i];
486
+ if (!fontDescriptions[fontFamily]) {
487
+ fontDescriptions[fontFamily] = [webfont.FontWatcher.DEFAULT_VARIATION];
488
+ }
489
+ this.currentlyWatched_ += fontDescriptions[fontFamily].length;
490
+ }
491
+
492
+ if (last) {
493
+ this.last_ = last;
494
+ }
495
+
496
+ for (var i = 0; i < length; i++) {
497
+ var fontFamily = fontFamilies[i];
498
+ var descriptions = fontDescriptions[fontFamily];
499
+
500
+ for (var j = 0, len = descriptions.length; j < len; j++) {
501
+ var fontDescription = descriptions[j];
502
+ var originalSize = this.getDefaultFontSize_(fontDescription);
503
+
504
+ this.watch_(fontFamily, fontDescription, originalSize);
505
+ }
506
+ }
507
+ };
508
+
509
+ webfont.FontWatcher.prototype.watch_ = function(fontFamily, fontDescription, originalSize) {
510
+ this.eventDispatcher_.dispatchFontLoading(fontFamily, fontDescription);
511
+ var requestedFont = this.createHiddenElementWithFont_(fontFamily, fontDescription);
512
+ var size = this.fontSizer_.getWidth(requestedFont);
513
+
514
+ if (originalSize != size) {
515
+ this.domHelper_.removeElement(requestedFont);
516
+ this.eventDispatcher_.dispatchFontActive(fontFamily, fontDescription);
517
+ this.success_ = true;
518
+ this.decreaseCurrentlyWatched_();
519
+ } else {
520
+ this.asyncCheck_(this.getTime_(), originalSize, requestedFont,
521
+ fontFamily, fontDescription);
522
+ }
523
+ };
524
+
525
+ webfont.FontWatcher.prototype.decreaseCurrentlyWatched_ = function() {
526
+ if (--this.currentlyWatched_ == 0 && this.last_) {
527
+ if (this.success_) {
528
+ this.eventDispatcher_.dispatchActive();
529
+ } else {
530
+ this.eventDispatcher_.dispatchInactive();
531
+ }
532
+ }
533
+ };
534
+
535
+ webfont.FontWatcher.prototype.check_ = function(started, originalSize,
536
+ requestedFont, fontFamily, fontDescription) {
537
+ var size = this.fontSizer_.getWidth(requestedFont);
538
+
539
+ if (originalSize != size) {
540
+ this.domHelper_.removeElement(requestedFont);
541
+ this.eventDispatcher_.dispatchFontActive(fontFamily, fontDescription);
542
+ this.success_ = true;
543
+ this.decreaseCurrentlyWatched_();
544
+ } else if ((this.getTime_() - started) < 5000) {
545
+ this.asyncCheck_(started, originalSize, requestedFont, fontFamily, fontDescription);
546
+ } else {
547
+ this.domHelper_.removeElement(requestedFont);
548
+ this.eventDispatcher_.dispatchFontInactive(fontFamily, fontDescription);
549
+ this.decreaseCurrentlyWatched_();
550
+ }
551
+ };
552
+
553
+ webfont.FontWatcher.prototype.asyncCheck_ = function(started, originalSize,
554
+ requestedFont, fontFamily, fontDescription) {
555
+ this.asyncCall_(function(context, func) {
556
+ return function() {
557
+ func.call(context, started, originalSize, requestedFont, fontFamily, fontDescription);
558
+ }
559
+ }(this, this.check_), 50);
560
+ };
561
+
562
+ webfont.FontWatcher.prototype.getDefaultFontSize_ = function(fontDescription) {
563
+ var defaultFont = this.createHiddenElementWithFont_(
564
+ webfont.FontWatcher.DEFAULT_FONT, fontDescription);
565
+ var size = this.fontSizer_.getWidth(defaultFont);
566
+
567
+ this.domHelper_.removeElement(defaultFont);
568
+ return size;
569
+ };
570
+
571
+ webfont.FontWatcher.prototype.createHiddenElementWithFont_ = function(
572
+ fontFamily, fontDescription) {
573
+ var quotedName = this.nameHelper_.quote(fontFamily);
574
+ var variationCss = this.fvd_.expand(fontDescription);
575
+ var styleString = "position:absolute;top:-999px;font-size:300px;font-family:" +
576
+ quotedName + "," + webfont.FontWatcher.DEFAULT_FONT + ";" +
577
+ variationCss;
578
+
579
+ var span = this.domHelper_.createElement('span', {
580
+ // IE must have a fallback font option, else sometimes the loaded font
581
+ // won't be detected - typically in the fully cached case.
582
+ 'style': styleString }, 'Mm');
583
+
584
+ this.domHelper_.insertInto('html', span);
585
+ return span;
586
+ };
587
+
588
+ webfont.WebFont = function(domHelper, fontModuleLoader, htmlElement, asyncCall,
589
+ userAgent) {
590
+ this.domHelper_ = domHelper;
591
+ this.fontModuleLoader_ = fontModuleLoader;
592
+ this.htmlElement_ = htmlElement;
593
+ this.asyncCall_ = asyncCall;
594
+ this.userAgent_ = userAgent;
595
+ this.moduleLoading_ = 0;
596
+ this.moduleFailedLoading_ = 0;
597
+ };
598
+
599
+ webfont.WebFont.prototype.addModule = function(name, factory) {
600
+ this.fontModuleLoader_.addModuleFactory(name, factory);
601
+ };
602
+
603
+ webfont.WebFont.prototype.load = function(configuration) {
604
+ var eventDispatcher = new webfont.EventDispatcher(
605
+ this.domHelper_, this.htmlElement_, configuration);
606
+
607
+ if (this.userAgent_.isSupportingWebFont()) {
608
+ this.load_(eventDispatcher, configuration);
609
+ } else {
610
+ eventDispatcher.dispatchInactive();
611
+ }
612
+ };
613
+
614
+ webfont.WebFont.prototype.isModuleSupportingUserAgent_ = function(module, eventDispatcher,
615
+ fontWatcher, support) {
616
+ if (!support) {
617
+ var allModulesLoaded = --this.moduleLoading_ == 0;
618
+
619
+ this.moduleFailedLoading_--;
620
+ if (allModulesLoaded) {
621
+ if (this.moduleFailedLoading_ == 0) {
622
+ eventDispatcher.dispatchInactive();
623
+ } else {
624
+ eventDispatcher.dispatchLoading();
625
+ }
626
+ }
627
+ fontWatcher.watch([], {}, allModulesLoaded);
628
+ return;
629
+ }
630
+ module.load(webfont.bind(this, this.onModuleReady_, eventDispatcher,
631
+ fontWatcher));
632
+ };
633
+
634
+ webfont.WebFont.prototype.onModuleReady_ = function(eventDispatcher, fontWatcher,
635
+ fontFamilies, opt_fontDescriptions) {
636
+ var allModulesLoaded = --this.moduleLoading_ == 0;
637
+
638
+ if (allModulesLoaded) {
639
+ eventDispatcher.dispatchLoading();
640
+ }
641
+ this.asyncCall_(webfont.bind(this, function(_fontWatcher, _fontFamilies,
642
+ _fontDescriptions, _allModulesLoaded) {
643
+ _fontWatcher.watch(_fontFamilies, _fontDescriptions || {}, _allModulesLoaded);
644
+ }, fontWatcher, fontFamilies, opt_fontDescriptions, allModulesLoaded));
645
+ };
646
+
647
+ webfont.WebFont.prototype.load_ = function(eventDispatcher, configuration) {
648
+ var modules = this.fontModuleLoader_.getModules(configuration),
649
+ self = this;
650
+
651
+ this.moduleFailedLoading_ = this.moduleLoading_ = modules.length;
652
+
653
+ var fontWatcher = new webfont.FontWatcher(this.domHelper_,
654
+ eventDispatcher, {
655
+ getWidth: function(elem) {
656
+ return elem.offsetWidth;
657
+ }}, self.asyncCall_, function() {
658
+ return +new Date();
659
+ });
660
+
661
+ for (var i = 0, len = modules.length; i < len; i++) {
662
+ var module = modules[i];
663
+
664
+ module.supportUserAgent(this.userAgent_,
665
+ webfont.bind(this, this.isModuleSupportingUserAgent_, module,
666
+ eventDispatcher, fontWatcher));
667
+ }
668
+ };
669
+
670
+ webfont.CssClassName = function(opt_joinChar) {
671
+ this.joinChar_ = opt_joinChar || webfont.CssClassName.DEFAULT_JOIN_CHAR;
672
+ };
673
+
674
+ webfont.CssClassName.DEFAULT_JOIN_CHAR = '-';
675
+
676
+ webfont.CssClassName.prototype.sanitize = function(name) {
677
+ return name.replace(/[\W_]+/g, '').toLowerCase();
678
+ };
679
+
680
+ webfont.CssClassName.prototype.build = function(__args__) {
681
+ var parts = []
682
+ for (var i = 0; i < arguments.length; i++) {
683
+ parts.push(this.sanitize(arguments[i]));
684
+ }
685
+ return parts.join(this.joinChar_);
686
+ };
687
+
688
+
689
+ webfont.CssFontFamilyName = function() {
690
+ this.quote_ = '"';
691
+ };
692
+
693
+ webfont.CssFontFamilyName.prototype.quote = function(name) {
694
+ var quoted = [];
695
+ var split = name.split(/,\s*/);
696
+ for (var i = 0; i < split.length; i++) {
697
+ var part = split[i].replace(/['"]/g, '');
698
+ if (part.indexOf(' ') == -1) {
699
+ quoted.push(part);
700
+ } else {
701
+ quoted.push(this.quote_ + part + this.quote_);
702
+ }
703
+ }
704
+ return quoted.join(',');
705
+ };
706
+
707
+ webfont.FontVariationDescription = function() {
708
+ this.properties_ = webfont.FontVariationDescription.PROPERTIES;
709
+ this.values_ = webfont.FontVariationDescription.VALUES;
710
+ };
711
+
712
+ webfont.FontVariationDescription.PROPERTIES = [
713
+ 'font-style',
714
+ 'font-weight'
715
+ ];
716
+
717
+ webfont.FontVariationDescription.VALUES = {
718
+ 'font-style': [
719
+ ['n', 'normal'],
720
+ ['i', 'italic'],
721
+ ['o', 'oblique']
722
+ ],
723
+ 'font-weight': [
724
+ ['1', '100'],
725
+ ['2', '200'],
726
+ ['3', '300'],
727
+ ['4', '400'],
728
+ ['5', '500'],
729
+ ['6', '600'],
730
+ ['7', '700'],
731
+ ['8', '800'],
732
+ ['9', '900'],
733
+ ['4', 'normal'],
734
+ ['7', 'bold']
735
+ ]
736
+ };
737
+
738
+ webfont.FontVariationDescription.Item = function(index, property, values) {
739
+ this.index_ = index;
740
+ this.property_ = property;
741
+ this.values_ = values;
742
+ }
743
+
744
+ webfont.FontVariationDescription.Item.prototype.compact = function(output, value) {
745
+ for (var i = 0; i < this.values_.length; i++) {
746
+ if (value == this.values_[i][1]) {
747
+ output[this.index_] = this.values_[i][0];
748
+ return;
749
+ }
750
+ }
751
+ }
752
+
753
+ webfont.FontVariationDescription.Item.prototype.expand = function(output, value) {
754
+ for (var i = 0; i < this.values_.length; i++) {
755
+ if (value == this.values_[i][0]) {
756
+ output[this.index_] = this.property_ + ':' + this.values_[i][1];
757
+ return;
758
+ }
759
+ }
760
+ }
761
+
762
+ webfont.FontVariationDescription.prototype.compact = function(input) {
763
+ var result = ['n', '4'];
764
+ var descriptors = input.split(';');
765
+
766
+ for (var i = 0, len = descriptors.length; i < len; i++) {
767
+ var pair = descriptors[i].replace(/\s+/g, '').split(':');
768
+ if (pair.length == 2) {
769
+ var property = pair[0];
770
+ var value = pair[1];
771
+ var item = this.getItem_(property);
772
+ if (item) {
773
+ item.compact(result, value);
774
+ }
775
+ }
776
+ }
777
+
778
+ return result.join('');
779
+ };
780
+
781
+ webfont.FontVariationDescription.prototype.expand = function(fvd) {
782
+ if (fvd.length != 2) {
783
+ return null;
784
+ }
785
+
786
+ var result = [null, null];
787
+
788
+ for (var i = 0, len = this.properties_.length; i < len; i++) {
789
+ var property = this.properties_[i];
790
+ var key = fvd.substr(i, 1);
791
+ var values = this.values_[property];
792
+ var item = new webfont.FontVariationDescription.Item(i, property, values);
793
+ item.expand(result, key);
794
+ }
795
+
796
+ if (result[0] && result[1]) {
797
+ return result.join(';') + ';';
798
+ } else {
799
+ return null;
800
+ }
801
+ }
802
+
803
+ webfont.FontVariationDescription.prototype.getItem_ = function(property) {
804
+ for (var i = 0; i < this.properties_.length; i++) {
805
+ if (property == this.properties_[i]) {
806
+ var values = this.values_[property];
807
+ return new webfont.FontVariationDescription.Item(i, property, values);
808
+ }
809
+ }
810
+
811
+ return null;
812
+ };
813
+
814
+ // Name of the global object.
815
+ var globalName = 'WebFont';
816
+
817
+ // Provide an instance of WebFont in the global namespace.
818
+ window[globalName] = (function() {
819
+ var domHelper = new webfont.DomHelper(document);
820
+ var userAgentParser = new webfont.UserAgentParser(navigator.userAgent);
821
+ var userAgent = userAgentParser.parse();
822
+ var asyncCall = function(func, timeout) { setTimeout(func, timeout); };
823
+
824
+ return new webfont.WebFont(domHelper, new webfont.FontModuleLoader(),
825
+ document.documentElement, asyncCall, userAgent);
826
+ })();
827
+
828
+ // Export the public API.
829
+ window[globalName]['load'] = window[globalName].load;
830
+ window[globalName]['addModule'] = window[globalName].addModule;
831
+
832
+ webfont.FontApiUrlBuilder = function(apiUrl) {
833
+ this.apiUrl_ = apiUrl || webfont.FontApiUrlBuilder.DEFAULT_API_URL;
834
+ this.fontFamilies_ = null;
835
+ };
836
+
837
+ webfont.FontApiUrlBuilder.DEFAULT_API_URL = '//fonts.googleapis.com/css';
838
+
839
+ webfont.FontApiUrlBuilder.prototype.setFontFamilies = function(fontFamilies) {
840
+ // maybe clone?
841
+ this.fontFamilies_ = fontFamilies;
842
+ };
843
+
844
+ webfont.FontApiUrlBuilder.prototype.webSafe = function(string) {
845
+ return string.replace(/ /g, '+');
846
+ };
847
+
848
+ webfont.FontApiUrlBuilder.prototype.build = function() {
849
+ if (!this.fontFamilies_) {
850
+ throw new Error('No fonts to load !');
851
+ }
852
+ var length = this.fontFamilies_.length;
853
+ var sb = [];
854
+
855
+ for (var i = 0; i < length; i++) {
856
+ sb.push(this.webSafe(this.fontFamilies_[i]));
857
+ }
858
+ var url = this.apiUrl_ + '?family=' + sb.join('%7C'); // '|' escaped.
859
+
860
+ return url;
861
+ };
862
+
863
+ webfont.FontApiParser = function(fontFamilies) {
864
+ this.fontFamilies_ = fontFamilies;
865
+ this.parsedFontFamilies_ = [];
866
+ this.variations_ = {};
867
+ this.fvd_ = new webfont.FontVariationDescription();
868
+ };
869
+
870
+ webfont.FontApiParser.VARIATIONS = {
871
+ 'ultralight': 'n2',
872
+ 'light': 'n3',
873
+ 'regular': 'i4',
874
+ 'bold': 'i7',
875
+ 'italic': 'i4',
876
+ 'bolditalic': 'i7',
877
+ 'ul': 'n2',
878
+ 'l': 'n3',
879
+ 'r': 'n4',
880
+ 'b': 'n7',
881
+ 'i': 'i4',
882
+ 'bi': 'i7'
883
+ };
884
+
885
+ webfont.FontApiParser.prototype.parse = function() {
886
+ var length = this.fontFamilies_.length;
887
+
888
+ for (var i = 0; i < length; i++) {
889
+ var pair = this.fontFamilies_[i].split(":");
890
+ var fontFamily = pair[0];
891
+ var variations = null;
892
+
893
+ if (pair.length == 2) {
894
+ var fvds = this.parseVariations_(pair[1]);
895
+
896
+ if (fvds.length > 0) {
897
+ variations = fvds;
898
+ }
899
+ } else {
900
+ variations = ['n4'];
901
+ }
902
+ this.parsedFontFamilies_.push(fontFamily);
903
+ this.variations_[fontFamily] = variations;
904
+ }
905
+ };
906
+
907
+ webfont.FontApiParser.prototype.generateFontVariationDescription_ = function(variation) {
908
+ if (!variation.match(/^[\w ]+$/)) {
909
+ return '';
910
+ }
911
+
912
+ var fvd = webfont.FontApiParser.VARIATIONS[variation];
913
+
914
+ if (fvd) {
915
+ return fvd;
916
+ } else {
917
+ var groups = variation.match(/^(\d*)(\w*)$/);
918
+ var numericMatch = groups[1];
919
+ var styleMatch = groups[2];
920
+ var s = styleMatch ? styleMatch : 'n';
921
+ var w = numericMatch ? numericMatch.substr(0, 1) : '4';
922
+ var css = this.fvd_.expand([s, w].join(''));
923
+ if (css) {
924
+ return this.fvd_.compact(css);
925
+ } else {
926
+ return null;
927
+ }
928
+ }
929
+ };
930
+
931
+ webfont.FontApiParser.prototype.parseVariations_ = function(variations) {
932
+ var finalVariations = [];
933
+ var providedVariations = variations.split(",");
934
+ var length = providedVariations.length;
935
+
936
+ for (var i = 0; i < length; i++) {
937
+ var variation = providedVariations[i];
938
+ var fvd = this.generateFontVariationDescription_(variation);
939
+
940
+ if (fvd) {
941
+ finalVariations.push(fvd);
942
+ }
943
+ }
944
+ return finalVariations;
945
+ };
946
+
947
+ webfont.FontApiParser.prototype.getFontFamilies = function() {
948
+ return this.parsedFontFamilies_;
949
+ };
950
+
951
+ webfont.FontApiParser.prototype.getVariations = function() {
952
+ return this.variations_;
953
+ };
954
+
955
+ webfont.GoogleFontApi = function(userAgent, domHelper, configuration) {
956
+ this.userAgent_ = userAgent;
957
+ this.domHelper_ = domHelper;
958
+ this.configuration_ = configuration;
959
+ };
960
+
961
+ webfont.GoogleFontApi.NAME = 'google';
962
+
963
+ webfont.GoogleFontApi.prototype.supportUserAgent = function(userAgent, support) {
964
+ if (userAgent.getPlatform().match(/iPad|iPod|iPhone/) != null) {
965
+ support(false);
966
+ }
967
+ return support(userAgent.isSupportingWebFont());
968
+ };
969
+
970
+ webfont.GoogleFontApi.prototype.load = function(onReady) {
971
+ var fontApiUrlBuilder = new webfont.FontApiUrlBuilder(
972
+ this.configuration_['api']);
973
+ var fontFamilies = this.configuration_['families'];
974
+ var domHelper = this.domHelper_;
975
+ var nonBlockingIe = this.userAgent_.getName() == 'MSIE' &&
976
+ this.configuration_['blocking'] != true;
977
+
978
+ fontApiUrlBuilder.setFontFamilies(fontFamilies);
979
+
980
+ if (nonBlockingIe) {
981
+ domHelper.whenBodyExists(function() {
982
+ domHelper.insertInto('head', domHelper.createCssLink(
983
+ fontApiUrlBuilder.build()));
984
+ });
985
+ } else {
986
+ domHelper.insertInto('head', domHelper.createCssLink(
987
+ fontApiUrlBuilder.build()));
988
+ }
989
+ var fontApiParser = new webfont.FontApiParser(fontFamilies);
990
+
991
+ fontApiParser.parse();
992
+ onReady(fontApiParser.getFontFamilies(), fontApiParser.getVariations());
993
+ };
994
+
995
+ WebFont.addModule(webfont.GoogleFontApi.NAME, function(configuration) {
996
+ var userAgentParser = new webfont.UserAgentParser(navigator.userAgent);
997
+ var userAgent = userAgentParser.parse();
998
+ return new webfont.GoogleFontApi(userAgent,
999
+ new webfont.DomHelper(document), configuration);
1000
+ });
1001
+
1002
+ /**
1003
+ *
1004
+ * WebFont.load({
1005
+ * custom: {
1006
+ * families: ['Font1', 'Font2'],
1007
+ * urls: [ 'http://moo', 'http://meuh' ] }
1008
+ * });
1009
+ */
1010
+ webfont.CustomCss = function(domHelper, configuration) {
1011
+ this.domHelper_ = domHelper;
1012
+ this.configuration_ = configuration;
1013
+ };
1014
+
1015
+ webfont.CustomCss.NAME = 'custom';
1016
+
1017
+ webfont.CustomCss.prototype.load = function(onReady) {
1018
+ var urls = this.configuration_['urls'] || [];
1019
+ var families = this.configuration_['families'] || [];
1020
+
1021
+ for (var i = 0, len = urls.length; i < len; i++) {
1022
+ var url = urls[i];
1023
+
1024
+ this.domHelper_.insertInto('head', this.domHelper_.createCssLink(url));
1025
+ }
1026
+ onReady(families);
1027
+ };
1028
+
1029
+ webfont.CustomCss.prototype.supportUserAgent = function(userAgent, support) {
1030
+ return support(userAgent.isSupportingWebFont());
1031
+ };
1032
+
1033
+ WebFont.addModule(webfont.CustomCss.NAME, function(configuration) {
1034
+ return new webfont.CustomCss(new webfont.DomHelper(document),
1035
+ configuration);
1036
+ });
1037
+
1038
+ webfont.TypekitScript = function(global, domHelper, configuration) {
1039
+ this.global_ = global;
1040
+ this.domHelper_ = domHelper;
1041
+ this.configuration_ = configuration;
1042
+ this.fontFamilies_ = [];
1043
+ this.fontVariations_ = {};
1044
+ };
1045
+
1046
+ webfont.TypekitScript.NAME = 'typekit';
1047
+ webfont.TypekitScript.HOOK = '__webfonttypekitmodule__';
1048
+
1049
+ webfont.TypekitScript.prototype.getScriptSrc = function(kitId) {
1050
+ var api = this.configuration_['api'] || 'http://use.typekit.com';
1051
+ return api + '/' + kitId + '.js';
1052
+ };
1053
+
1054
+ webfont.TypekitScript.prototype.supportUserAgent = function(userAgent, support) {
1055
+ var kitId = this.configuration_['id'];
1056
+ var configuration = this.configuration_;
1057
+ var self = this;
1058
+
1059
+ if (kitId) {
1060
+ // Provide data to Typekit for processing.
1061
+ if (!this.global_[webfont.TypekitScript.HOOK]) {
1062
+ this.global_[webfont.TypekitScript.HOOK] = {};
1063
+ }
1064
+
1065
+ // Typekit will call 'init' to indicate whether it supports fonts
1066
+ // and what fonts will be provided.
1067
+ this.global_[webfont.TypekitScript.HOOK][kitId] = function(callback) {
1068
+ var init = function(typekitSupports, fontFamilies, fontVariations) {
1069
+ self.fontFamilies_ = fontFamilies;
1070
+ self.fontVariations_ = fontVariations;
1071
+ support(typekitSupports);
1072
+ };
1073
+ callback(userAgent, configuration, init);
1074
+ };
1075
+
1076
+ // Load the Typekit script.
1077
+ var script = this.domHelper_.createScriptSrc(this.getScriptSrc(kitId))
1078
+ this.domHelper_.insertInto('head', script);
1079
+
1080
+ } else {
1081
+ support(true);
1082
+ }
1083
+ };
1084
+
1085
+ webfont.TypekitScript.prototype.load = function(onReady) {
1086
+ onReady(this.fontFamilies_, this.fontVariations_);
1087
+ };
1088
+
1089
+ WebFont.addModule(webfont.TypekitScript.NAME, function(configuration) {
1090
+ return new webfont.TypekitScript(window, new webfont.DomHelper(document), configuration);
1091
+ });
1092
+