the_role 1.7.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. data/.travis.yml +5 -0
  2. data/README.md +139 -114
  3. data/app/assets/stylesheets/the_role.css.scss +47 -0
  4. data/app/controllers/admin/role_sections_controller.rb +8 -6
  5. data/app/controllers/admin/roles_controller.rb +9 -6
  6. data/app/controllers/the_role_controller.rb +18 -0
  7. data/app/models/concerns/role_model.rb +124 -0
  8. data/app/models/concerns/the_role_base.rb +30 -0
  9. data/app/models/concerns/the_role_user_model.rb +45 -0
  10. data/app/views/admin/roles/_role.html.haml +54 -53
  11. data/app/views/admin/roles/_sidebar.html.haml +4 -1
  12. data/app/views/admin/roles/edit.html.haml +2 -2
  13. data/app/views/admin/roles/index.haml +2 -2
  14. data/app/views/admin/roles/new.html.haml +18 -17
  15. data/lib/generators/the_role/USAGE +19 -0
  16. data/lib/generators/the_role/templates/the_role.rb +5 -0
  17. data/lib/generators/the_role/the_role_generator.rb +23 -0
  18. data/lib/the_role/config.rb +20 -0
  19. data/lib/the_role/hash.rb +23 -30
  20. data/lib/the_role/param_helper.rb +5 -11
  21. data/lib/the_role/version.rb +1 -1
  22. data/lib/the_role.rb +15 -14
  23. data/the_role.gemspec +2 -2
  24. metadata +20 -18
  25. data/app/assets/javascripts/admin_the_role.js +0 -4
  26. data/app/assets/javascripts/bootstrap-alert.js +0 -90
  27. data/app/assets/javascripts/bootstrap-dropdown.js +0 -100
  28. data/app/assets/stylesheets/admin_the_role.css +0 -6
  29. data/app/assets/stylesheets/custom.css +0 -3
  30. data/app/assets/stylesheets/headers.css +0 -12
  31. data/app/assets/stylesheets/reset.css +0 -117
  32. data/app/assets/stylesheets/role_base.css +0 -1739
  33. data/lib/the_role/engine.rb +0 -16
  34. data/lib/the_role/modules/base.rb +0 -30
  35. data/lib/the_role/modules/controller_requires.rb +0 -17
  36. data/lib/the_role/modules/role_model.rb +0 -121
  37. data/lib/the_role/modules/user_model.rb +0 -31
