r68682 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r68681‎ | r68682 | r68683 >
Date:20:12, 28 June 2010
Author:papyromancer
Status:deferred (Comments)
Tags:
Comment:
adding in Modernizr for css-transform capabilities check
Modified paths:
  • /branches/MwEmbedStandAlone/libraries/jquery/plugins/modernizr.js (added) (history)
  • /branches/MwEmbedStandAlone/loader.js (modified) (history)
  • /branches/MwEmbedStandAlone/mwEmbed.js (modified) (history)

Diff [purge]

Index: branches/MwEmbedStandAlone/loader.js
@@ -21,7 +21,8 @@
2222 var mwCoreComponentList = [
2323 'mw.Parser',
2424 'mw.Language',
25 - 'mw.Api'
 25+ 'mw.Api',
 26+ 'Modernizr'
2627 ];
2728
2829
@@ -120,7 +121,7 @@
121122 "mw.Language" : "components/mw.Language.js",
122123 "mw.Parser" : "components/mw.Parser.js",
123124 "mw.Api" : "components/mw.Api.js",
124 -
 125+ "Modernizr" : "libraries/jquery/plugins/modernizr.js",
125126 "JSON" : "libraries/json/json2.js",
126127
127128 "$j.replaceText.js" : "libraries/jquery/plugins/jquery.replaceText.js",
Index: branches/MwEmbedStandAlone/mwEmbed.js
@@ -2123,12 +2123,12 @@
21242124 */
21252125 $.fn.loadingSpinner = function( ) {
21262126 if ( this ) {
2127 - var csstransforms = false;
2128 - if ( csstransforms ) {
 2127+ //var csstransforms = false;
 2128+ if ( Modernizr.csstransforms ) {
21292129 var barNumber = 7;
21302130 var barContent = '';
21312131 var barSpacingDegrees = 360 / barNumber;
2132 - var barOpacityDelta = 1 / (barNumber)
 2132+ var barOpacityDelta = 1 / (barNumber);
21332133 for (i = 1; i < barNumber+1; i++) {
21342134 barContent += '<div class="bar' + i + '" style="-moz-transform:rotate(' + (i-1) * barSpacingDegrees + 'deg) translate(0, -40px);-webkit-transform:rotate(' + (i-1) * barSpacingDegrees + 'deg) translate(0, -40px);opacity:' + (i) * barOpacityDelta + '; background:#000"/>';
21352135 }
Index: branches/MwEmbedStandAlone/libraries/jquery/plugins/modernizr.js
@@ -0,0 +1,307 @@
 2+/*!
 3+ * Modernizr JavaScript library 1.2pre
 4+ * http://modernizr.com/
 5+ *
 6+ * Copyright (c) 2009-2010 Faruk Ates - http://farukat.es/
 7+ * Licensed under the MIT license.
 8+ * http://modernizr.com/license/
 9+ *
 10+ * Featuring major contributions by
 11+ * Paul Irish - http://paulirish.com
 12+ */
 13+/*
 14+ * Modernizr is a script that will detect native CSS3 and HTML5 features
 15+ * available in the current UA and provide an object containing all
 16+ * features with a true/false value, depending on whether the UA has
 17+ * native support for it or not.
 18+ *
 19+ * In addition to that, Modernizr will add classes to the <html>
 20+ * element of the page, one for each cutting-edge feature. If the UA
 21+ * supports it, a class like "cssgradients" will be added. If not,
 22+ * the class name will be "no-cssgradients". This allows for simple
 23+ * if-conditionals in CSS styling, making it easily to have fine
 24+ * control over the look and feel of your website.
 25+ *
 26+ * @author Faruk Ates
 27+ * @copyright (2009-2010) Faruk Ates.
 28+ *
 29+ * @contributor Paul Irish
 30+ * @contributor Ben Alman
 31+ */
 32+
 33+window.Modernizr = (function(window,doc,undefined){
 34+
 35+ var version = '1.2pre',
 36+
 37+ ret = {},
 38+
 39+ /**
 40+ * enableHTML5 is a private property for advanced use only. If enabled,
 41+ * it will make Modernizr.init() run through a brief while() loop in
 42+ * which it will create all HTML5 elements in the DOM to allow for
 43+ * styling them in Internet Explorer, which does not recognize any
 44+ * non-HTML4 elements unless created in the DOM this way.
 45+ *
 46+ * enableHTML5 is ON by default.
 47+ */
 48+ enableHTML5 = true,
 49+
 50+
 51+ /**
 52+ * fontfaceCheckDelay is the ms delay before the @font-face test is
 53+ * checked a second time. This is neccessary because both Gecko and
 54+ * WebKit do not load data: URI font data synchronously.
 55+ * https://bugzilla.mozilla.org/show_bug.cgi?id=512566
 56+ * The check will be done again at fontfaceCheckDelay*2 and then
 57+ * a fourth time at window's load event.
 58+ * If you need to query for @font-face support, send a callback to:
 59+ * Modernizr._fontfaceready(fn);
 60+ * The callback is passed the boolean value of Modernizr.fontface
 61+ */
 62+ fontfaceCheckDelay = 75,
 63+
 64+
 65+ docElement = doc.documentElement,
 66+
 67+ /**
 68+ * Create our "modernizr" element that we do most feature tests on.
 69+ */
 70+ mod = 'modernizr'
 71+ m = doc.createElement( mod ),
 72+ m_style = m.style,
 73+
 74+ /**
 75+ * Create the input element for various Web Forms feature tests.
 76+ */
 77+ f = doc.createElement( 'input' ),
 78+
 79+ // Reused strings.
 80+
 81+ canvas = 'canvas',
 82+ canvastext = 'canvastext',
 83+ webgl = 'webgl',
 84+ rgba = 'rgba',
 85+ hsla = 'hsla',
 86+ multiplebgs = 'multiplebgs',
 87+ borderimage = 'borderimage',
 88+ borderradius = 'borderradius',
 89+ boxshadow = 'boxshadow',
 90+ opacity = 'opacity',
 91+ cssanimations = 'cssanimations',
 92+ csscolumns = 'csscolumns',
 93+ cssgradients = 'cssgradients',
 94+ cssreflections = 'cssreflections',
 95+ csstransforms = 'csstransforms',
 96+ csstransforms3d = 'csstransforms3d',
 97+ csstransitions = 'csstransitions',
 98+ fontface = 'fontface',
 99+ geolocation = 'geolocation',
 100+ video = 'video',
 101+ audio = 'audio',
 102+ input = 'input',
 103+ inputtypes = input + 'types',
 104+ // inputtypes is an object of its own containing individual tests for
 105+ // various new input types, such as search, range, datetime, etc.
 106+
 107+ svg = 'svg',
 108+ smil = 'smil',
 109+ svgclippaths = svg+'clippaths',
 110+
 111+ background = 'background',
 112+ backgroundColor = background + 'Color',
 113+ canPlayType = 'canPlayType',
 114+
 115+ // FF gets really angry if you name local variables as these, but camelCased.
 116+ localstorage = 'localStorage',
 117+ sessionstorage = 'sessionStorage',
 118+ applicationcache = 'applicationCache',
 119+
 120+ webWorkers = 'webworkers',
 121+ hashchange = 'hashchange',
 122+ crosswindowmessaging = 'crosswindowmessaging',
 123+ historymanagement = 'historymanagement',
 124+ draganddrop = 'draganddrop',
 125+ websqldatabase = 'websqldatabase',
 126+ websocket = 'websocket',
 127+ flash = 'flash',
 128+ smile = ':)',
 129+ touch = 'touch',
 130+
 131+ toString = Object.prototype.toString,
 132+
 133+ // list of property values to set for css tests. see ticket #21
 134+ setProperties = ' -o- -moz- -ms- -webkit- -khtml- '.split(' '),
 135+
 136+ tests = {},
 137+ inputs = {},
 138+ attrs = {},
 139+
 140+ classes = [],
 141+
 142+ /**
 143+ * isEventSupported determines if a given element supports the given event
 144+ * function from http://yura.thinkweb2.com/isEventSupported/
 145+ */
 146+ isEventSupported = (function(){
 147+
 148+ var TAGNAMES = {
 149+ 'select':'input','change':'input',
 150+ 'submit':'form','reset':'form',
 151+ 'error':'img','load':'img','abort':'img'
 152+ },
 153+ cache = { };
 154+
 155+ function isEventSupported(eventName, element) {
 156+ var canCache = (arguments.length == 1);
 157+
 158+ // only return cached result when no element is given
 159+ if (canCache && cache[eventName]) {
 160+ return cache[eventName];
 161+ }
 162+
 163+ element = element || document.createElement(TAGNAMES[eventName] || 'div');
 164+ eventName = 'on' + eventName;
 165+
 166+ // When using `setAttribute`, IE skips "unload", WebKit skips "unload" and "resize"
 167+ // `in` "catches" those
 168+ var isSupported = (eventName in element);
 169+
 170+ if (!isSupported && element.setAttribute) {
 171+ element.setAttribute(eventName, 'return;');
 172+ isSupported = typeof element[eventName] == 'function';
 173+ }
 174+
 175+ element = null;
 176+ return canCache ? (cache[eventName] = isSupported) : isSupported;
 177+ }
 178+
 179+ return isEventSupported;
 180+ })();
 181+
 182+
 183+ /**
 184+ * set_css applies given styles to the Modernizr DOM node.
 185+ */
 186+ function set_css( str ) {
 187+ m_style.cssText = str;
 188+ }
 189+
 190+ /**
 191+ * set_css_all extrapolates all vendor-specific css strings.
 192+ */
 193+ function set_css_all( str1, str2 ) {
 194+ return set_css(setProperties.join(str1 + ';') + ( str2 || '' ));
 195+ }
 196+
 197+ /**
 198+ * contains returns a boolean for if substr is found within str.
 199+ */
 200+ function contains( str, substr ) {
 201+ return (''+str).indexOf( substr ) !== -1;
 202+ }
 203+
 204+ /**
 205+ * test_props is a generic CSS / DOM property test; if a browser supports
 206+ * a certain property, it won't return undefined for it.
 207+ * A supported CSS property returns empty string when its not yet set.
 208+ */
 209+ function test_props( props, callback ) {
 210+ for ( var i in props ) {
 211+ if ( m_style[ props[i] ] !== undefined && ( !callback || callback( props[i] ) ) ) {
 212+ return true;
 213+ }
 214+ }
 215+ }
 216+
 217+ /**
 218+ * test_props_all tests a list of DOM properties we want to check against.
 219+ * We specify literally ALL possible (known and/or likely) properties on
 220+ * the element including the non-vendor prefixed one, for forward-
 221+ * compatibility.
 222+ */
 223+ function test_props_all( prop, callback ) {
 224+ var uc_prop = prop.charAt(0).toUpperCase() + prop.substr(1),
 225+ props = [
 226+ prop,
 227+ 'Webkit' + uc_prop,
 228+ 'Moz' + uc_prop,
 229+ 'O' + uc_prop,
 230+ 'ms' + uc_prop,
 231+ 'Khtml' + uc_prop
 232+ ];
 233+
 234+ return !!test_props( props, callback );
 235+ }
 236+
 237+ // Tests
 238+
 239+ tests[csstransforms] = function() {
 240+ // set_css_all( 'transform:rotate(3deg)' );
 241+ return !!test_props([ 'transformProperty', 'WebkitTransform', 'MozTransform', 'OTransform', 'msTransform' ]);
 242+ };
 243+
 244+ // end of tests.
 245+
 246+
 247+
 248+ // Run through all tests and detect their support in the current UA.
 249+ // todo: hypothetically we could be doing an array of tests and use a basic loop here.
 250+ for ( var feature in tests ) {
 251+ if ( tests.hasOwnProperty( feature ) ) {
 252+ // run the test, then based on the boolean, define an appropriate className
 253+ classes.push( ( !( ret[ feature ] = tests[ feature ]() ) ? 'no-' : '' ) + feature );
 254+ }
 255+ }
 256+
 257+ // input tests need to run.
 258+// if (!ret[input]) webforms();
 259+
 260+
 261+
 262+
 263+
 264+
 265+ /**
 266+ * Addtest allows the user to define their own feature tests
 267+ * the result will be added onto the Modernizr object,
 268+ * as well as an appropriate className set on the html element
 269+ *
 270+ * @param feature - String naming the feature
 271+ * @param test - Function returning true if feature is supported, false if not
 272+ */
 273+ ret.addTest = function (feature, test) {
 274+ if (ret[ feature ]) {
 275+ return; // quit if you're trying to overwrite an existing test
 276+ }
 277+ feature = feature.toLowerCase();
 278+ test = !!(test());
 279+ docElement.className += ' ' + (!test ? 'no-' : '') + feature;
 280+ ret[ feature ] = test;
 281+ return ret; // allow chaining.
 282+ };
 283+
 284+ /**
 285+ * Reset m.style.cssText to nothing to reduce memory footprint.
 286+ */
 287+ set_css( '' );
 288+ m = f = null;
 289+
 290+ // Enable HTML 5 elements for styling in IE.
 291+ if ( enableHTML5 && !(!/*@cc_on@if(@_jscript_version<9)!@end@*/0) ) {
 292+ // iepp v1.5.1 MIT @jon_neal http://code.google.com/p/ie-print-protector/
 293+ (function(p,e){function q(a,b){if(g[a])g[a].styleSheet.cssText+=b;else{var c=r[l],d=e[j]("style");d.media=a;c.insertBefore(d,c[l]);g[a]=d;q(a,b)}}function s(a,b){for(var c=new RegExp("\\b("+m+")\\b(?!.*[;}])","gi"),d=function(k){return".iepp_"+k},h=-1;++h<a.length;){b=a[h].media||b;s(a[h].imports,b);q(b,a[h].cssText.replace(c,d))}}function t(){for(var a,b=e.getElementsByTagName("*"),c,d,h=new RegExp("^"+m+"$","i"),k=-1;++k<b.length;)if((a=b[k])&&(d=a.nodeName.match(h))){c=new RegExp("^\\s*<"+d+"(.*)\\/"+d+">\\s*$","i");i.innerHTML=a.outerHTML.replace(/\r|\n/g," ").replace(c,a.currentStyle.display=="block"?"<div$1/div>":"<span$1/span>");c=i.childNodes[0];c.className+=" iepp_"+d;c=f[f.length]=[a,c];a.parentNode.replaceChild(c[1],c[0])}s(e.styleSheets,"all")}function u(){for(var a=-1,b;++a<f.length;)f[a][1].parentNode.replaceChild(f[a][0],f[a][1]);for(b in g)r[l].removeChild(g[b]);g={};f=[]}for(var r=e.documentElement,i=e.createDocumentFragment(),g={},m="abbr|article|aside|audio|canvas|command|datalist|details|figure|figcaption|footer|header|hgroup|keygen|mark|meter|nav|output|progress|section|source|summary|time|video",n=m.split("|"),f=[],o=-1,l="firstChild",j="createElement";++o<n.length;){e[j](n[o]);i[j](n[o])}i=i.appendChild(e[j]("div"));p.attachEvent("onbeforeprint",t);p.attachEvent("onafterprint",u)})(this,doc);
 294+ }
 295+
 296+ // Assign private properties to the return object with prefix
 297+ ret._enableHTML5 = enableHTML5;
 298+ ret._version = version;
 299+
 300+ // Remove "no-js" class from <html> element, if it exists:
 301+ docElement.className=docElement.className.replace(/\bno-js\b/,'js');
 302+
 303+ // Add the new classes to the <html> element.
 304+ docElement.className += ' ' + classes.join( ' ' );
 305+
 306+ return ret;
 307+
 308+})(this,this.document);

Comments

#Comment by Mdale (talk | contribs)   18:44, 29 June 2010

I don't think modernizer is a jquery plugin .. should move it to MwEmbedStandAlone/libraries/browser/

Status & tagging log