Blame Identity/Models/Html/Trac/htdocs/js/trac.js

d6e8d8
// Used for dynamically updating the height of a textarea
d6e8d8
function resizeTextArea(id, rows) {
d6e8d8
  var textarea = document.getElementById(id);
d6e8d8
  if (!textarea || (typeof(textarea.rows) == "undefined")) return;
d6e8d8
  textarea.rows = rows;
d6e8d8
}
d6e8d8
d6e8d8
// A better way than for example hardcoding foo.onload
d6e8d8
function addEvent(element, type, func){
d6e8d8
  if (element.addEventListener) {
d6e8d8
    element.addEventListener(type, func, false);
d6e8d8
    return true;
d6e8d8
  } else if (element.attachEvent) {
d6e8d8
    return element.attachEvent("on" + type, func);
d6e8d8
  }
d6e8d8
  return false;
d6e8d8
}
d6e8d8
d6e8d8
// Convenience function for the nearest ancestor element with a specific tag
d6e8d8
// name
d6e8d8
function getAncestorByTagName(e, tagName) {
d6e8d8
  tagName = tagName.toLowerCase();
d6e8d8
  do {
d6e8d8
    e = e.parentNode;
d6e8d8
  } while ((e.nodeType == 1) && (e.tagName.toLowerCase() != tagName));
d6e8d8
  return (e.nodeType == 1) ? e : null;
d6e8d8
}
d6e8d8
d6e8d8
// Adapted from http://www.kryogenix.org/code/browser/searchhi/
d6e8d8
function searchHighlight() {
d6e8d8
  if (!document.createElement) return;
d6e8d8
d6e8d8
  var div = document.getElementById("searchable");
d6e8d8
  if (!div) return;
d6e8d8
d6e8d8
  function getSearchWords(url) {
d6e8d8
    if (url.indexOf('?') == -1) return [];
d6e8d8
    var queryString = url.substr(url.indexOf('?') + 1);
d6e8d8
    var params = queryString.split('&';;
d6e8d8
    for (var p in params) {
d6e8d8
      var param = params[p].split('=');
d6e8d8
      if (param.length < 2) continue;
d6e8d8
      if (param[0] == 'q' || param[0] == 'p') { // q= for Google, p= for Yahoo
d6e8d8
        var query = decodeURIComponent(param[1].replace(/\+/g, ' '));
d6e8d8
        if (query[0] == '!') query = query.slice(1);
d6e8d8
        words = query.split(/(".*?")|('.*?')|(\s+)/);
d6e8d8
        var words2 = new Array();
d6e8d8
        for (var w in words) {
d6e8d8
          words[w] = words[w].replace(/^\s+$/, '');
d6e8d8
          if (words[w] != '') {
d6e8d8
            words2.push(words[w].replace(/^['"]/, '').replace(/['"]$/, ''));
d6e8d8
          }
d6e8d8
        }
d6e8d8
        return words2;
d6e8d8
      }
d6e8d8
    }
d6e8d8
    return [];
d6e8d8
  }
d6e8d8
d6e8d8
  function highlightWord(node, word, searchwordindex) {
d6e8d8
    // If this node is a text node and contains the search word, highlight it by
d6e8d8
    // surrounding it with a span element
d6e8d8
    if (node.nodeType == 3) { // Node.TEXT_NODE
d6e8d8
      var pos = node.nodeValue.toLowerCase().indexOf(word.toLowerCase());
d6e8d8
      if (pos >= 0 && !/^searchword\d$/.test(node.parentNode.className)) {
d6e8d8
        var span = document.createElement("span");
d6e8d8
        span.className = "searchword" + (searchwordindex % 5);
d6e8d8
        span.appendChild(document.createTextNode(
d6e8d8
          node.nodeValue.substr(pos, word.length)));
d6e8d8
        node.parentNode.insertBefore(span, node.parentNode.insertBefore(
d6e8d8
          document.createTextNode(node.nodeValue.substr(pos + word.length)),
d6e8d8
            node.nextSibling));
d6e8d8
        node.nodeValue = node.nodeValue.substr(0, pos);
d6e8d8
        return true;
d6e8d8
      }
d6e8d8
    } else if (!node.nodeName.match(/button|select|textarea/i)) {
d6e8d8
      // Recurse into child nodes
d6e8d8
      for (var i = 0; i < node.childNodes.length; i++) {
d6e8d8
        if (highlightWord(node.childNodes[i], word, searchwordindex)) i++;
d6e8d8
      }
d6e8d8
    }
d6e8d8
    return false;
d6e8d8
  }
d6e8d8
d6e8d8
  var words = getSearchWords(document.URL);
d6e8d8
  if (!words.length) words = getSearchWords(document.referrer);
d6e8d8
  if (words.length) {
d6e8d8
    for (var w in words) {
d6e8d8
      if (words[w].length) highlightWord(div, words[w], w);
d6e8d8
    }
d6e8d8
  }
d6e8d8
}
d6e8d8
d6e8d8
function enableControl(id, enabled) {
d6e8d8
  if (typeof(enabled) == "undefined") enabled = true;
d6e8d8
  var control = document.getElementById(id);
d6e8d8
  if (!control) return;
d6e8d8
  control.disabled = !enabled;
d6e8d8
  var label = getAncestorByTagName(control, "label");
d6e8d8
  if (label) {
d6e8d8
    label.className = enabled ? "enabled" : "disabled";
d6e8d8
  } else {
d6e8d8
    var labels = document.getElementsByTagName("label");
d6e8d8
    for (var i = 0; i < labels.length; i++) {
d6e8d8
      if (labels[i].htmlFor == id) {
d6e8d8
        labels[i].className = enabled ? "enabled" : "disabled";
d6e8d8
        break;
d6e8d8
      }
d6e8d8
    }
d6e8d8
  }
d6e8d8
}
d6e8d8
d6e8d8
function addHeadingLinks(container, title) {
d6e8d8
  var base = document.location.pathname;
d6e8d8
  function addLinks(elems) {
d6e8d8
    for (var i = 0; i < elems.length; i++) {
d6e8d8
      var hn = elems[i];
d6e8d8
      if (hn.id) {
d6e8d8
        var link = document.createElement('a');
d6e8d8
        link.href = base + '#' + hn.id;
d6e8d8
        link.className = 'anchor';
d6e8d8
        link.title = title.replace(/\$id/, hn.id);
d6e8d8
        link.appendChild(document.createTextNode(" \u00B6"));
d6e8d8
        hn.appendChild(link);
d6e8d8
      }
d6e8d8
    }
d6e8d8
  }
d6e8d8
  for (var lvl = 0; lvl <= 6; lvl++) {
d6e8d8
    addLinks(container.getElementsByTagName('h' + lvl));
d6e8d8
  }
d6e8d8
}