@@ -0,0 +1,45 @@
1
+ module TheRoleUserModel
2
+ extend ActiveSupport::Concern
3
+
4
+ include TheRoleBase
5
+
6
+ included do
7
+ belongs_to :role
8
+ before_validation :set_default_role, on: :create
9
+ after_save { |user| user.instance_variable_set(:@role_hash, nil) }
10
+ end
11
+
12
+ module ClassMethods
13
+ def with_role name
14
+ Role.where(name: name).first.users
15
+ end
16
+ end
17
+
18
+ def role_hash; @role_hash ||= role.try(:to_hash) || {} end
19
+
20
+ # FALSE if object is nil
21
+ # If object is a USER - check for youself
22
+ # Check for owner field - :user_id
23
+ # Check for owner _object_ if owner field is not :user_id
24
+ def owner? obj
25
+ return false unless obj
26
+ return true if admin?
27
+
28
+ section_name = obj.class.to_s.tableize
29
+ return true if moderator?(section_name)
30
+
31
+ return id == obj.id if obj.is_a?(User)
32
+ return id == obj[:user_id] if obj[:user_id]
33
+ return id == obj[:user][:id] if obj[:user]
34
+ false
35
+ end
36
+
37
+ private
38
+
39
+ def set_default_role
40
+ unless role
41
+ default_role = Role.where(name: TheRole.config.default_user_role).first
42
+ self.role = default_role if default_role
43
+ end
44
+ end
45
+ end
@@ -1,53 +1,54 @@
1
- .well
2
- %h3
3
- %b= t '.role_name'
4
- = role.name
5
-
6
- %h5
7
- %b= t '.title'
8
- = role.title
9
-
10
- %p.description
11
- %b= t '.role_description'
12
- = role.description
13
-
14
- - role.to_hash.each_pair do |section, rules|
15
- .section
16
- %h3= section
17
- .delete
18
- .btn-group
19
- = button_to t('.delete_section'), admin_role_section_path(role, section), :method => :delete, :class => 'btn btn-danger', :confirm => t('.section_delete_confirm')
20
-
21
- - rules.each_pair do |rule, value|
22
- .rule
23
- %h4
24
- →
25
- = rule
26
- .controls
27
- .btn-group
28
- - klass = value ? :success : :info
29
- - state = value ? t('.enable') : t('.disable')
30
- %button{ :class => "btn btn-#{klass}" }= state
31
- %button{ :class => "btn btn-#{klass} dropdown-toggle", 'data-toggle' => :dropdown }
32
- %span.caret
33
- %ul.dropdown-menu
34
- %li.success= link_to t('.enable'), rule_on_admin_role_section_path(role, section, :name => rule), :method => :put
35
- %li.info= link_to t('.disable'), rule_off_admin_role_section_path(role, section, :name => rule), :method => :put
36
- %li.divider
37
- %li.error= link_to t('.delete_rule'), destroy_rule_admin_role_section_path(role, section, :name => rule), :method => :delete, :confirm => t('.rule_delete_confirm')
38
-
39
- %h4= t '.create_section'
40
-
41
- = form_tag admin_role_sections_path(role), :class => 'well form-inline' do |f|
42
- = text_field_tag :section_name, '', :class => 'input-xlarge', :placeholder => t('.new_section_placeholder')
43
- = submit_tag t('.create_section'), :class => :btn
44
-
45
- %h4= t '.create_rule'
46
-
47
- = form_tag create_rule_admin_role_sections_path(role), :class => 'well form-inline' do |f|
48
- %select.span3{ :name => :section_name }
49
- - role.to_hash.each_pair do |section, rules|
50
- %option{ :value => section }= section
51
-
52
- = text_field_tag :rule_name, '', :class => 'input-large', :placeholder => t('.new_rule_placeholder')
53
- = submit_tag t('.create_rule'), :class => :btn
1
+ - content_for :role_main do
2
+ .well
3
+ %h3
4
+ %b= t '.role_name'
5
+ = role.name
6
+
7
+ %h5
8
+ %b= t '.title'
9
+ = role.title
10
+
11
+ %p.description
12
+ %b= t '.role_description'
13
+ = role.description
14
+
15
+ - role.to_hash.each_pair do |section, rules|
16
+ .section
17
+ %h3= section
18
+ .delete
19
+ .btn-group
20
+ = button_to t('.delete_section'), admin_role_section_path(role, section), :method => :delete, :class => 'btn btn-danger', :confirm => t('.section_delete_confirm')
21
+
22
+ - rules.each_pair do |rule, value|
23
+ .rule
24
+ %h4
25
+ →
26
+ = rule
27
+ .controls
28
+ .btn-group
29
+ - klass = value ? :success : :info
30
+ - state = value ? t('.enable') : t('.disable')
31
+ %button{ :class => "btn btn-#{klass}" }= state
32
+ %button{ :class => "btn btn-#{klass} dropdown-toggle", 'data-toggle' => :dropdown }
33
+ %span.caret
34
+ %ul.dropdown-menu
35
+ %li.success= link_to t('.enable'), rule_on_admin_role_section_path(role, section, :name => rule), :method => :put
36
+ %li.info= link_to t('.disable'), rule_off_admin_role_section_path(role, section, :name => rule), :method => :put
37
+ %li.divider
38
+ %li.error= link_to t('.delete_rule'), destroy_rule_admin_role_section_path(role, section, :name => rule), :method => :delete, :confirm => t('.rule_delete_confirm')
39
+
40
+ %h4= t '.create_section'
41
+
42
+ = form_tag admin_role_sections_path(role), :class => 'well form-inline' do |f|
43
+ = text_field_tag :section_name, '', :class => 'input-xlarge', :placeholder => t('.new_section_placeholder')
44
+ = submit_tag t('.create_section'), :class => :btn
45
+
46
+ %h4= t '.create_rule'
47
+
48
+ = form_tag create_rule_admin_role_sections_path(role), :class => 'well form-inline' do |f|
49
+ %select.span3{ :name => :section_name }
50
+ - role.to_hash.each_pair do |section, rules|
51
+ %option{ :value => section }= section
52
+
53
+ = text_field_tag :rule_name, '', :class => 'input-large', :placeholder => t('.new_rule_placeholder')
54
+ = submit_tag t('.create_rule'), :class => :btn
@@ -1,8 +1,11 @@
1
- - content_for :sidebar do
1
+ - content_for :role_sidebar do
2
+ %h3= link_to raw('← Home'), root_path
3
+ %br
2
4
  %h3= t '.roles_list'
