~exarkun/twisted-website/trunk

« back to all changes in this revision

Viewing changes to trac-files/common/js/trac.js

  • Committer: Jean-Paul Calderone
  • Date: 2011-10-17 17:00:12 UTC
  • Revision ID: exarkun@divmod.com-20111017170012-7k9v28ldkschawad
Initial import from subversion

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(function($){
 
2
  
 
3
  $.fn.addAnchor = function(title) {
 
4
    title = title || "Link here";
 
5
    return this.filter("*[id]").each(function() {
 
6
      $("<a class='anchor'> \u00B6</a>").attr("href", "#" + this.id)
 
7
        .attr("title", title).appendTo(this);
 
8
    });
 
9
  }
 
10
  
 
11
  $.fn.checked = function(checked) {
 
12
    if (checked == undefined) { // getter
 
13
      if (!this.length) return false;
 
14
      return this.get(0).checked;
 
15
    } else { // setter
 
16
      return this.each(function() {
 
17
        this.checked = checked;
 
18
      });
 
19
    }
 
20
  }
 
21
  
 
22
  $.fn.enable = function(enabled) {
 
23
    if (enabled == undefined) enabled = true;
 
24
    return this.each(function() {
 
25
      this.disabled = !enabled;
 
26
      var label = $(this).parents("label");
 
27
      if (!label.length && this.id) {
 
28
        label = $("label[for='" + this.id + "']");
 
29
      }
 
30
      if (!enabled) {
 
31
        label.addClass("disabled");
 
32
      } else {
 
33
        label.removeClass("disabled");
 
34
      }
 
35
    });
 
36
  }
 
37
  
 
38
  $.loadStyleSheet = function(href, type) {
 
39
    type = type || "text/css";
 
40
    $(document).ready(function() {
 
41
      if (document.createStyleSheet) { // MSIE
 
42
        document.createStyleSheet(href);
 
43
      } else {
 
44
        $("<link rel='stylesheet' type='" + type + "' href='" + href + "' />")
 
45
          .appendTo("head");
 
46
      }
 
47
    });
 
48
  }
 
49
  
 
50
  // Used for dynamically updating the height of a textarea
 
51
  window.resizeTextArea = function (id, rows) {
 
52
    var textarea = $("#" + id).get(0);
 
53
    if (!textarea || textarea.rows == undefined) return;
 
54
    textarea.rows = rows;
 
55
  }
 
56
  
 
57
  // The following are defined for backwards compatibility with releases prior
 
58
  // to Trac 0.11
 
59
  
 
60
  window.addEvent = function(elem, type, func) {
 
61
    $(elem).bind(type, func);
 
62
  }
 
63
  window.addHeadingLinks = function(container, title) {
 
64
    $.each(["h1", "h2", "h3", "h4", "h5", "h6"], function() {
 
65
      $(this, container).addAnchor(title);
 
66
    });
 
67
  }
 
68
  window.enableControl = function(id, enabled) {
 
69
    $("#" + id).enable(enabled);
 
70
  }
 
71
  window.getAncestorByTagName = function(elem, tagName) {
 
72
    return $(elem).parents(tagName).get(0);
 
73
  }
 
74
 
 
75
})(jQuery);
 
 
b'\\ No newline at end of file'