bootstrap-tooltip-rails 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in bootstrap-tooltip-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 Brandon Hilkert
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,66 @@
1
+ bootstrap-tooltip-rails Gem
2
+ =======================
3
+
4
+ bootstrap-tooltip-rails is a Ruby Gem that integrates Twitter's Bootstrap Tooltip library within the Rails Asset Pipeline.
5
+
6
+ Installation
7
+ -----
8
+
9
+ Add to Gemfile:
10
+
11
+ gem 'bootstrap-tooltip-rails'
12
+
13
+ Bundle application to install:
14
+
15
+ bundle install
16
+
17
+ Configiration
18
+ ---
19
+
20
+ To add the .js and .css assets to the asset manifest files, run the following:
21
+
22
+ rails g bootstrap:tooltip:install
23
+
24
+ If you prefer to add the assets manually, do the following:
25
+
26
+ add the following to application.js:
27
+
28
+ //= require bootstrap/bootstrap-tooltip
29
+
30
+ add the following to application.css:
31
+
32
+ *= require bootstrap/bootstrap-tooltip
33
+
34
+ Usage
35
+ ---
36
+
37
+ Add the following to the view or global JS include:
38
+
39
+ ```javascript
40
+ $(function(){
41
+ $("a[rel='tooltip']").tooltip();
42
+ })
43
+ ````
44
+
45
+ Additional options can be passed to tooltip() in the form of a hash as documented [here](http://twitter.github.com/bootstrap/javascript.html#tooltips).
46
+
47
+ Add rel and title properties to a link in your view like the following:
48
+
49
+ ```HTML
50
+ <a href="#" rel="tooltip" title="Tooltip message...">Test</a>
51
+ ````
52
+
53
+ Other options can be
54
+
55
+ Requirements
56
+ ----
57
+
58
+ bootstrap-tooltip-rails requires a Rails application with Asset pipeline.
59
+
60
+
61
+ Copyright
62
+ ---
63
+ Copyright (c) 2012 Brandon Hilkert.
64
+ See [LICENSE][] for details.
65
+
66
+ [license]: https://github.com/brandonhilkert/bootstrap-tooltip-rails/blob/master/LICENSE
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "bootstrap/tooltip/rails/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "bootstrap-tooltip-rails"
7
+ s.version = Bootstrap::Tooltip::Rails::VERSION
8
+ s.authors = ["Brandon Hilkert"]
9
+ s.email = ["brandonhilkert@gmail.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{Adds Twitter's Bootstrap Tooltips to Rails}
12
+ s.description = %q{A Ruby Gem that embeds the code necessary to easily use Twitter's Bootstrap Tooltip library within your application.}
13
+
14
+ s.rubyforge_project = "bootstrap-tooltip-rails"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_development_dependency 'bundler'
22
+ s.add_dependency 'thor'
23
+ s.add_dependency 'rails', '>= 3.1'
24
+ end
@@ -0,0 +1,2 @@
1
+ require "bootstrap/tooltip/rails/version"
2
+ require 'bootstrap/tooltip/rails/engine' if defined?(Rails)
@@ -0,0 +1,8 @@
1
+ module Bootstrap
2
+ module Tooltip
3
+ module Rails
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ module Bootstrap
2
+ module Tooltip
3
+ module Rails
4
+ VERSION = "0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ module Bootstrap
2
+ module Tooltip
3
+ module Generators
4
+
5
+ class InstallGenerator < ::Rails::Generators::Base
6
+ desc "This generator installs Bootstrap Tootsip to the Asset Pipeline"
7
+
8
+ def add_assets
9
+ if File.exist?("app/assets/javascripts/application.js")
10
+ insert_into_file "app/assets/javascripts/application.js", "//= require bootstrap/bootstrap-tooltip\n", :after => "jquery_ujs\n"
11
+ end
12
+
13
+ if File.exist?("app/assets/stylesheets/application.css")
14
+ insert_into_file "app/assets/stylesheets/application.css", " *= require bootstrap/bootstrap-tooltip\n", :after => "require_self\n"
15
+ end
16
+ end
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,270 @@
1
+ /* ===========================================================
2
+ * bootstrap-tooltip.js v2.0.0
3
+ * http://twitter.github.com/bootstrap/javascript.html#tooltips
4
+ * Inspired by the original jQuery.tipsy by Jason Frame
5
+ * ===========================================================
6
+ * Copyright 2012 Twitter, Inc.
7
+ *
8
+ * Licensed under the Apache License, Version 2.0 (the "License");
9
+ * you may not use this file except in compliance with the License.
10
+ * You may obtain a copy of the License at
11
+ *
12
+ * http://www.apache.org/licenses/LICENSE-2.0
13
+ *
14
+ * Unless required by applicable law or agreed to in writing, software
15
+ * distributed under the License is distributed on an "AS IS" BASIS,
16
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
+ * See the License for the specific language governing permissions and
18
+ * limitations under the License.
19
+ * ========================================================== */
20
+
21
+ !function( $ ) {
22
+
23
+ "use strict"
24
+
25
+ /* TOOLTIP PUBLIC CLASS DEFINITION
26
+ * =============================== */
27
+
28
+ var Tooltip = function ( element, options ) {
29
+ this.init('tooltip', element, options)
30
+ }
31
+
32
+ Tooltip.prototype = {
33
+
34
+ constructor: Tooltip
35
+
36
+ , init: function ( type, element, options ) {
37
+ var eventIn
38
+ , eventOut
39
+
40
+ this.type = type
41
+ this.$element = $(element)
42
+ this.options = this.getOptions(options)
43
+ this.enabled = true
44
+
45
+ if (this.options.trigger != 'manual') {
46
+ eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
47
+ eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
48
+ this.$element.on(eventIn, this.options.selector, $.proxy(this.enter, this))
49
+ this.$element.on(eventOut, this.options.selector, $.proxy(this.leave, this))
50
+ }
51
+
52
+ this.options.selector ?
53
+ (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
54
+ this.fixTitle()
55
+ }
56
+
57
+ , getOptions: function ( options ) {
58
+ options = $.extend({}, $.fn[this.type].defaults, options, this.$element.data())
59
+
60
+ if (options.delay && typeof options.delay == 'number') {
61
+ options.delay = {
62
+ show: options.delay
63
+ , hide: options.delay
64
+ }
65
+ }
66
+
67
+ return options
68
+ }
69
+
70
+ , enter: function ( e ) {
71
+ var self = $(e.currentTarget)[this.type](this._options).data(this.type)
72
+
73
+ if (!self.options.delay || !self.options.delay.show) {
74
+ self.show()
75
+ } else {
76
+ self.hoverState = 'in'
77
+ setTimeout(function() {
78
+ if (self.hoverState == 'in') {
79
+ self.show()
80
+ }
81
+ }, self.options.delay.show)
82
+ }
83
+ }
84
+
85
+ , leave: function ( e ) {
86
+ var self = $(e.currentTarget)[this.type](this._options).data(this.type)
87
+
88
+ if (!self.options.delay || !self.options.delay.hide) {
89
+ self.hide()
90
+ } else {
91
+ self.hoverState = 'out'
92
+ setTimeout(function() {
93
+ if (self.hoverState == 'out') {
94
+ self.hide()
95
+ }
96
+ }, self.options.delay.hide)
97
+ }
98
+ }
99
+
100
+ , show: function () {
101
+ var $tip
102
+ , inside
103
+ , pos
104
+ , actualWidth
105
+ , actualHeight
106
+ , placement
107
+ , tp
108
+
109
+ if (this.hasContent() && this.enabled) {
110
+ $tip = this.tip()
111
+ this.setContent()
112
+
113
+ if (this.options.animation) {
114
+ $tip.addClass('fade')
115
+ }
116
+
117
+ placement = typeof this.options.placement == 'function' ?
118
+ this.options.placement.call(this, $tip[0], this.$element[0]) :
119
+ this.options.placement
120
+
121
+ inside = /in/.test(placement)
122
+
123
+ $tip
124
+ .remove()
125
+ .css({ top: 0, left: 0, display: 'block' })
126
+ .appendTo(inside ? this.$element : document.body)
127
+
128
+ pos = this.getPosition(inside)
129
+
130
+ actualWidth = $tip[0].offsetWidth
131
+ actualHeight = $tip[0].offsetHeight
132
+
133
+ switch (inside ? placement.split(' ')[1] : placement) {
134
+ case 'bottom':
135
+ tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
136
+ break
137
+ case 'top':
138
+ tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}
139
+ break
140
+ case 'left':
141
+ tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}
142
+ break
143
+ case 'right':
144
+ tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}
145
+ break
146
+ }
147
+
148
+ $tip
149
+ .css(tp)
150
+ .addClass(placement)
151
+ .addClass('in')
152
+ }
153
+ }
154
+
155
+ , setContent: function () {
156
+ var $tip = this.tip()
157
+ $tip.find('.tooltip-inner').html(this.getTitle())
158
+ $tip.removeClass('fade in top bottom left right')
159
+ }
160
+
161
+ , hide: function () {
162
+ var that = this
163
+ , $tip = this.tip()
164
+
165
+ $tip.removeClass('in')
166
+
167
+ function removeWithAnimation() {
168
+ var timeout = setTimeout(function () {
169
+ $tip.off($.support.transition.end).remove()
170
+ }, 500)
171
+
172
+ $tip.one($.support.transition.end, function () {
173
+ clearTimeout(timeout)
174
+ $tip.remove()
175
+ })
176
+ }
177
+
178
+ $.support.transition && this.$tip.hasClass('fade') ?
179
+ removeWithAnimation() :
180
+ $tip.remove()
181
+ }
182
+
183
+ , fixTitle: function () {
184
+ var $e = this.$element
185
+ if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
186
+ $e.attr('data-original-title', $e.attr('title') || '').removeAttr('title')
187
+ }
188
+ }
189
+
190
+ , hasContent: function () {
191
+ return this.getTitle()
192
+ }
193
+
194
+ , getPosition: function (inside) {
195
+ return $.extend({}, (inside ? {top: 0, left: 0} : this.$element.offset()), {
196
+ width: this.$element[0].offsetWidth
197
+ , height: this.$element[0].offsetHeight
198
+ })
199
+ }
200
+
201
+ , getTitle: function () {
202
+ var title
203
+ , $e = this.$element
204
+ , o = this.options
205
+
206
+ title = $e.attr('data-original-title')
207
+ || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
208
+
209
+ title = title.toString().replace(/(^\s*|\s*$)/, "")
210
+
211
+ return title
212
+ }
213
+
214
+ , tip: function () {
215
+ return this.$tip = this.$tip || $(this.options.template)
216
+ }
217
+
218
+ , validate: function () {
219
+ if (!this.$element[0].parentNode) {
220
+ this.hide()
221
+ this.$element = null
222
+ this.options = null
223
+ }
224
+ }
225
+
226
+ , enable: function () {
227
+ this.enabled = true
228
+ }
229
+
230
+ , disable: function () {
231
+ this.enabled = false
232
+ }
233
+
234
+ , toggleEnabled: function () {
235
+ this.enabled = !this.enabled
236
+ }
237
+
238
+ , toggle: function () {
239
+ this[this.tip().hasClass('in') ? 'hide' : 'show']()
240
+ }
241
+
242
+ }
243
+
244
+
245
+ /* TOOLTIP PLUGIN DEFINITION
246
+ * ========================= */
247
+
248
+ $.fn.tooltip = function ( option ) {
249
+ return this.each(function () {
250
+ var $this = $(this)
251
+ , data = $this.data('tooltip')
252
+ , options = typeof option == 'object' && option
253
+ if (!data) $this.data('tooltip', (data = new Tooltip(this, options)))
254
+ if (typeof option == 'string') data[option]()
255
+ })
256
+ }
257
+
258
+ $.fn.tooltip.Constructor = Tooltip
259
+
260
+ $.fn.tooltip.defaults = {
261
+ animation: true
262
+ , delay: 0
263
+ , selector: false
264
+ , placement: 'top'
265
+ , trigger: 'hover'
266
+ , title: ''
267
+ , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
268
+ }
269
+
270
+ }( window.jQuery )
@@ -0,0 +1,85 @@
1
+ .fade {
2
+ -webkit-transition: opacity 0.15s linear;
3
+ -moz-transition: opacity 0.15s linear;
4
+ -ms-transition: opacity 0.15s linear;
5
+ -o-transition: opacity 0.15s linear;
6
+ transition: opacity 0.15s linear;
7
+ opacity: 0;
8
+ }
9
+ .fade.in {
10
+ opacity: 1;
11
+ }
12
+ .tooltip {
13
+ position: absolute;
14
+ z-index: 1020;
15
+ display: block;
16
+ visibility: visible;
17
+ padding: 5px;
18
+ font-size: 11px;
19
+ opacity: 0;
20
+ filter: alpha(opacity=0);
21
+ }
22
+ .tooltip.in {
23
+ opacity: 0.8;
24
+ filter: alpha(opacity=80);
25
+ }
26
+ .tooltip.top {
27
+ margin-top: -2px;
28
+ }
29
+ .tooltip.right {
30
+ margin-left: 2px;
31
+ }
32
+ .tooltip.bottom {
33
+ margin-top: 2px;
34
+ }
35
+ .tooltip.left {
36
+ margin-left: -2px;
37
+ }
38
+ .tooltip.top .tooltip-arrow {
39
+ bottom: 0;
40
+ left: 50%;
41
+ margin-left: -5px;
42
+ border-left: 5px solid transparent;
43
+ border-right: 5px solid transparent;
44
+ border-top: 5px solid #000000;
45
+ }
46
+ .tooltip.left .tooltip-arrow {
47
+ top: 50%;
48
+ right: 0;
49
+ margin-top: -5px;
50
+ border-top: 5px solid transparent;
51
+ border-bottom: 5px solid transparent;
52
+ border-left: 5px solid #000000;
53
+ }
54
+ .tooltip.bottom .tooltip-arrow {
55
+ top: 0;
56
+ left: 50%;
57
+ margin-left: -5px;
58
+ border-left: 5px solid transparent;
59
+ border-right: 5px solid transparent;
60
+ border-bottom: 5px solid #000000;
61
+ }
62
+ .tooltip.right .tooltip-arrow {
63
+ top: 50%;
64
+ left: 0;
65
+ margin-top: -5px;
66
+ border-top: 5px solid transparent;
67
+ border-bottom: 5px solid transparent;
68
+ border-right: 5px solid #000000;
69
+ }
70
+ .tooltip-inner {
71
+ max-width: 200px;
72
+ padding: 3px 8px;
73
+ color: #ffffff;
74
+ text-align: center;
75
+ text-decoration: none;
76
+ background-color: #000000;
77
+ -webkit-border-radius: 4px;
78
+ -moz-border-radius: 4px;
79
+ border-radius: 4px;
80
+ }
81
+ .tooltip-arrow {
82
+ position: absolute;
83
+ width: 0;
84
+ height: 0;
85
+ }
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bootstrap-tooltip-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Brandon Hilkert
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-01 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: &70330909083000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70330909083000
25
+ - !ruby/object:Gem::Dependency
26
+ name: thor
27
+ requirement: &70330909081960 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70330909081960
36
+ - !ruby/object:Gem::Dependency
37
+ name: rails
38
+ requirement: &70330909081240 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '3.1'
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: *70330909081240
47
+ description: A Ruby Gem that embeds the code necessary to easily use Twitter's Bootstrap
48
+ Tooltip library within your application.
49
+ email:
50
+ - brandonhilkert@gmail.com
51
+ executables: []
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE
58
+ - README.md
59
+ - Rakefile
60
+ - bootstrap-tooltip-rails.gemspec
61
+ - lib/bootstrap-tooltip-rails.rb
62
+ - lib/bootstrap/tooltip/rails/engine.rb
63
+ - lib/bootstrap/tooltip/rails/version.rb
64
+ - lib/generators/bootstrap/tooltip/install/install_generator.rb
65
+ - vendor/assets/javascripts/bootstrap/bootstrap-tooltip.js
66
+ - vendor/assets/stylesheets/bootstrap/bootstrap-tooltip.css
67
+ homepage: ''
68
+ licenses: []
69
+ post_install_message:
70
+ rdoc_options: []
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ segments:
80
+ - 0
81
+ hash: -56130364256708744
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ segments:
89
+ - 0
90
+ hash: -56130364256708744
91
+ requirements: []
92
+ rubyforge_project: bootstrap-tooltip-rails
93
+ rubygems_version: 1.8.10
94
+ signing_key:
95
+ specification_version: 3
96
+ summary: Adds Twitter's Bootstrap Tooltips to Rails
97
+ test_files: []