From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: John 'Warthog9' Hawley <warthog9@eaglescrag.net>,
Kevin Cernekee <cernekee@gmail.com>,
Jakub Narebski <jnareb@gmail.com>
Subject: [PATCH 06/11] gitweb.js: Provide getElementsByClassName method (if it not exists)
Date: Fri, 15 Apr 2011 16:44:00 +0200 [thread overview]
Message-ID: <1302878645-458-7-git-send-email-jnareb@gmail.com> (raw)
In-Reply-To: <1302878645-458-1-git-send-email-jnareb@gmail.com>
The code is simplified and does not support full specification of
native getElementsByClassName method, but implements just subset that
would be enough for gitweb, supporting only single class name.
This patch makes subsequent timezone manipulation work on Mozilla
1.17.2 which doesn't have document.getElementsByClassName (while
native implementation is used e.g. for Firefox 4.0).
Signed-off-by: John 'Warthog9' Hawley <warthog9@eaglescrag.net>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This patch is unchanged from v1 version, except added commentary in
the commit message.
gitweb/static/js/lib/common-lib.js | 51 ++++++++++++++++++++++++++++++++++++
1 files changed, 51 insertions(+), 0 deletions(-)
diff --git a/gitweb/static/js/lib/common-lib.js b/gitweb/static/js/lib/common-lib.js
index d6b0c0d..b371391 100644
--- a/gitweb/static/js/lib/common-lib.js
+++ b/gitweb/static/js/lib/common-lib.js
@@ -89,6 +89,57 @@ function createRequestObject() {
/* ............................................................ */
+/* Support for legacy browsers */
+
+/**
+ * Provides getElementsByClassName method, if there is no native
+ * implementation of this method.
+ *
+ * NOTE that there are limits and differences compared to native
+ * getElementsByClassName as defined by e.g.:
+ * https://developer.mozilla.org/en/DOM/document.getElementsByClassName
+ * http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#dom-getelementsbyclassname
+ * http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#dom-document-getelementsbyclassname
+ *
+ * Namely, this implementation supports only single class name as
+ * argument and not set of space-separated tokens representing classes,
+ * it returns Array of nodes rather than live NodeList, and has
+ * additional optional argument where you can limit search to given tags
+ * (via getElementsByTagName).
+ *
+ * Based on
+ * http://code.google.com/p/getelementsbyclassname/
+ * http://www.dustindiaz.com/getelementsbyclass/
+ * http://stackoverflow.com/questions/1818865/do-we-have-getelementsbyclassname-in-javascript
+ *
+ * See also http://ejohn.org/blog/getelementsbyclassname-speed-comparison/
+ *
+ * @param {String} class: name of _single_ class to find
+ * @param {String} [taghint] limit search to given tags
+ * @returns {Node[]} array of matching elements
+ */
+if (!('getElementsByClassName' in document)) {
+ document.getElementsByClassName = function (classname, taghint) {
+ taghint = taghint || "*";
+ var elements = (taghint === "*" && document.all) ?
+ document.all :
+ document.getElementsByTagName(taghint);
+ var pattern = new RegExp("(^|\\s)" + classname + "(\\s|$)");
+ var matches= [];
+ for (var i = 0, j = 0, n = elements.length; i < n; i++) {
+ var el= elements[i];
+ if (el.className && pattern.test(el.className)) {
+ // matches.push(el);
+ matches[j] = el;
+ j++;
+ }
+ }
+ return matches;
+ };
+} // end if
+
+
+/* ............................................................ */
/* unquoting/unescaping filenames */
/**#@+
--
1.7.3
next prev parent reply other threads:[~2011-04-15 14:45 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-04-15 14:43 [PATCHv2 00/11] gitweb: Change timezone in dates using JavaScript Jakub Narebski
2011-04-15 14:43 ` [PATCH 01/11] gitweb: Split JavaScript for maintability, combining on build Jakub Narebski
2011-04-15 14:43 ` [PATCH 02/11] gitweb.js: Update and improve comments in JavaScript files Jakub Narebski
2011-04-15 14:43 ` [PATCH 03/11] gitweb.js: Provide default values for padding in padLeftStr and padLeft Jakub Narebski
2011-04-15 14:43 ` [PATCH 04/11] gitweb.js: Extract and improve datetime handling Jakub Narebski
2011-04-15 14:43 ` [PATCH 05/11] gitweb.js: Introduce gitweb/static/js/lib/cookies.js Jakub Narebski
2011-04-15 14:44 ` Jakub Narebski [this message]
2011-04-15 14:44 ` [PATCH 07/11] gitweb: Refactor generating of long dates into format_timestamp_html Jakub Narebski
2011-04-15 14:44 ` [PATCH 08/11] gitweb: Unify the way long timestamp is displayed Jakub Narebski
2011-04-15 14:44 ` [PATCH 09/11] gitweb: JavaScript ability to adjust time based on timezone Jakub Narebski
2011-04-15 14:44 ` [PATCHv2/RFC 10/11] gitweb.js: Add UI for selecting common timezone to display dates Jakub Narebski
2011-04-15 17:43 ` Jakub Narebski
2011-04-15 18:06 ` Jakub Narebski
2011-04-15 19:17 ` [PATCHv3 " Jakub Narebski
2011-04-15 14:44 ` [PATCHv2/RFC 11/11] gitweb: Make JavaScript ability to adjust timezones configurable Jakub Narebski
2011-04-19 1:01 ` [PATCHv2 00/11] gitweb: Change timezone in dates using JavaScript Junio C Hamano
2011-04-19 1:26 ` Jakub Narebski
2011-04-19 6:36 ` Jakub Narebski
2011-04-19 16:58 ` Junio C Hamano
2011-04-19 17:18 ` [PATCH 12/11] Remove gitweb/gitweb.cgi and other legacy targets from main Makefile Jakub Narebski
2011-04-19 11:54 ` [PATCH -01/11] git-instaweb: Simplify build dependency on gitweb Jakub Narebski
-- strict thread matches above, loose matches on Subject: below --
2011-04-09 22:49 [PATCH 00/11] gitweb: Change timezone Jakub Narebski
2011-04-09 22:49 ` [PATCH 06/11] gitweb.js: Provide getElementsByClassName method (if it not exists) Jakub Narebski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1302878645-458-7-git-send-email-jnareb@gmail.com \
--to=jnareb@gmail.com \
--cc=cernekee@gmail.com \
--cc=git@vger.kernel.org \
--cc=warthog9@eaglescrag.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).