3
5
  - (@roles || Role.all).each do |role|
4
6
  %p
5
7
  = link_to role.title, edit_admin_role_url(role)
8
+ (#{role.users.count})
6
9
  = link_to raw('×'), admin_role_url(role), :method => :delete, :title => role.title, :confirm => t('.delete_role_confirm'), :class => :delete
7
10
 
8
11
  %p.new= link_to t('.new_role'), new_admin_role_path
@@ -1,2 +1,2 @@
1
- = render :partial => 'sidebar'
2
- = render :partial => 'role', :locals => { :role => @role }
1
+ = render partial: 'sidebar'
2
+ = render partial: 'role', locals: { role: @role }
@@ -1,2 +1,2 @@
1
- = render :partial => 'sidebar'
2
- = render :partial => 'role', :locals => { :role => @roles.first }
1
+ = render partial: 'sidebar'
2
+ = render partial: 'role', locals: { role: @roles.first }
@@ -1,23 +1,24 @@
1
- = render :partial => 'sidebar'
1
+ = render partial: 'sidebar'
2
2
 
3
- .well
4
- - @role.errors.each do |field, message|
5
- %p
6
- = field
7
- \:
8
- = message
3
+ - content_for :role_main do
4
+ .well
5
+ - @role.errors.each do |field, message|
6
+ %p
7
+ = field
8
+ \:
9
+ = message
9
10
 
10
- .form
11
- %h3= raw t('.create')
11
+ .form
12
+ %h3= raw t('.create')
12
13
 
13
- = form_for(@role, :url => admin_roles_path) do |f|
14
- %label= t('.name')
15
- %p= f.text_field :name
14
+ = form_for(@role, :url => admin_roles_path) do |f|
15
+ %label= t('.name')
16
+ %p= f.text_field :name
16
17
 
17
- %label= t('.title')
18
- %p= f.text_field :title
18
+ %label= t('.title')
19
+ %p= f.text_field :title
19
20
 
20
- %label= t('.description')
21
- %p= f.text_field :description
21
+ %label= t('.description')
22
+ %p= f.text_field :description
22
23
 
23
- = f.submit t('.create'), :class => :btn
24
+ = f.submit t('.create'), :class => :btn
@@ -0,0 +1,19 @@
1
+ ---------------------------------------
2
+ TheRole
3
+ ---------------------------------------
4
+
5
+ Description:
6
+ This generators helps to install TheRole gem into your Application
7
+
8
+ This text:
9
+ bundle exec rails g the_role --help
10
+
11
+ Generators:
12
+ bundle exec rails g the_role install
13
+
14
+ Migrations:
15
+ bundle exec rake the_role_engine:install:migrations
16
+
17
+ ---------------------------------------
18
+ TheRole
19
+ ---------------------------------------
@@ -0,0 +1,5 @@
1
+ # TheRole.config.param_name => value
2
+
3
+ TheRole.configure do |config|
4
+ config.layout = 'the_role'
5
+ end
@@ -0,0 +1,23 @@
1
+ class TheRoleGenerator < Rails::Generators::NamedBase
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ # argument :xname, type: :string, default: :xname
4
+
5
+ def generate_controllers
6
+ if gen_name == 'install'
7
+ cp_setup
8
+ else
9
+ puts 'TheComments Generator - wrong Name'
10
+ puts 'Try to use install'
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def gen_name
17
+ name.to_s.downcase
18
+ end
19
+
20
+ def cp_setup
21
+ copy_file 'the_role.rb', 'config/initializers/the_role.rb'
22
+ end
23
+ end
@@ -0,0 +1,20 @@
1
+ module TheRole
2
+ def self.configure(&block)
3
+ yield @config ||= TheRole::Configuration.new
4
+ end
5
+
6
+ def self.config
7
+ @config
8
+ end
9
+
10
+ # Configuration class
11
+ class Configuration
12
+ include ActiveSupport::Configurable
13
+ config_accessor :layout, :default_user_role
14
+ end
15
+
16
+ configure do |config|
17
+ config.layout = :application
18
+ config.default_user_role = nil
19
+ end
20
+ end
data/lib/the_role/hash.rb CHANGED
@@ -1,14 +1,10 @@
1
1
  # load 'the_role/hash.rb' - UPDATE, BUT NOT RELOAD [for console testing]
2
-
3
2
  class Hash
4
- # Puts message about potential compatibility problem
5
- if respond_to? :underscorify_keys
6
- puts "\nWARNING!\nHASH#underscorify_keys detected.\nIf now it's native active_support/core_ext/hash method,\nyou should to create new issue for https://github.com/the-teacher/the_role\n\n"
7
- end
8
-
9
- # RAILS 4 like methods for RAILS 3
10
- # DEEP TRANSFORM HELPER METHODS
11
- unless respond_to? :deep_transform_keys
3
+ # deep_transform_keys
4
+ # deep_stringify_keys
5
+ # underscorify_keys
6
+ # deep_reset
7
+ unless {}.respond_to?(:deep_transform_keys)
12
8
  def deep_transform_keys(&block)
13
9
  result = {}
14
10
  each do |key, value|
@@ -24,12 +20,9 @@ class Hash
24
20
  end
25
21
  self
26
22
  end
27
- puts "[TheRole] RAILS 4 like method **deep_transform_keys** mixed to HASH class"
28
23
  end
29
24
 
30
- # RAILS 4 like methods for RAILS 3
31
- # DEEP TRANSFORM HELPER METHODS
32
- unless respond_to? :deep_stringify_keys
25
+ unless {}.respond_to?(:deep_stringify_keys)
33
26
  def deep_stringify_keys
34
27
  deep_transform_keys{ |key| key.to_s }
35
28
  end
@@ -37,29 +30,29 @@ class Hash
37
30
  def deep_stringify_keys!
38
31
  deep_transform_keys!{ |key| key.to_s }
39
32
  end
40
- puts "[TheRole] RAILS 4 like method **deep_stringify_keys** mixed to HASH class"
41
33
  end
42
34
 
43
- # Potential compatibility problem with RAILS_VERSION > 4.0
44
- # But I hope nobody will create function with this name
45
- def underscorify_keys
46
- deep_transform_keys{ |key| TheRole::ParamHelper.prepare(key) }
47
- end
35
+ unless {}.respond_to?(:underscorify_keys)
36
+ def underscorify_keys
37
+ deep_transform_keys{ |key| TheRoleParam.process(key) }
38
+ end
48
39
 
49
- def underscorify_keys!
50
- replace underscorify_keys
40
+ def underscorify_keys!
41
+ replace underscorify_keys
42
+ end
51
43
  end
52
44
 
53
- # DEEP RESET VALUES
54
- def deep_reset(default = nil)
55
- hash = dup
56
- hash.each do |key, value|
57
- hash[key] = hash[key].is_a?(Hash) ? hash[key].deep_reset(default) : default
45
+ unless {}.respond_to?(:deep_reset)
46
+ def deep_reset(default = nil)
47
+ hash = dup
48
+ hash.each do |key, value|
49
+ hash[key] = hash[key].is_a?(Hash) ? hash[key].deep_reset(default) : default
50
+ end
51
+ hash
58
52
  end
59
- hash
60
- end
61
53
 
62
- def deep_reset!(default = nil)
63
- replace deep_reset(default)
54
+ def deep_reset!(default = nil)
55
+ replace deep_reset(default)
56
+ end
64
57
  end
65
58
  end
@@ -1,15 +1,9 @@
1
1
  require "active_support/inflector"
2
2
 
3
- # TheRole::ParamHelper.prepare 'hello world'
3
+ # TheRoleParam.process 'hello world'
4
4
 
5
- module TheRole
6
- module ParamHelper
7
- def param_prepare param
8
- param.to_s.parameterize.underscore
9
- end
10
-
11
- def self.prepare param
12
- param.to_s.parameterize.underscore
13
- end
5
+ module TheRoleParam
6
+ def self.process param
7
+ param.to_s.parameterize.underscore
14
8
  end
15
- end
9
+ end
@@ -1,3 +1,3 @@
1
1
  module TheRole
2
- VERSION = "1.7.0"
2
+ VERSION = "2.0.0"
3
3
  end
data/lib/the_role.rb CHANGED
@@ -1,21 +1,22 @@
1
1
  require 'haml'
2
2
 
3
- require 'the_role/param_helper'
4
3
  require 'the_role/hash'
5
-
6
- require 'the_role/engine'
4
+ require 'the_role/config'
7
5
  require 'the_role/version'
8
- require 'the_role/the_class_exists'
9
-
10
- require 'the_role/modules/base'
11
- require 'the_role/modules/user_model'
12
- require 'the_role/modules/role_model'
13
- require 'the_role/modules/controller_requires'
6
+ require 'the_role/param_helper'
14
7
 
15
8
  module TheRole
16
- # include TheRole::Base
17
- # include TheRole::Requires
18
- # include TheRole::UserModel
19
- # include TheRole::RoleModel
20
- # include TheRole::ParamHelper
9
+ class Engine < Rails::Engine
10
+ initializer "TheRole precompile hook", :group => :all do |app|
11
+ app.config.assets.precompile += %w( admin_the_role.js admin_the_role.css )
12
+ end
13
+
14
+ # http://stackoverflow.com/questions/6279325/adding-to-rails-autoload-path-from-gem
15
+
16
+ # config.to_prepare do
17
+ # Role.send :include, TheRole::RoleModel if the_class_exists? :Role
18
+ # User.send :include, TheRole::UserModel if the_class_exists? :User
19
+ # ApplicationController.send :include, TheRole::Requires if the_class_exists? :ApplicationController
20
+ # end
21
+ end
21
22
  end
data/the_role.gemspec CHANGED
@@ -13,10 +13,10 @@ Gem::Specification.new do |s|
13
13
 
14
14
  s.rubyforge_project = "the_role"
15
15
 
16
- s.files = `git ls-files`.split("\n")
16
+ s.files = `git ls-files`.split("\n").select{ |file_name| !(file_name =~ /^spec/) }
17
17
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
18
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
19
  s.require_paths = ["lib"]
20
20
 
21
21
  s.add_dependency 'haml'
22
- end
22
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: the_role
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 2.0.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-31 00:00:00.000000000 Z
12
+ date: 2013-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: haml
16
- requirement: &21325720 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *21325720
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  description: Authorization lib for Rails 3 with Web Interface, aka CanCan killer
26
31
  email:
27
32
  - zykin-ilya@ya.ru
@@ -31,20 +36,18 @@ extra_rdoc_files: []
31
36
  files:
32
37
  - .gitignore
33
38
  - .rvmrc.example
39
+ - .travis.yml
34
40
  - Bye_bye_CanCan_I_got_the_Role.png
35
41
  - Gemfile
36
42
  - README.md
37
43
  - Rakefile
38
- - app/assets/javascripts/admin_the_role.js
39
- - app/assets/javascripts/bootstrap-alert.js
40
- - app/assets/javascripts/bootstrap-dropdown.js
41
- - app/assets/stylesheets/admin_the_role.css
42
- - app/assets/stylesheets/custom.css
43
- - app/assets/stylesheets/headers.css
44
- - app/assets/stylesheets/reset.css
45
- - app/assets/stylesheets/role_base.css
44
+ - app/assets/stylesheets/the_role.css.scss
46
45
  - app/controllers/admin/role_sections_controller.rb
47
46
  - app/controllers/admin/roles_controller.rb
47
+ - app/controllers/the_role_controller.rb
48
+ - app/models/concerns/role_model.rb
49
+ - app/models/concerns/the_role_base.rb
50
+ - app/models/concerns/the_role_user_model.rb
48
51
  - app/views/admin/roles/_form.haml
49
52
  - app/views/admin/roles/_role.html.haml
50
53
  - app/views/admin/roles/_sidebar.html.haml
@@ -58,14 +61,13 @@ files:
58
61
  - config/locales/zh_CN.yml
59
62
  - config/routes.rb
60
63
  - db/migrate/20111025025129_create_roles.rb
64
+ - lib/generators/the_role/USAGE
65
+ - lib/generators/the_role/templates/the_role.rb
66
+ - lib/generators/the_role/the_role_generator.rb
61
67
  - lib/tasks/roles.rake
62
68
  - lib/the_role.rb
63
- - lib/the_role/engine.rb
69
+ - lib/the_role/config.rb
64
70
  - lib/the_role/hash.rb
65
- - lib/the_role/modules/base.rb
66
- - lib/the_role/modules/controller_requires.rb
67
- - lib/the_role/modules/role_model.rb
68
- - lib/the_role/modules/user_model.rb
69
71
  - lib/the_role/param_helper.rb
70
72
  - lib/the_role/the_class_exists.rb
71
73
  - lib/the_role/version.rb
@@ -91,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
93
  version: '0'
92
94
  requirements: []
93
95
  rubyforge_project: the_role
94
- rubygems_version: 1.8.15
96
+ rubygems_version: 1.8.25
95
97
  signing_key:
96
98
  specification_version: 3
97
99
  summary: Authorization lib for Rails 3 with Web Interface, aka CanCan killer
@@ -1,4 +0,0 @@
1
- //= require jquery
2
- //= require jquery_ujs
3
- //= require bootstrap-alert
4
- //= require bootstrap-dropdown
@@ -1,90 +0,0 @@
1
- /* ==========================================================
2
- * bootstrap-alert.js v2.0.4
3
- * http://twitter.github.com/bootstrap/javascript.html#alerts
4
- * ==========================================================
5
- * Copyright 2012 Twitter, Inc.
6
- *
7
- * Licensed under the Apache License, Version 2.0 (the "License");
8
- * you may not use this file except in compliance with the License.
9
- * You may obtain a copy of the License at
10
- *
11
- * http://www.apache.org/licenses/LICENSE-2.0
12
- *
13
- * Unless required by applicable law or agreed to in writing, software
14
- * distributed under the License is distributed on an "AS IS" BASIS,
15
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
- * See the License for the specific language governing permissions and
17
- * limitations under the License.
18
- * ========================================================== */
19
-
20
-
21
- !function ($) {
22
-
23
- "use strict"; // jshint ;_;
24
-
25
-
26
- /* ALERT CLASS DEFINITION
27
- * ====================== */
28
-
29
- var dismiss = '[data-dismiss="alert"]'
30
- , Alert = function (el) {
31
- $(el).on('click', dismiss, this.close)
32
- }
33
-
34
- Alert.prototype.close = function (e) {
35
- var $this = $(this)
36
- , selector = $this.attr('data-target')
37
- , $parent
38
-
39
- if (!selector) {
40
- selector = $this.attr('href')
41
- selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
42
- }
43
-
44
- $parent = $(selector)
45
-
46
- e && e.preventDefault()
47
-
48
- $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
49
-
50
- $parent.trigger(e = $.Event('close'))
51
-
52
- if (e.isDefaultPrevented()) return
53
-
54
- $parent.removeClass('in')
55
-
56
- function removeElement() {
57
- $parent
58
- .trigger('closed')
59
- .remove()
60
- }
61
-
62
- $.support.transition && $parent.hasClass('fade') ?
63
- $parent.on($.support.transition.end, removeElement) :
64
- removeElement()
65
- }
66
-
67
-
68
- /* ALERT PLUGIN DEFINITION
69
- * ======================= */
70
-
71
- $.fn.alert = function (option) {
72
- return this.each(function () {
73
- var $this = $(this)
74
- , data = $this.data('alert')
75
- if (!data) $this.data('alert', (data = new Alert(this)))
76
- if (typeof option == 'string') data[option].call($this)
77
- })
78
- }
79
-
80
- $.fn.alert.Constructor = Alert
81
-
82
-
83
- /* ALERT DATA-API
84
- * ============== */
85
-
86
- $(function () {
87
- $('body').on('click.alert.data-api', dismiss, Alert.prototype.close)
88
- })
89
-
90
- }(window.jQuery);