groundworkcss-rails 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/app/helpers/breadcrumbs_helper.rb~ +5 -0
- data/app/helpers/flash_block_helper.rb~ +18 -0
- data/app/helpers/flash_helper.rb~ +21 -0
- data/app/helpers/groundwork_flash_helper.rb~ +21 -0
- data/app/helpers/modal_helper.rb~ +42 -0
- data/app/helpers/social_glyph_helper.rb~ +12 -0
- data/lib/generators/groundworkcss/install/install_generator.rb~ +44 -0
- data/lib/generators/groundworkcss/install/templates/application.css.scss~ +8 -0
- data/lib/generators/groundworkcss/install/templates/application.css~ +7 -0
- data/lib/generators/groundworkcss/install/templates/application.js~ +10 -0
- data/lib/generators/groundworkcss/install/templates/groundwork-and-overrides.scss~ +12 -0
- data/lib/generators/groundworkcss/install/templates/groundwork-overrides.scss~ +7 -0
- data/lib/generators/groundworkcss/install/templates/groundwork.coffee~ +0 -0
- data/lib/generators/groundworkcss/install/templates/groundwork.js~ +1 -0
- data/lib/generators/groundworkcss/layout/layout_generator.rb~ +1 -1
- data/lib/generators/groundworkcss/layout/templates/_header.html.erb~ +24 -0
- data/lib/generators/groundworkcss/layout/templates/_sidebar.html.erb~ +18 -0
- data/lib/generators/groundworkcss/layout/templates/layout.html.erb~ +44 -0
- data/lib/groundworkcss/rails/bootstrap.rb~ +2 -0
- data/lib/groundworkcss/rails/engine.rb~ +30 -0
- data/lib/groundworkcss/rails/version.rb +1 -1
- data/lib/groundworkcss/rails/version.rb~ +1 -1
- data/lib/twitter-bootstrap-rails.rb~ +10 -0
- data/vendor/assets/javascripts/groundwork.js~ +8 -0
- data/vendor/assets/javascripts/groundworkcss/groundwork.js +24 -217
- data/vendor/assets/javascripts/groundworkcss/groundwork.js~ +7 -0
- data/vendor/assets/javascripts/groundworkcss/plugins/jquery.modals.js +1 -1
- data/vendor/assets/javascripts/groundworkcss/plugins/jquery.popover.js +1 -1
- data/vendor/assets/javascripts/groundworkcss/plugins/jquery.responsiveTables.js +1 -1
- data/vendor/assets/javascripts/groundworkcss/plugins/jquery.responsiveText.js +1 -1
- data/vendor/assets/javascripts/groundworkcss/plugins/jquery.tooltip.js +24 -10
- data/vendor/assets/stylesheets/groundworkcss-scss/_buttons.scss +3 -0
- data/vendor/assets/stylesheets/groundworkcss-scss/_classes.scss +149 -0
- data/vendor/assets/stylesheets/groundworkcss-scss/_font-awesome.scss~ +534 -0
- data/vendor/assets/stylesheets/groundworkcss-scss/_grid.scss +46 -366
- data/vendor/assets/stylesheets/groundworkcss-scss/_layout.scss +11 -11
- data/vendor/assets/stylesheets/groundworkcss-scss/_mixins.scss +9 -0
- data/vendor/assets/stylesheets/groundworkcss-scss/_responsive.scss +4 -106
- data/vendor/assets/stylesheets/groundworkcss-scss/_social-icons.scss~ +92 -0
- data/vendor/assets/stylesheets/groundworkcss-scss/_tooltips.scss +5 -5
- data/vendor/assets/stylesheets/groundworkcss-scss/_typography.scss +48 -43
- data/vendor/assets/stylesheets/groundworkcss-scss/_variables.scss +47 -46
- data/vendor/assets/stylesheets/groundworkcss-scss/groundwork.scss +3 -0
- metadata +318 -299
- data/vendor/assets/javascripts/groundworkcss/coffee/groundwork.coffee +0 -207
- data/vendor/assets/javascripts/groundworkcss/coffee/plugins/jquery.modals.coffee +0 -162
- data/vendor/assets/javascripts/groundworkcss/coffee/plugins/jquery.popover.coffee +0 -198
- data/vendor/assets/javascripts/groundworkcss/coffee/plugins/jquery.responsiveTables.coffee +0 -56
- data/vendor/assets/javascripts/groundworkcss/coffee/plugins/jquery.responsiveText.coffee +0 -32
- data/vendor/assets/javascripts/groundworkcss/coffee/plugins/jquery.tooltip.coffee +0 -121
@@ -0,0 +1,18 @@
|
|
1
|
+
module FlashBlockHelper
|
2
|
+
def flash_block
|
3
|
+
output = ''
|
4
|
+
flash.each do |type, message|
|
5
|
+
output += flash_container(type, message)
|
6
|
+
end
|
7
|
+
|
8
|
+
raw(output)
|
9
|
+
end
|
10
|
+
|
11
|
+
def flash_container(type, message)
|
12
|
+
# Types: important, success, warning, error
|
13
|
+
#<p class="warning message">This is a warning message.</p>
|
14
|
+
raw(content_tag(:p, :class => "message #{type}") do
|
15
|
+
message
|
16
|
+
end)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module GroundworkFlashHelper
|
2
|
+
ALERT_TYPES = [:error, :success, :warning]
|
3
|
+
|
4
|
+
def groundwork_flash
|
5
|
+
flash_messages = []
|
6
|
+
flash.each do |type, message|
|
7
|
+
next if message.blank?
|
8
|
+
|
9
|
+
type = :success if type == :notice
|
10
|
+
type = :error if type == :alert
|
11
|
+
next unless ALERT_TYPES.include?(type)
|
12
|
+
|
13
|
+
Array(message).each do |msg|
|
14
|
+
text = content_tag(:p,
|
15
|
+
msg.html_safe, :class => "message #{type}")
|
16
|
+
flash_messages << text if message
|
17
|
+
end
|
18
|
+
end
|
19
|
+
flash_messages.join("\n").html_safe
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module GroundworkFlashHelper
|
2
|
+
ALERT_TYPES = [:error, :success, :warning]
|
3
|
+
|
4
|
+
def bootstrap_flash
|
5
|
+
flash_messages = []
|
6
|
+
flash.each do |type, message|
|
7
|
+
next if message.blank?
|
8
|
+
|
9
|
+
type = :success if type == :notice
|
10
|
+
type = :error if type == :alert
|
11
|
+
next unless ALERT_TYPES.include?(type)
|
12
|
+
|
13
|
+
Array(message).each do |msg|
|
14
|
+
text = content_tag(:p,
|
15
|
+
msg.html_safe, :class => "message #{type}")
|
16
|
+
flash_messages << text if message
|
17
|
+
end
|
18
|
+
end
|
19
|
+
flash_messages.join("\n").html_safe
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module ModalHelper
|
2
|
+
def modal_dialog(options = {}, escape = true, &block)
|
3
|
+
default_options = {:class => "bootstrap-modal modal"}
|
4
|
+
content_tag :div, nil, options.merge(default_options), escape, &block
|
5
|
+
end
|
6
|
+
|
7
|
+
def modal_header(options = {}, escape = true, &block)
|
8
|
+
default_options = {:class => 'modal-header'}
|
9
|
+
content_tag :div, nil, options.merge(default_options), escape do
|
10
|
+
raw("<button class=\"close\" data-dismiss=\"modal\">×</button>" + capture(&block))
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def modal_body(options = {}, escape = true, &block)
|
15
|
+
default_options = {:class => 'modal-body'}
|
16
|
+
content_tag :div, nil, options.merge(default_options), escape, &block
|
17
|
+
end
|
18
|
+
|
19
|
+
def modal_footer(options = {}, escape = true, &block)
|
20
|
+
default_options = {:class => 'modal-footer'}
|
21
|
+
content_tag :div, nil, options.merge(default_options), escape, &block
|
22
|
+
end
|
23
|
+
|
24
|
+
def modal_toggle(content_or_options = nil, options = {}, &block)
|
25
|
+
if block_given?
|
26
|
+
options = content_or_options if content_or_options.is_a?(Hash)
|
27
|
+
default_options = {:class => 'btn', "data-toggle" => "modal", "href" => options[:dialog]}.merge(options)
|
28
|
+
|
29
|
+
content_tag :a, nil, default_options, true, &block
|
30
|
+
else
|
31
|
+
default_options = {:class => 'btn', "data-toggle" => "modal", "href" => options[:dialog]}.merge(options)
|
32
|
+
content_tag :a, content_or_options, default_options, true
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def modal_cancel_button content, options = {}
|
37
|
+
default_options = {:class => "btn bootstrap-modal-cancel-button"}
|
38
|
+
|
39
|
+
content_tag_string "a", content, default_options.merge(options)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module SocialGlyphHelper
|
2
|
+
# ==== Examples
|
3
|
+
# social_glyph(:dropbox, :large)
|
4
|
+
# # => <i class="social-icon dropbox large"></i>
|
5
|
+
# social_glyph(:dropbox)
|
6
|
+
# # => <i class="social-icon dropbox"></i>
|
7
|
+
|
8
|
+
def social_glyph(icon, size)
|
9
|
+
content_tag :i, nil, :class => "social-icon #{icon} #{size unless size.nil?}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module Groundworkcss
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < ::Rails::Generators::Base
|
6
|
+
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
8
|
+
desc "This generator installs GroundworkCSS to Asset Pipeline"
|
9
|
+
argument :stylesheets_type, :type => :string, :default => 'less', :banner => '*less or static'
|
10
|
+
|
11
|
+
def add_assets
|
12
|
+
|
13
|
+
if File.exist?('app/assets/javascripts/application.js')
|
14
|
+
insert_into_file "app/assets/javascripts/application.js", "//= require groundwork\n", :after => "jquery_ujs\n"
|
15
|
+
else
|
16
|
+
copy_file "application.js", "app/assets/javascripts/application.js"
|
17
|
+
end
|
18
|
+
|
19
|
+
if File.exist?('app/assets/stylesheets/application.css')
|
20
|
+
style_require_block = " *= require groundwork-and-overrides\n"
|
21
|
+
insert_into_file "app/assets/stylesheets/application.css", style_require_block, :after => "require_self\n"
|
22
|
+
else
|
23
|
+
copy_file "application.css", "app/assets/stylesheets/application.css"
|
24
|
+
end
|
25
|
+
|
26
|
+
copy_file "groundwork-and-overrides.scss", "app/assets/stylesheets/groundwork-and-overrides.scss"
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
def add_javascript
|
31
|
+
if use_coffeescript?
|
32
|
+
copy_file "groundwork.coffee", "app/assets/javascripts/groundwork.js.coffee"
|
33
|
+
else
|
34
|
+
copy_file "groundwork.js", "app/assets/javascripts/groundwork.js"
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def use_coffeescript?
|
40
|
+
::Rails.configuration.app_generators.rails[:javascript_engine] == :coffee
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require_self
|
6
|
+
*= require groundworkscss/groundwork
|
7
|
+
*= require_tree .
|
8
|
+
*/
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require_self
|
6
|
+
*= require_tree .
|
7
|
+
*/
|
@@ -0,0 +1,10 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require twitter/bootstrap
|
10
|
+
//= require_tree .
|
@@ -0,0 +1,12 @@
|
|
1
|
+
$socialPath: "../assets/groundworkcss/social-icons" !default;
|
2
|
+
$fontAwesomePath: "../assets/groundworkcss" !default;
|
3
|
+
|
4
|
+
@import "groundworkcss-scss/groundwork";
|
5
|
+
|
6
|
+
body {
|
7
|
+
background: url("pw_maze_white.png");
|
8
|
+
}
|
9
|
+
|
10
|
+
header{
|
11
|
+
background: white;
|
12
|
+
}
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -14,7 +14,7 @@ module Groundworkcss
|
|
14
14
|
ext = app.config.generators.options[:rails][:template_engine] || :erb
|
15
15
|
template "layout.html.#{ext}", "app/views/layouts/#{layout_name}.html.#{ext}"
|
16
16
|
copy_file "_sidebar.html.#{ext}", "app/views/layouts/_sidebar.html.#{ext}"
|
17
|
-
copy_file "_header.html.#{ext}", "app/views/layouts/
|
17
|
+
copy_file "_header.html.#{ext}", "app/views/layouts/_sidebar.html.#{ext}"
|
18
18
|
end
|
19
19
|
end
|
20
20
|
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<header class="white band padded">
|
2
|
+
<div class="container pad-top">
|
3
|
+
<div class="row">
|
4
|
+
<div class="one third padded">
|
5
|
+
|
6
|
+
<h1 class="responsive">
|
7
|
+
<a href="#">
|
8
|
+
<%= ::Rails.application.class.to_s.split("::").first %>
|
9
|
+
</a>
|
10
|
+
</h1>
|
11
|
+
|
12
|
+
</div>
|
13
|
+
<div class="two thirds padded">
|
14
|
+
<nav class="inline pull-right pad-top">
|
15
|
+
<ul>
|
16
|
+
<li><a href="#">Link 1</a></li>
|
17
|
+
<li><a href="#">Link 2</a></li>
|
18
|
+
<li><a href="#">Link 3</a></li>
|
19
|
+
</ul>
|
20
|
+
</nav>
|
21
|
+
</div>
|
22
|
+
</div>
|
23
|
+
</div>
|
24
|
+
</header>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<% if content_for?(:nav) || content_for?(:sidebar)%>
|
2
|
+
<aside class="one fifth padded border-right">
|
3
|
+
<% if content_for? :nav %>
|
4
|
+
<h3>Navigation</h3>
|
5
|
+
<nav>
|
6
|
+
<ul>
|
7
|
+
<%= yield :nav%>
|
8
|
+
</ul>
|
9
|
+
</nav>
|
10
|
+
<%end%>
|
11
|
+
|
12
|
+
<br/>
|
13
|
+
|
14
|
+
<% if content_for? :sidebar%>
|
15
|
+
<%= yield :sidebar%>
|
16
|
+
<%end%>
|
17
|
+
</aside>
|
18
|
+
<%end%>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<!doctype html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<meta charset="utf-8">
|
5
|
+
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
|
6
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
|
7
|
+
<title><%%= content_for?(:title) ? yield(:title) : "<%= app_name %>" %></title>
|
8
|
+
<%%= csrf_meta_tags %>
|
9
|
+
|
10
|
+
<!-- Le HTML5 shim, for IE6-8 support of HTML elements -->
|
11
|
+
<!--[if lt IE 9]>
|
12
|
+
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.6.1/html5shiv.js" type="text/javascript"></script>
|
13
|
+
<![endif]-->
|
14
|
+
<%%= stylesheet_link_tag "application", :media => "all" %>
|
15
|
+
</head>
|
16
|
+
<body>
|
17
|
+
|
18
|
+
<%%= render :partial => "layouts/header"%>
|
19
|
+
|
20
|
+
<div class="container">
|
21
|
+
<div class="row">
|
22
|
+
<%%= render :partial => "layouts/sidebar"%>
|
23
|
+
|
24
|
+
<section class="
|
25
|
+
<%%if content_for?(:sidebar) || content_for?(:nav)%>
|
26
|
+
four fifths
|
27
|
+
<%%end%>
|
28
|
+
padded">
|
29
|
+
|
30
|
+
<%%= groundwork_flash %>
|
31
|
+
|
32
|
+
<%%= yield %>
|
33
|
+
|
34
|
+
</section>
|
35
|
+
</div>
|
36
|
+
|
37
|
+
<footer class="footer align-center">
|
38
|
+
<p>© Company 2013</p>
|
39
|
+
</footer>
|
40
|
+
|
41
|
+
</div> <!-- /container -->
|
42
|
+
<%%= javascript_include_tag "application" %>
|
43
|
+
</body>
|
44
|
+
</html>
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../../../app/helpers/flash_block_helper.rb'
|
4
|
+
require File.dirname(__FILE__) + '/../../../app/helpers/glyph_helper.rb'
|
5
|
+
require File.dirname(__FILE__) + '/../../../app/helpers/social_glyph_helper.rb'
|
6
|
+
|
7
|
+
module Groundworkcss
|
8
|
+
module Rails
|
9
|
+
class Engine < ::Rails::Engine
|
10
|
+
initializer 'groundworkcss-rails.setup',
|
11
|
+
:after => 'less-rails.after.load_config_initializers',
|
12
|
+
:group => :all do |app|
|
13
|
+
if defined?(Less)
|
14
|
+
app.config.less.paths << File.join(config.root, 'vendor', 'toolkit')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
initializer 'groundworkcss-rails.setup_helpers' do |app|
|
19
|
+
app.config.to_prepare do
|
20
|
+
ActionController::Base.send :include, BreadCrumbs
|
21
|
+
ActionController::Base.send :helper, FlashBlockHelper
|
22
|
+
ActionController::Base.send :helper, ModalHelper
|
23
|
+
ActionController::Base.send :helper, GlyphHelper
|
24
|
+
ActionController::Base.send :helper, SocialGlyphHelper
|
25
|
+
#ActionController::Base.send :helper_method, :render_breadcrumbs
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
//= require_tree ./libs
|
2
|
+
//= require ./plugins/jquery.modals.js
|
3
|
+
//= require ./plugins/jquery.orbit-1.4.0.js
|
4
|
+
//= require ./plugins/jquery.popover.js
|
5
|
+
//= require ./plugins/jquery.responsiveTables.js
|
6
|
+
//= require ./plugins/jquery.responsiveText.js
|
7
|
+
//= require ./plugins/jquery.tooltip.js
|
8
|
+
//= require ./groundwork_ujs.js
|
@@ -1,4 +1,4 @@
|
|
1
|
-
// Generated by CoffeeScript 1.
|
1
|
+
// Generated by CoffeeScript 1.6.1
|
2
2
|
|
3
3
|
/*
|
4
4
|
*
|
@@ -241,7 +241,7 @@
|
|
241
241
|
|
242
242
|
(function($) {
|
243
243
|
return $.fn.tooltip = function(options) {
|
244
|
-
var closetooltip, defaults, delayShow, getElementPosition, setPosition, showtooltip, tooltip, trigger;
|
244
|
+
var closetooltip, defaults, delayShow, getElementPosition, resettooltip, setPosition, showtooltip, tooltip, trigger;
|
245
245
|
defaults = {
|
246
246
|
topOffset: 0,
|
247
247
|
delay: 100,
|
@@ -251,6 +251,10 @@
|
|
251
251
|
tooltip = $('#tooltip');
|
252
252
|
delayShow = '';
|
253
253
|
trigger = '';
|
254
|
+
if ($('#tooltip').length !== 1) {
|
255
|
+
tooltip = $("<div id=\"tooltip\"></div>");
|
256
|
+
tooltip.appendTo("body").hide();
|
257
|
+
}
|
254
258
|
getElementPosition = function(el) {
|
255
259
|
var bottom, left, offset, right, top, win;
|
256
260
|
offset = el.offset();
|
@@ -288,22 +292,32 @@
|
|
288
292
|
}
|
289
293
|
return tooltip.css(attrs);
|
290
294
|
};
|
295
|
+
resettooltip = function() {
|
296
|
+
return tooltip.text('').removeClass('left right top bottom').css({
|
297
|
+
left: 'auto',
|
298
|
+
right: 'auto',
|
299
|
+
top: 'auto',
|
300
|
+
bottom: 'auto',
|
301
|
+
width: 'auto',
|
302
|
+
'padding-left': 'auto',
|
303
|
+
'padding-right': 'auto'
|
304
|
+
});
|
305
|
+
};
|
291
306
|
closetooltip = function() {
|
292
|
-
tooltip.stop().
|
307
|
+
tooltip.stop().hide();
|
308
|
+
resettooltip();
|
293
309
|
return $('[role=tooltip]').removeClass('on');
|
294
310
|
};
|
295
311
|
showtooltip = function(trigger) {
|
296
|
-
closetooltip();
|
297
312
|
clearTimeout(delayShow);
|
298
313
|
return delayShow = setTimeout(function() {
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
}
|
304
|
-
tooltip.css("opacity", 0).text(trigger.attr('data-title'));
|
314
|
+
tooltip.css({
|
315
|
+
"opacity": 0,
|
316
|
+
"display": "block"
|
317
|
+
}).text(trigger.attr('data-title'));
|
305
318
|
setPosition(trigger);
|
306
319
|
trigger.addClass('on');
|
320
|
+
console.log(tooltip.css('display'));
|
307
321
|
return tooltip.animate({
|
308
322
|
top: "+=10",
|
309
323
|
opacity: 1
|
@@ -341,213 +355,6 @@
|
|
341
355
|
};
|
342
356
|
})(jQuery);
|
343
357
|
|
344
|
-
/* --------------------------------------------
|
345
|
-
Begin jquery.popover.coffee
|
346
|
-
--------------------------------------------
|
347
|
-
*/
|
348
|
-
|
349
|
-
|
350
|
-
/*
|
351
|
-
*
|
352
|
-
* jQuery Popovers by Gary Hepting - https://github.com/ghepting/jquery-popovers
|
353
|
-
*
|
354
|
-
* Open source under the BSD License.
|
355
|
-
*
|
356
|
-
* Copyright © 2013 Gary Hepting. All rights reserved.
|
357
|
-
*
|
358
|
-
*/
|
359
|
-
|
360
|
-
|
361
|
-
(function($) {
|
362
|
-
return $.fn.popover = function(options) {
|
363
|
-
var closePopover, defaults, delayAdjust, delayHide, getElementPosition, popover, resetPopover, setPosition, showPopover, trigger;
|
364
|
-
defaults = {
|
365
|
-
hover: false,
|
366
|
-
click: true,
|
367
|
-
resize: true,
|
368
|
-
scroll: true,
|
369
|
-
topOffset: 0,
|
370
|
-
delay: 500,
|
371
|
-
speed: 100
|
372
|
-
};
|
373
|
-
options = $.extend(defaults, options);
|
374
|
-
popover = $('#popover');
|
375
|
-
delayHide = '';
|
376
|
-
delayAdjust = '';
|
377
|
-
trigger = '';
|
378
|
-
getElementPosition = function(el) {
|
379
|
-
var bottom, left, offset, right, top, win;
|
380
|
-
offset = el.offset();
|
381
|
-
win = $(window);
|
382
|
-
return {
|
383
|
-
top: top = offset.top - win.scrollTop(),
|
384
|
-
left: left = offset.left - win.scrollLeft(),
|
385
|
-
bottom: bottom = win.height() - top - el.outerHeight(),
|
386
|
-
right: right = win.width() - left - el.outerWidth()
|
387
|
-
};
|
388
|
-
};
|
389
|
-
resetPopover = function(resize) {
|
390
|
-
popover.css({
|
391
|
-
top: 'auto',
|
392
|
-
right: 'auto',
|
393
|
-
bottom: 'auto',
|
394
|
-
left: 'auto'
|
395
|
-
});
|
396
|
-
if (resize) {
|
397
|
-
popover.css({
|
398
|
-
width: 'auto'
|
399
|
-
});
|
400
|
-
}
|
401
|
-
popover.removeClass('top');
|
402
|
-
popover.removeClass('right');
|
403
|
-
popover.removeClass('bottom');
|
404
|
-
return popover.removeClass('left');
|
405
|
-
};
|
406
|
-
setPosition = function(trigger, skipAnimation, resize) {
|
407
|
-
var attrs, coords, height, width;
|
408
|
-
if (trigger) {
|
409
|
-
if (resize) {
|
410
|
-
resetPopover(true);
|
411
|
-
} else {
|
412
|
-
resetPopover();
|
413
|
-
}
|
414
|
-
coords = getElementPosition(trigger);
|
415
|
-
if (popover.outerWidth() > ($(window).width() - 20)) {
|
416
|
-
popover.css('width', $(window).width() - 20);
|
417
|
-
}
|
418
|
-
popover.css('max-width', Math.min($(window).width() - parseInt($('body').css('padding-left')) - parseInt($('body').css('padding-right')), parseInt(popover.css('max-width'))));
|
419
|
-
width = popover.outerWidth();
|
420
|
-
height = popover.outerHeight();
|
421
|
-
attrs = {};
|
422
|
-
if (coords.left <= coords.right) {
|
423
|
-
popover.addClass('left');
|
424
|
-
attrs.left = coords.left;
|
425
|
-
} else {
|
426
|
-
popover.addClass('right');
|
427
|
-
attrs.right = coords.right;
|
428
|
-
}
|
429
|
-
if ((coords.top - options.topOffset) > (height + 20)) {
|
430
|
-
popover.addClass('top');
|
431
|
-
attrs.top = trigger.offset().top - height - 20;
|
432
|
-
} else {
|
433
|
-
popover.addClass('bottom');
|
434
|
-
attrs.top = trigger.offset().top + 15;
|
435
|
-
}
|
436
|
-
popover.css(attrs);
|
437
|
-
if (skipAnimation) {
|
438
|
-
return popover.css({
|
439
|
-
top: '+=10'
|
440
|
-
});
|
441
|
-
}
|
442
|
-
}
|
443
|
-
};
|
444
|
-
closePopover = function() {
|
445
|
-
$('.popover-trigger').removeClass('popover-trigger');
|
446
|
-
return popover.removeClass('sticky').remove();
|
447
|
-
};
|
448
|
-
showPopover = function(e) {
|
449
|
-
var tip;
|
450
|
-
trigger = $(e.target);
|
451
|
-
if (!trigger.hasClass('popover-trigger')) {
|
452
|
-
closePopover();
|
453
|
-
trigger.addClass('popover-trigger');
|
454
|
-
}
|
455
|
-
tip = $('#' + trigger.attr('data-content')).html();
|
456
|
-
popover = $("<div id=\"popover\"></div>");
|
457
|
-
if (!tip || tip === "") {
|
458
|
-
return false;
|
459
|
-
}
|
460
|
-
trigger.removeAttr("title");
|
461
|
-
popover.css("opacity", 0).html(tip).appendTo("body");
|
462
|
-
setPosition(trigger);
|
463
|
-
popover.animate({
|
464
|
-
top: "+=10",
|
465
|
-
opacity: 1
|
466
|
-
}, options.speed);
|
467
|
-
popover.bind("click", function(e) {
|
468
|
-
if (e.target.tagName !== 'a') {
|
469
|
-
popover.addClass('sticky');
|
470
|
-
e.stopPropagation();
|
471
|
-
e.preventDefault();
|
472
|
-
return false;
|
473
|
-
}
|
474
|
-
});
|
475
|
-
popover.find('.close').bind("click", function(e) {
|
476
|
-
$('.popover-trigger').removeClass('popover-trigger');
|
477
|
-
popover.removeClass('sticky').remove();
|
478
|
-
e.stopPropagation();
|
479
|
-
e.preventDefault();
|
480
|
-
return false;
|
481
|
-
});
|
482
|
-
return popover.bind({
|
483
|
-
mouseenter: function() {
|
484
|
-
return clearTimeout(delayHide);
|
485
|
-
},
|
486
|
-
mouseleave: function() {
|
487
|
-
if (!popover.hasClass('sticky')) {
|
488
|
-
return delayHide = setTimeout((function() {
|
489
|
-
$('.popover-trigger').removeClass('popover-trigger');
|
490
|
-
return popover.removeClass('sticky').remove();
|
491
|
-
}), 500);
|
492
|
-
}
|
493
|
-
}
|
494
|
-
});
|
495
|
-
};
|
496
|
-
return this.each(function() {
|
497
|
-
var $this;
|
498
|
-
$this = $(this);
|
499
|
-
if (options.hover) {
|
500
|
-
$this.bind({
|
501
|
-
mouseenter: function(e) {
|
502
|
-
trigger = $(e.target);
|
503
|
-
clearTimeout(delayHide);
|
504
|
-
if (!$this.hasClass('popover-trigger') && !popover.hasClass('sticky')) {
|
505
|
-
return showPopover(e);
|
506
|
-
}
|
507
|
-
},
|
508
|
-
mouseleave: function() {
|
509
|
-
if (!popover.hasClass('sticky')) {
|
510
|
-
return delayHide = setTimeout(function() {
|
511
|
-
return closePopover();
|
512
|
-
}, options.delay);
|
513
|
-
}
|
514
|
-
}
|
515
|
-
});
|
516
|
-
}
|
517
|
-
if (options.click) {
|
518
|
-
$this.bind("click", function(e) {
|
519
|
-
trigger = $(e.target);
|
520
|
-
if (!trigger.hasClass('popover-trigger')) {
|
521
|
-
closePopover();
|
522
|
-
showPopover(e);
|
523
|
-
}
|
524
|
-
popover.addClass('sticky');
|
525
|
-
e.preventDefault();
|
526
|
-
e.stopPropagation();
|
527
|
-
return false;
|
528
|
-
});
|
529
|
-
}
|
530
|
-
if (options.resize) {
|
531
|
-
$(window).resize(function() {
|
532
|
-
clearTimeout(delayAdjust);
|
533
|
-
return delayAdjust = setTimeout(function() {
|
534
|
-
return setPosition(trigger, true, true);
|
535
|
-
}, 100);
|
536
|
-
});
|
537
|
-
}
|
538
|
-
if (options.scroll) {
|
539
|
-
$(window).scroll(function() {
|
540
|
-
return setPosition(trigger, true);
|
541
|
-
});
|
542
|
-
}
|
543
|
-
return $('html, body').bind("click", function(e) {
|
544
|
-
$('.popover-trigger').removeClass('popover-trigger');
|
545
|
-
return popover.removeClass('sticky').remove();
|
546
|
-
});
|
547
|
-
});
|
548
|
-
};
|
549
|
-
})(jQuery);
|
550
|
-
|
551
358
|
/* --------------------------------------------
|
552
359
|
Begin jquery.responsiveText.coffee
|
553
360
|
--------------------------------------------
|