-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mount standalone API via new Wikilookup global (#10)
* This starts the decoupling process by separating the jQuery plugin from the standalone Wikilookup API. An alias is kept for compatibility (verified by unit tests which I intentionally left unmodified in this commit). * Update ESLint config to only whitelist "jQuery", and not "$". This project uses file closures to map from one to the other, which is presumably to support WordPress themes that might have other legacy libraries occupying the $ global (e.g. via jQuery.noConflict etc). Enforce this to avoid mistakes from slipping in by only whitelisting the one we want to use globally. No violations were found by ESLint :) * Update some of the public-facing titles to refer to the library as Wikilookup instead of jQuery.wikilookup, jQuery.Wikilookup or $.wikilookup. Ref #6.
- Loading branch information
Showing
12 changed files
with
57 additions
and
61 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
"browser": true | ||
}, | ||
"globals": { | ||
"$": false, | ||
"jQuery": false | ||
"jQuery": false, | ||
"Wikilookup": false | ||
} | ||
} |
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
( function ( $ ) { | ||
if ( !$.wikilookup ) { | ||
$.wikilookup = {}; | ||
} | ||
}( jQuery ) ); | ||
// Support: Wikilookup 0.2.3 and earlier | ||
// Also expose Wikilookup via $.wikilookup | ||
jQuery.wikilookup = window.Wikilookup = {}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,22 @@ | ||
( function ( $ ) { | ||
$.wikilookup.tools = { | ||
/** | ||
* Get the value of a nested property in an object, | ||
* if it exists, safely. If, at any point, the chain | ||
* breaks, the method safely stops and returns undefined. | ||
* | ||
* @param {Object} obj Object to fetch the property from | ||
* @param {string[]} props An array of nested properties | ||
* @return {Mixed} Value of the nested property chain | ||
*/ | ||
getPropValue: function ( obj, props ) { | ||
var val = obj || {}, | ||
counter = 0; | ||
Wikilookup.tools = { | ||
/** | ||
* Get the value of a nested property in an object, | ||
* if it exists, safely. If, at any point, the chain | ||
* breaks, the method safely stops and returns undefined. | ||
* | ||
* @param {Object} obj Object to fetch the property from | ||
* @param {string[]} props An array of nested properties | ||
* @return {Mixed} Value of the nested property chain | ||
*/ | ||
getPropValue: function ( obj, props ) { | ||
var val = obj || {}, | ||
counter = 0; | ||
|
||
do { | ||
val = val[ props[ counter ] ]; | ||
counter++; | ||
} while ( val && counter < props.length ); | ||
do { | ||
val = val[ props[ counter ] ]; | ||
counter++; | ||
} while ( val && counter < props.length ); | ||
|
||
return val; | ||
} | ||
}; | ||
}( jQuery ) ); | ||
return val; | ||
} | ||
}; |
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