Conversation
It would be awesome if jquery wasn't needed for this one, There's not a lot of $-functions. maybe you could change them if your looking at this http://youmightnotneedjquery.com/ |
I agree with @icaaq ; we should avoid jQuery if possible. Additionally, I think we should make this one big function instead of setting globals as options. Then the user could call:
|
Removed jQuery dependency and use of global for settings. The embed script is now:
|
// For the time being, we are not gonna do anything if querySelectorAll is not available in the browser | ||
if ('querySelectorAll' in document) { | ||
var elements = document.querySelectorAll(options.include_elems.join(', ')); | ||
Array.prototype.forEach.call(elements, function(o, i){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use elements.forEach
directly, I believe; might be cleaner. We should probably also include an Array.prototype.forEach
check as well, since that was introduced with querySelectorAll
.
One more tiny nitpick is that the JavaScript standard is camel-casing. Not a big deal. |
@@ -0,0 +1,161 @@ | |||
var _mdn_promote_links = window._mdn_promote_links || function (user_settings) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this just be: function mdnPromoteLinks()
?
Changes:
|
FWIW, once this hits production, we need to be sure to remove the warning that this doesn't work from the docs pointing to it here: https://developer.mozilla.org/en-US/docs/MDN/Promote#Embed_code_%28JavaScript%29 |
I have some more improvements to make and some more tests to do. Once I complete them in a couple of days I'll deploy it in my blog for testing. Once it seems working ok, I'll edit the doc and remove the warning. Thanks, |
Awesome, just let me know when it's ready to look at again! |
Also, I just thought of something. Can we add another |
I agree, adding s user settings option for custom links would be helpful. Eric Shepherd
|
Yeah, will do. (Sorry, got caught up in pending work at office after reaching back from Paris) |
Sorry for the delay :) Added provision for the user to pass extra links to the script to linkify. The updated embed code is:
|
var options = { | ||
includeElems: ['p', 'div', 'span'], | ||
trackingSting: '?utm_source=js%20snippet&utm_medium=content%20link&utm_campaign=promote%20mdn', | ||
maxlinks: 3, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent with the camel-casing of other Elements, we should call this maxLinks
Yay more progress! 💃 |
@darkwing can you take another look please. |
@@ -0,0 +1,206 @@ | |||
var mdnPromoteLinks = window.mdnPromoteLinks || function (userSettings) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change this line to:
function PromoteMDNLinks(userSettings) {
After your next commit, can you squash your commits into one? http://davidwalsh.name/squash-commits-git That way I can more easily send you a pull request with changes in the future! Thank you so much! |
Oh, also, do you have a test document you could add to this PR? That way we can compare and test the same way! |
Removed dependancy on jQuery Removed jQuery dependancy and use of gloabl for settings. Replacedd massive if block with an early return if browser doesn't support querySelectorAll. Repalced all under_scored names to camelCased Added provision to pass a custom classname to be used on outbound links to MDN. Cleaned up nodelist.forEach a little and added a polyfill for array.forEach Some stupid bug fixes and improvements in keyword mathcing. Renamed maxlinks param to maxLinks for consistency. Fixed typo in a variable name. Rewriting the array forEach shim code to use a standalone function, rather than extending the array prototype. Moved the checking for document.querySelectorAll support to the beginning of the code. Adding provision for the end user to pass extra keywords and links for the script to linkify. A couple of minor improvements.
Squashed the commits into one large commit. The test document that I'm using is at https://github.com/riverspirit/promote-mdn-script/blob/master/promote-mdn-test.html |
|
||
options = extend({}, options, userSettings || {}); | ||
|
||
for (var i in options.extraLinks) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can use your extend
function here
…th the inbuilt keyword-links
Done. Should I squash it again? |
Yes please! :) Tomorrow I'm going to download your stuff and then submit PRs for further updates. Great work on this! I'm so excited! |
Removed dependancy on jQuery Removed jQuery dependancy and use of gloabl for settings. Replacedd massive if block with an early return if browser doesn't support querySelectorAll. Repalced all under_scored names to camelCased Added provision to pass a custom classname to be used on outbound links to MDN. Cleaned up nodelist.forEach a little and added a polyfill for array.forEach Some stupid bug fixes and improvements in keyword mathcing. Renamed maxlinks param to maxLinks for consistency. Fixed typo in a variable name. Rewriting the array forEach shim code to use a standalone function, rather than extending the array prototype. Moved the checking for document.querySelectorAll support to the beginning of the code. Adding provision for the end user to pass extra keywords and links for the script to linkify. A couple of minor improvements. Reusing the extend function to merge the user passed keyword-links with the inbuilt keyword-links
Removed dependancy on jQuery Removed jQuery dependancy and use of gloabl for settings. Replacedd massive if block with an early return if browser doesn't support querySelectorAll. Repalced all under_scored names to camelCased Added provision to pass a custom classname to be used on outbound links to MDN. Cleaned up nodelist.forEach a little and added a polyfill for array.forEach Some stupid bug fixes and improvements in keyword mathcing. Renamed maxlinks param to maxLinks for consistency. Fixed typo in a variable name. Rewriting the array forEach shim code to use a standalone function, rather than extending the array prototype. Moved the checking for document.querySelectorAll support to the beginning of the code. Adding provision for the end user to pass extra keywords and links for the script to linkify. A couple of minor improvements. Reusing the extend function to merge the user passed keyword-links with the inbuilt keyword-links
I think I messed up something with the rebasing. My actual squashed commit is riverspirit/kuma@042d82b But every time I push the squashed commit, I'm being asked to pull again and that is causing another merge commit. Is that ok? |
Looking again |
I made some updates here: https://gist.github.com/darkwing/9693628 Something is up with your branch though :/ Can you try to rebase again? |
@darkwing, i messed up something big time with the rebase. Is it ok to open a new pull request for the consolidated commit? |
Yes, of course :) I don't need credit, you've done all the work! :) |
@riverspirit I'm going to close this for now until you have your updated PR. Thank you! |
@darkwing once again sorry about the delay. Been busy with http://html5conf.in that we're organizing early next month. Thanks for your encouragement. |
About promote MDN script
People can embed this code in their sites and it will scan their site content for keywords such as 'JavaScript' and will link it back to the corresponding page on MDN on that topic.
Code to embed in sites