r112529 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r112528‎ | r112529 | r112530 >
Date:21:58, 27 February 2012
Author:jdlrobson
Status:ok (Comments)
Tags:
Comment:
use jquery where available instead of native javascript library
Modified paths:
  • /trunk/extensions/MobileFrontend/javascripts/application.js (modified) (history)
  • /trunk/extensions/MobileFrontend/javascripts/beta_application.js (modified) (history)

Diff [purge]

Index: trunk/extensions/MobileFrontend/javascripts/beta_application.js
@@ -98,7 +98,7 @@
9999 }
100100 }
101101
102 - function utilities( el ) {
 102+ utilities = typeof(jQuery) !== "undefined" ? jQuery : function( el ) {
103103 if( typeof(el) === 'string' ) {
104104 if( document.querySelectorAll ) {
105105 return document.querySelectorAll( el );
@@ -133,7 +133,7 @@
134134 removeClass: removeClass
135135 };
136136 }
137 - utilities.ajax = function( options ) {
 137+ utilities.ajax = utilities.ajax || function( options ) {
138138 var xmlHttp, url;
139139 if ( window.XMLHttpRequest ) {
140140 xmlHttp = new XMLHttpRequest();
Index: trunk/extensions/MobileFrontend/javascripts/application.js
@@ -94,7 +94,7 @@
9595 }
9696 }
9797
98 - utilities = function( el ) {
 98+ utilities = typeof(jQuery) !== "undefined" ? jQuery : function( el ) {
9999 if( typeof(el) === 'string' ) {
100100 if( document.querySelectorAll ) {
101101 return document.querySelectorAll( el );
@@ -128,7 +128,7 @@
129129 removeClass: removeClass
130130 };
131131 }
132 - utilities.ajax = function( options ) {
 132+ utilities.ajax = utilities.ajax || function( options ) {
133133 var xmlHttp, url;
134134 if ( window.XMLHttpRequest ) {
135135 xmlHttp = new XMLHttpRequest();

Follow-up revisions

RevisionCommit summaryAuthorDate
r112674follow up to r112529 c31595jdlrobson09:36, 29 February 2012

Comments

#Comment by Robmoen (talk | contribs)   21:23, 28 February 2012

Marking ok. Though, Per JS conventions use typeof as an operator instead of a function.

utilities = typeof(jQuery) !== "undefined" ? jQuery : function( el ) {
	if( typeof(el) === 'string' ) {

Use:

utilities = typeof jQuery !== 'undefined' ? jQuery : function( el ) {
	if( typeof el === 'string' ) {
#Comment by Catrope (talk | contribs)   21:24, 28 February 2012

You can also use utilities = jQuery || function( el ) { .... };

#Comment by Catrope (talk | contribs)   21:25, 28 February 2012

Wait, you can't, never mind.

#Comment by Jdlrobson (talk | contribs)   09:37, 29 February 2012

Nice catch! Addressed in r112674

Status & tagging log