application.js 3.5 KB
Newer Older
Jacob Thornton's avatar
Jacob Thornton committed
1
$(document).ready(function(){
2

Jacob Thornton's avatar
Jacob Thornton committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  // scroll spy logic
  // ================

  var activeTarget,
      $window = $(window),
      position = {},
      nav = $('body > .topbar li a'),
      targets = nav.map(function () {
        return $(this).attr('href');
      }),
      offsets = $.map(targets, function (id) {
        return $(id).offset().top;
      });


  function setButton(id) {
    nav.parent("li").removeClass('active');
    $(nav[$.inArray(id, targets)]).parent("li").addClass('active');
  }

  function processScroll(e) {
    var scrollTop = $window.scrollTop() + 10, i;
    for (i = offsets.length; i--;) {
      if (activeTarget != targets[i] && scrollTop >= offsets[i] && (!offsets[i + 1] || scrollTop <= offsets[i + 1])) {
        activeTarget = targets[i];
        setButton(activeTarget);
      }
    }
  }

  nav.click(function () {
    processScroll();
  });

  processScroll();

  $window.scroll(processScroll);


  // Dropdown example for topbar nav
  // ===============================

Jacob Thornton's avatar
Jacob Thornton committed
45
46
47
48
  $("body").bind("click", function(e) {
    $("ul.menu-dropdown").hide();
    $('a.menu').parent("li").removeClass("open").children("ul.menu-dropdown").hide();
  });
Jacob Thornton's avatar
Jacob Thornton committed
49

Jacob Thornton's avatar
Jacob Thornton committed
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
  $("a.menu").click(function(e) {
    var $target = $(this);
    var $parent = $target.parent("li");
    var $siblings = $target.siblings("ul.menu-dropdown");
    var $parentSiblings = $parent.siblings("li");
    if ($parent.hasClass("open")) {
      $parent.removeClass("open");
      $siblings.hide();
    } else {
      $parent.addClass("open");
      $siblings.show();
    }
    $parentSiblings.children("ul.menu-dropdown").hide();
    $parentSiblings.removeClass("open");
    return false;
  });
66

Jacob Thornton's avatar
Jacob Thornton committed
67

68
  // table sort example
Jacob Thornton's avatar
Jacob Thornton committed
69
70
  // ==================

71
72
  $("#sortTableExample").tablesorter( {sortList: [[1,0]]} );

Jacob Thornton's avatar
Jacob Thornton committed
73
74
75
76

  // add on logic
  // ============

77
78
79
80
81
82
83
  $('.add-on :checkbox').click(function() {
    if ($(this).attr('checked')) {
      $(this).parents('.add-on').addClass('active');
    } else {
      $(this).parents('.add-on').removeClass('active');
    }
  });
Jacob Thornton's avatar
Jacob Thornton committed
84

Jacob Thornton's avatar
Jacob Thornton committed
85

86
  // Disable certain links in docs
Jacob Thornton's avatar
Jacob Thornton committed
87
88
  // =============================

89
  $('ul.tabs a, ul.pills a, .pagination a, .well .btn, .actions .btn, .alert-message .btn, a.close').click(function(e) {
90
91
    e.preventDefault();
  });
92

93
94
95
96
97
98
99
100
101
  // Copy code blocks in docs
  $(".copy-code").focus(function() {
    $(this).select();
  });
  $(".copy-code").mouseup(function(e) {
    e.preventDefault();
  });


Jacob Thornton's avatar
Jacob Thornton committed
102
103
  // POSITION TWIPSIES
  // =================
104

Jacob Thornton's avatar
Jacob Thornton committed
105
106
107
108
  $('.twipsies.well a').each(function () {
    var type = this.title
      , $anchor = $(this)
      , $twipsy = $('.twipsy.' + type)
109

Jacob Thornton's avatar
Jacob Thornton committed
110
111
112
113
      , twipsy = {
          width: $twipsy.width() + 10
        , height: $twipsy.height() + 10
        }
114

Jacob Thornton's avatar
Jacob Thornton committed
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
      , anchor = {
          position: $anchor.position()
        , width: $anchor.width()
        , height: $anchor.height()
        }

      , offset = {
          above: {
            top: anchor.position.top - twipsy.height
          , left: anchor.position.left + (anchor.width/2) - (twipsy.width/2)
          }
        , below: {
            top: anchor.position.top + anchor.height
          , left: anchor.position.left + (anchor.width/2) - (twipsy.width/2)
          }
        , left: {
            top: anchor.position.top + (anchor.height/2) - (twipsy.height/2)
          , left: anchor.position.left - twipsy.width - 5
          }
        , right: {
            top: anchor.position.top + (anchor.height/2) - (twipsy.height/2)
          , left: anchor.position.left + anchor.width + 5
          }
138
139
      }

Jacob Thornton's avatar
Jacob Thornton committed
140
    $twipsy.css(offset[type])
141

Jacob Thornton's avatar
Jacob Thornton committed
142
  });
143

Jacob Thornton's avatar
Jacob Thornton committed
144
});