wiki.techinc.nl/resources/jquery/jquery.highlightText.js

69 lines
2.7 KiB
JavaScript
Raw Normal View History

/**
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
* Plugin that highlights matched word partials in a given element.
* TODO: Add a function for restoring the previous text.
* TODO: Accept mappings for converting shortcuts like WP: to Wikipedia:.
*/
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
( function ( $ ) {
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
$.highlightText = {
// Split our pattern string at spaces and run our highlight function on the results
splitAndHighlight: function ( node, pat ) {
var i,
patArray = pat.split( ' ' );
for ( i = 0; i < patArray.length; i++ ) {
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
if ( patArray[i].length === 0 ) {
continue;
}
$.highlightText.innerHighlight( node, patArray[i] );
}
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
return node;
},
// scans a node looking for the pattern and wraps a span around each match
innerHighlight: function ( node, pat ) {
var i, match, pos, spannode, middlebit, middleclone;
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
// if this is a text node
if ( node.nodeType === 3 ) {
// TODO - need to be smarter about the character matching here.
// non latin characters can make regex think a new word has begun: do not use \b
// http://stackoverflow.com/questions/3787072/regex-wordwrap-with-utf8-characters-in-js
// look for an occurrence of our pattern and store the starting position
Lint: Go-go-gadget jshint! Passing entire JS code base (again). There were still some files not passing jshint, and for files that did, we managed to screw 'em up again. Added more explicit settings in .jshintrc to avoid relying on a kind of default somewhere. There are too many default-factors: closest(.jshintrc), ~/.jshintrc, IDE/editor, node-jshint.. Added node_modules/ and extensions/ to .jshintignore. Previously "$ jshint ." would recurse over all kinds of unrelated code. Extensions should have their own jshint dotfiles. When linting from Jenkins this won't be a problem as those will be ran per repo (so when linting core it will skip extensions and when in an extension dir, the core dotfiles don't apply as they'll be out of scope). Some of our modules are really messy and should be refactored to be less spaghetti-ish and have more descriptive variable names and more manageable function-level complexity. But for this commit, I'm keeping it as much as-is as possible, because its hard/large enough to review as it is. A few errors are cited below to give an impression of the kind of warnings I addressed (for cases where the diff isn't so obvious): * jquery.hidpi.js: line 110, col 15, Empty block. * mediawiki.jqueryMsg.js: line 34, col 17, Too many var statements. * mediawiki.jqueryMsg.js: line 145, col 33, Strings must use singlequote. * mediawiki.action.edit.js: line 74, col 73, 'selectText' is defined but never used. * startup.js: line 19, col 22, 'isCompatible' is defined but never used. * jquery.byteLength.test.js: line 26, col 9, Identifier 'U_00A2' is not in camel case. * jquery.localize.test.js: line 63, col 29, 'attrs' is defined but never used. * mediawiki.cldr.test.js: line 72, col 27, 'mw' is not defined. * mediawiki.jscompat.test.js: line 6, col 17, Strings must use singlequote. * mediawiki.api.parse.test.js: line 9, col 17, Strings must use singlequote. * mediawiki.api.parse.test.js: line 7, col 15, 'mw' is not defined. * mediawiki.api.parse.test.js: line 14, col 24, '$' is not defined. * mediawiki.api.test.js: line 43, col 28, 'data' is defined but never used. Other fixes: * Add closures fix implied global errors ($, mw and more), and prevents local variables from becoming globals. * Avoid jQ magic map arg etc. (per code conventions). * Fix incorrect usage of jQuery methods (prop instead of attr, prop false instead of removeProp, ..). * Unquote keys in object literals for consistency, and enforce single quotes (no magic quotes in javascript, as much as we might think "\n" and '/n' are really exactly the same). Chose single quotes over double quotes since that's what most code already had and what conventions seemed to prefer (both the old generic ones and the new per-lang ones since 2011/2012). * Enforce camelCase variable names with jshint per code conventions. * $foo.on('x', fn).trigger('x') -> $foo.on('x', fn); fn() (No event simulation overhead, unless intended of course) * Incorrect indentation (ignore whitespace in the diff!). * Avoid proprietary selectors like ':first' when .eq(0) afterwards is just as possible (significantly faster in jQuery due to mostly avoiding the Sizzle engine and going native in modern browsers). * When at it, convert deprecated jQuery methods to new ones. Mostly just .delegate(sel, type, fn) -> .on(type, sel, fn). * Addressed whitespace here and there. Interesting: * mediawiki.js: local function "compare" wasn't used anymore (hasn't been in a while!) removed per jshint warning. * mediawiki.special.recentchanges.js: Was a mess, only a few lines of code, rewritten. Pfew, let's hope it's the last one before we lint from Jenkins! Change-Id: I23ad60a1d804c542d9b91454aaa20ce7be4ff289
2012-09-26 07:14:52 +00:00
match = node.data.match( new RegExp( '(^|\\s)' + $.escapeRE( pat ), 'i' ) );
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
if ( match ) {
pos = match.index + match[1].length; // include length of any matched spaces
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
// create the span wrapper for the matched text
spannode = document.createElement( 'span' );
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
spannode.className = 'highlight';
// shave off the characters preceding the matched text
middlebit = node.splitText( pos );
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
// shave off any unmatched text off the end
middlebit.splitText( pat.length );
// clone for appending to our span
middleclone = middlebit.cloneNode( true );
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
// append the matched text node to the span
spannode.appendChild( middleclone );
// replace the matched node, with our span-wrapped clone of the matched node
middlebit.parentNode.replaceChild( spannode, middlebit );
}
// if this is an element with childnodes, and not a script, style or an element we created
} else if ( node.nodeType === 1 && node.childNodes && !/(script|style)/i.test( node.tagName )
&& !( node.tagName.toLowerCase() === 'span' && node.className.match( /\bhighlight/ ) ) ) {
for ( i = 0; i < node.childNodes.length; ++i ) {
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
// call the highlight function for each child node
$.highlightText.innerHighlight( node.childNodes[i], pat );
}
}
}
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
};
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
$.fn.highlightText = function ( matchString ) {
return this.each( function () {
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
var $el = $( this );
$el.data( 'highlightText', { originalText: $el.text() } );
$.highlightText.splitAndHighlight( this, matchString );
} );
};
jshint: resources/jquery/* * .jshintrc: Updated to include more strict options that match our code conventions. Also separated into 3 groups: - stricter (curly, eqeqeq etc.) - laxer (smarttabs, laxbreak) - envrionment (browser) * .jshintignore: Updated to include more third-party/upstream files that should not be linted. * Most of it is just routine cleanup, a few notable points: - jquery.autoEllipsis: Removed unused variable $protectedText. - jquery.arrowSteps.js: Remove <!-- --> and language="javascript" that hasn't been needed for almost a decade. - jquery.byteLimit: Use dashToCamel key for .data(), this already happens internally in jQuery data(), since data storage should use keys that are usable as identifiers. The dashed versions are to populate these from data-attribute-names, which then becomes data.attributeNames. jQuery data() takes both forms as convenience. - jquery.client.js: To avoid a rewrite of it, allowing unexpected assignments (boss) and eval (evil) in the functions that use that. Left as it is for now, could use a rewrite later. - jquery.color.js: Tolerate unexpected assignment for now (boss). Left as it is for now, should perhaps be refactored later. Also re-ordered per jshint/jslint to put definition before invocation. This option can be disabled, but then it doesn't warn for invoking undefined functions (or typos) at all. - jquery.expandableField.js: Remove empty switch/case. - jquery.localize.js: Alias mw global. - jquery.suggestions.js: Use e.which; jQuery.Event normalizes e.keyCode etc. - jquery.tablesorter.js: Alias mw global. - jquery.textSelection.js: Fix leakage of variable in global scope of var "i" and "j". - mediawiki.util.test.js: Fixed implied global `pCustom`. * Review with -w for your own sanity. Change-Id: Ia972f79539a96a38357ec4e92b0b6e38cc301681
2012-07-03 15:21:32 +00:00
}( jQuery ) );