kulesa-sidekiq 1.2.2
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.
- data/.gitignore +6 -0
- data/.rvmrc +4 -0
- data/COMM-LICENSE +83 -0
- data/Changes.md +207 -0
- data/Gemfile +12 -0
- data/LICENSE +22 -0
- data/README.md +61 -0
- data/Rakefile +9 -0
- data/bin/client +7 -0
- data/bin/sidekiq +14 -0
- data/bin/sidekiqctl +74 -0
- data/config.ru +18 -0
- data/examples/chef/cookbooks/sidekiq/README.rdoc +11 -0
- data/examples/chef/cookbooks/sidekiq/recipes/default.rb +55 -0
- data/examples/chef/cookbooks/sidekiq/templates/default/monitrc.conf.erb +8 -0
- data/examples/chef/cookbooks/sidekiq/templates/default/sidekiq.erb +219 -0
- data/examples/chef/cookbooks/sidekiq/templates/default/sidekiq.yml.erb +22 -0
- data/examples/clockwork.rb +44 -0
- data/examples/config.yml +10 -0
- data/examples/monitrc.conf +6 -0
- data/examples/por.rb +27 -0
- data/examples/scheduling.rb +37 -0
- data/examples/sinkiq.rb +59 -0
- data/examples/web-ui.png +0 -0
- data/lib/sidekiq.rb +98 -0
- data/lib/sidekiq/capistrano.rb +35 -0
- data/lib/sidekiq/cli.rb +214 -0
- data/lib/sidekiq/client.rb +72 -0
- data/lib/sidekiq/extensions/action_mailer.rb +26 -0
- data/lib/sidekiq/extensions/active_record.rb +27 -0
- data/lib/sidekiq/extensions/generic_proxy.rb +21 -0
- data/lib/sidekiq/fetch.rb +76 -0
- data/lib/sidekiq/logging.rb +46 -0
- data/lib/sidekiq/manager.rb +163 -0
- data/lib/sidekiq/middleware/chain.rb +96 -0
- data/lib/sidekiq/middleware/client/unique_jobs.rb +36 -0
- data/lib/sidekiq/middleware/server/active_record.rb +13 -0
- data/lib/sidekiq/middleware/server/exception_handler.rb +38 -0
- data/lib/sidekiq/middleware/server/failure_jobs.rb +25 -0
- data/lib/sidekiq/middleware/server/logging.rb +31 -0
- data/lib/sidekiq/middleware/server/retry_jobs.rb +69 -0
- data/lib/sidekiq/middleware/server/timeout.rb +21 -0
- data/lib/sidekiq/middleware/server/unique_jobs.rb +17 -0
- data/lib/sidekiq/processor.rb +92 -0
- data/lib/sidekiq/rails.rb +21 -0
- data/lib/sidekiq/redis_connection.rb +27 -0
- data/lib/sidekiq/retry.rb +59 -0
- data/lib/sidekiq/testing.rb +44 -0
- data/lib/sidekiq/testing/inline.rb +37 -0
- data/lib/sidekiq/util.rb +40 -0
- data/lib/sidekiq/version.rb +3 -0
- data/lib/sidekiq/web.rb +185 -0
- data/lib/sidekiq/worker.rb +62 -0
- data/lib/sidekiq/yaml_patch.rb +21 -0
- data/myapp/.gitignore +15 -0
- data/myapp/Capfile +5 -0
- data/myapp/Gemfile +19 -0
- data/myapp/Rakefile +7 -0
- data/myapp/app/controllers/application_controller.rb +3 -0
- data/myapp/app/controllers/work_controller.rb +38 -0
- data/myapp/app/helpers/application_helper.rb +2 -0
- data/myapp/app/mailers/.gitkeep +0 -0
- data/myapp/app/mailers/user_mailer.rb +9 -0
- data/myapp/app/models/.gitkeep +0 -0
- data/myapp/app/models/post.rb +5 -0
- data/myapp/app/views/layouts/application.html.erb +14 -0
- data/myapp/app/views/user_mailer/greetings.html.erb +3 -0
- data/myapp/app/views/work/index.html.erb +1 -0
- data/myapp/app/workers/hard_worker.rb +10 -0
- data/myapp/config.ru +4 -0
- data/myapp/config/application.rb +59 -0
- data/myapp/config/boot.rb +6 -0
- data/myapp/config/database.yml +25 -0
- data/myapp/config/deploy.rb +15 -0
- data/myapp/config/environment.rb +5 -0
- data/myapp/config/environments/development.rb +38 -0
- data/myapp/config/environments/production.rb +67 -0
- data/myapp/config/environments/test.rb +37 -0
- data/myapp/config/initializers/backtrace_silencers.rb +7 -0
- data/myapp/config/initializers/inflections.rb +15 -0
- data/myapp/config/initializers/mime_types.rb +5 -0
- data/myapp/config/initializers/secret_token.rb +7 -0
- data/myapp/config/initializers/session_store.rb +8 -0
- data/myapp/config/initializers/sidekiq.rb +6 -0
- data/myapp/config/initializers/wrap_parameters.rb +14 -0
- data/myapp/config/locales/en.yml +5 -0
- data/myapp/config/routes.rb +10 -0
- data/myapp/db/migrate/20120123214055_create_posts.rb +10 -0
- data/myapp/db/seeds.rb +7 -0
- data/myapp/lib/assets/.gitkeep +0 -0
- data/myapp/lib/tasks/.gitkeep +0 -0
- data/myapp/log/.gitkeep +0 -0
- data/myapp/script/rails +6 -0
- data/sidekiq.gemspec +27 -0
- data/test/config.yml +9 -0
- data/test/fake_env.rb +0 -0
- data/test/helper.rb +16 -0
- data/test/test_cli.rb +168 -0
- data/test/test_client.rb +119 -0
- data/test/test_extensions.rb +69 -0
- data/test/test_manager.rb +51 -0
- data/test/test_middleware.rb +92 -0
- data/test/test_processor.rb +32 -0
- data/test/test_retry.rb +125 -0
- data/test/test_stats.rb +68 -0
- data/test/test_testing.rb +97 -0
- data/test/test_testing_inline.rb +75 -0
- data/test/test_web.rb +122 -0
- data/web/assets/images/bootstrap/glyphicons-halflings-white.png +0 -0
- data/web/assets/images/bootstrap/glyphicons-halflings.png +0 -0
- data/web/assets/javascripts/application.js +20 -0
- data/web/assets/javascripts/vendor/bootstrap.js +12 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-alert.js +91 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-button.js +98 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-carousel.js +154 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-collapse.js +136 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-dropdown.js +92 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-modal.js +210 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-popover.js +95 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-scrollspy.js +125 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-tab.js +130 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-tooltip.js +270 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-transition.js +51 -0
- data/web/assets/javascripts/vendor/bootstrap/bootstrap-typeahead.js +271 -0
- data/web/assets/javascripts/vendor/jquery.js +9266 -0
- data/web/assets/javascripts/vendor/jquery.timeago.js +148 -0
- data/web/assets/stylesheets/application.css +27 -0
- data/web/assets/stylesheets/vendor/bootstrap-responsive.css +567 -0
- data/web/assets/stylesheets/vendor/bootstrap.css +3365 -0
- data/web/views/index.slim +48 -0
- data/web/views/layout.slim +26 -0
- data/web/views/queue.slim +11 -0
- data/web/views/retries.slim +29 -0
- data/web/views/retry.slim +52 -0
- metadata +371 -0
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
require 'sidekiq'
|
|
3
|
+
require 'sidekiq/worker'
|
|
4
|
+
require 'active_record'
|
|
5
|
+
require 'action_mailer'
|
|
6
|
+
require 'sidekiq/rails'
|
|
7
|
+
require 'sidekiq/extensions/action_mailer'
|
|
8
|
+
require 'sidekiq/extensions/active_record'
|
|
9
|
+
|
|
10
|
+
Sidekiq.hook_rails!
|
|
11
|
+
|
|
12
|
+
class TestInline < MiniTest::Unit::TestCase
|
|
13
|
+
describe 'sidekiq inline testing' do
|
|
14
|
+
class InlineError < RuntimeError; end
|
|
15
|
+
|
|
16
|
+
class InlineWorker
|
|
17
|
+
include Sidekiq::Worker
|
|
18
|
+
def perform(pass)
|
|
19
|
+
raise InlineError unless pass
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
class InlineFooMailer < ActionMailer::Base
|
|
24
|
+
def bar(str)
|
|
25
|
+
raise InlineError
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
class InlineFooModel < ActiveRecord::Base
|
|
30
|
+
def self.bar(str)
|
|
31
|
+
raise InlineError
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
before do
|
|
36
|
+
load 'sidekiq/testing/inline.rb'
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
after do
|
|
40
|
+
Sidekiq::Worker::ClassMethods.class_eval do
|
|
41
|
+
remove_method :perform_async
|
|
42
|
+
alias_method :perform_async, :perform_async_old
|
|
43
|
+
remove_method :perform_async_old
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
it 'stubs the async call when in testing mode' do
|
|
48
|
+
assert InlineWorker.perform_async(true)
|
|
49
|
+
|
|
50
|
+
assert_raises InlineError do
|
|
51
|
+
InlineWorker.perform_async(false)
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it 'stubs the delay call on mailers' do
|
|
56
|
+
assert_raises InlineError do
|
|
57
|
+
InlineFooMailer.delay.bar('three')
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'stubs the delay call on models' do
|
|
62
|
+
assert_raises InlineError do
|
|
63
|
+
InlineFooModel.delay.bar('three')
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
it 'stubs the enqueue call when in testing mode' do
|
|
68
|
+
assert Sidekiq::Client.enqueue(InlineWorker, true)
|
|
69
|
+
|
|
70
|
+
assert_raises InlineError do
|
|
71
|
+
Sidekiq::Client.enqueue(InlineWorker, false)
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
data/test/test_web.rb
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
require 'helper'
|
|
2
|
+
require 'sidekiq'
|
|
3
|
+
require 'sidekiq/web'
|
|
4
|
+
require 'rack/test'
|
|
5
|
+
|
|
6
|
+
class TestWeb < MiniTest::Unit::TestCase
|
|
7
|
+
describe 'sidekiq web' do
|
|
8
|
+
include Rack::Test::Methods
|
|
9
|
+
|
|
10
|
+
def app
|
|
11
|
+
Sidekiq::Web
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
before do
|
|
15
|
+
Sidekiq.redis = REDIS
|
|
16
|
+
Sidekiq.redis {|c| c.flushdb }
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
class WebWorker
|
|
20
|
+
include Sidekiq::Worker
|
|
21
|
+
|
|
22
|
+
def perform(a, b)
|
|
23
|
+
a + b
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it 'shows active queues' do
|
|
28
|
+
get '/'
|
|
29
|
+
assert_equal 200, last_response.status
|
|
30
|
+
assert_match /Sidekiq is idle/, last_response.body
|
|
31
|
+
refute_match /default/, last_response.body
|
|
32
|
+
|
|
33
|
+
assert WebWorker.perform_async(1, 2)
|
|
34
|
+
|
|
35
|
+
get '/'
|
|
36
|
+
assert_equal 200, last_response.status
|
|
37
|
+
assert_match /Sidekiq is idle/, last_response.body
|
|
38
|
+
assert_match /default/, last_response.body
|
|
39
|
+
refute_match /foo/, last_response.body
|
|
40
|
+
|
|
41
|
+
assert Sidekiq::Client.push('queue' => :foo, 'class' => WebWorker, 'args' => [1, 3])
|
|
42
|
+
|
|
43
|
+
get '/'
|
|
44
|
+
assert_equal 200, last_response.status
|
|
45
|
+
assert_match /Sidekiq is idle/, last_response.body
|
|
46
|
+
assert_match /default/, last_response.body
|
|
47
|
+
assert_match /foo/, last_response.body
|
|
48
|
+
assert_match /Backlog: 2/, last_response.body
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
it 'handles queues with no name' do
|
|
52
|
+
get '/queues'
|
|
53
|
+
assert_equal 404, last_response.status
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
it 'handles missing retry' do
|
|
57
|
+
get '/retries/12391982.123'
|
|
58
|
+
assert_equal 302, last_response.status
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it 'handles queue view' do
|
|
62
|
+
get '/queues/default'
|
|
63
|
+
assert_equal 200, last_response.status
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
it 'can delete a queue' do
|
|
67
|
+
Sidekiq.redis do |conn|
|
|
68
|
+
conn.rpush('queue:foo', '{}')
|
|
69
|
+
conn.sadd('queues', 'foo')
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
get '/queues/foo'
|
|
73
|
+
assert_equal 200, last_response.status
|
|
74
|
+
|
|
75
|
+
post '/queues/foo'
|
|
76
|
+
assert_equal 302, last_response.status
|
|
77
|
+
|
|
78
|
+
Sidekiq.redis do |conn|
|
|
79
|
+
refute conn.smembers('queues').include?('foo')
|
|
80
|
+
end
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
it 'can display retries' do
|
|
84
|
+
get '/retries'
|
|
85
|
+
assert_equal 200, last_response.status
|
|
86
|
+
assert_match /found/, last_response.body
|
|
87
|
+
refute_match /HardWorker/, last_response.body
|
|
88
|
+
|
|
89
|
+
add_retry
|
|
90
|
+
|
|
91
|
+
get '/retries'
|
|
92
|
+
assert_equal 200, last_response.status
|
|
93
|
+
refute_match /found/, last_response.body
|
|
94
|
+
assert_match /HardWorker/, last_response.body
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it 'can display a single retry' do
|
|
98
|
+
get '/retries/12938712.123333'
|
|
99
|
+
assert_equal 302, last_response.status
|
|
100
|
+
_, score = add_retry
|
|
101
|
+
|
|
102
|
+
get "/retries/#{score}"
|
|
103
|
+
assert_equal 200, last_response.status
|
|
104
|
+
assert_match /HardWorker/, last_response.body
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def add_retry
|
|
108
|
+
msg = { 'class' => 'HardWorker',
|
|
109
|
+
'args' => ['bob', 1, Time.now.to_f],
|
|
110
|
+
'queue' => 'default',
|
|
111
|
+
'error_message' => 'Some fake message',
|
|
112
|
+
'error_class' => 'RuntimeError',
|
|
113
|
+
'retry_count' => 0,
|
|
114
|
+
'failed_at' => Time.now.utc, }
|
|
115
|
+
score = Time.now.to_f
|
|
116
|
+
Sidekiq.redis do |conn|
|
|
117
|
+
conn.zadd('retry', score, Sidekiq.dump_json(msg))
|
|
118
|
+
end
|
|
119
|
+
[msg, score]
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
Binary file
|
|
Binary file
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
//= require vendor/jquery
|
|
2
|
+
//= require vendor/jquery.timeago
|
|
3
|
+
//= require bootstrap
|
|
4
|
+
//= require_tree .
|
|
5
|
+
|
|
6
|
+
$(function() {
|
|
7
|
+
$.timeago.settings.allowFuture = true
|
|
8
|
+
$("time").timeago();
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
$(function() {
|
|
12
|
+
$('.check_all').live('click', function() {
|
|
13
|
+
var checked = $(this).attr('checked');
|
|
14
|
+
if (checked == 'checked') {
|
|
15
|
+
$('input[type=checkbox]', $(this).closest('table')).attr('checked', checked);
|
|
16
|
+
} else {
|
|
17
|
+
$('input[type=checkbox]', $(this).closest('table')).removeAttr('checked');
|
|
18
|
+
}
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//= require vendor/bootstrap/bootstrap-transition
|
|
2
|
+
//= require vendor/bootstrap/bootstrap-alert
|
|
3
|
+
//= require vendor/bootstrap/bootstrap-modal
|
|
4
|
+
//= require vendor/bootstrap/bootstrap-dropdown
|
|
5
|
+
//= require vendor/bootstrap/bootstrap-scrollspy
|
|
6
|
+
//= require vendor/bootstrap/bootstrap-tab
|
|
7
|
+
//= require vendor/bootstrap/bootstrap-tooltip
|
|
8
|
+
//= require vendor/bootstrap/bootstrap-popover
|
|
9
|
+
//= require vendor/bootstrap/bootstrap-button
|
|
10
|
+
//= require vendor/bootstrap/bootstrap-collapse
|
|
11
|
+
//= require vendor/bootstrap/bootstrap-carousel
|
|
12
|
+
//= require vendor/bootstrap/bootstrap-typeahead
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/* ==========================================================
|
|
2
|
+
* bootstrap-alert.js v2.0.0
|
|
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"
|
|
24
|
+
|
|
25
|
+
/* ALERT CLASS DEFINITION
|
|
26
|
+
* ====================== */
|
|
27
|
+
|
|
28
|
+
var dismiss = '[data-dismiss="alert"]'
|
|
29
|
+
, Alert = function ( el ) {
|
|
30
|
+
$(el).on('click', dismiss, this.close)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
Alert.prototype = {
|
|
34
|
+
|
|
35
|
+
constructor: Alert
|
|
36
|
+
|
|
37
|
+
, close: function ( e ) {
|
|
38
|
+
var $this = $(this)
|
|
39
|
+
, selector = $this.attr('data-target')
|
|
40
|
+
, $parent
|
|
41
|
+
|
|
42
|
+
if (!selector) {
|
|
43
|
+
selector = $this.attr('href')
|
|
44
|
+
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
$parent = $(selector)
|
|
48
|
+
$parent.trigger('close')
|
|
49
|
+
|
|
50
|
+
e && e.preventDefault()
|
|
51
|
+
|
|
52
|
+
$parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
|
|
53
|
+
|
|
54
|
+
$parent.removeClass('in')
|
|
55
|
+
|
|
56
|
+
function removeElement() {
|
|
57
|
+
$parent.remove()
|
|
58
|
+
$parent.trigger('closed')
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
$.support.transition && $parent.hasClass('fade') ?
|
|
62
|
+
$parent.on($.support.transition.end, removeElement) :
|
|
63
|
+
removeElement()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
/* ALERT PLUGIN DEFINITION
|
|
70
|
+
* ======================= */
|
|
71
|
+
|
|
72
|
+
$.fn.alert = function ( option ) {
|
|
73
|
+
return this.each(function () {
|
|
74
|
+
var $this = $(this)
|
|
75
|
+
, data = $this.data('alert')
|
|
76
|
+
if (!data) $this.data('alert', (data = new Alert(this)))
|
|
77
|
+
if (typeof option == 'string') data[option].call($this)
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
$.fn.alert.Constructor = Alert
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
/* ALERT DATA-API
|
|
85
|
+
* ============== */
|
|
86
|
+
|
|
87
|
+
$(function () {
|
|
88
|
+
$('body').on('click.alert.data-api', dismiss, Alert.prototype.close)
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
}( window.jQuery )
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/* ============================================================
|
|
2
|
+
* bootstrap-button.js v2.0.0
|
|
3
|
+
* http://twitter.github.com/bootstrap/javascript.html#buttons
|
|
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
|
+
!function( $ ){
|
|
21
|
+
|
|
22
|
+
"use strict"
|
|
23
|
+
|
|
24
|
+
/* BUTTON PUBLIC CLASS DEFINITION
|
|
25
|
+
* ============================== */
|
|
26
|
+
|
|
27
|
+
var Button = function ( element, options ) {
|
|
28
|
+
this.$element = $(element)
|
|
29
|
+
this.options = $.extend({}, $.fn.button.defaults, options)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
Button.prototype = {
|
|
33
|
+
|
|
34
|
+
constructor: Button
|
|
35
|
+
|
|
36
|
+
, setState: function ( state ) {
|
|
37
|
+
var d = 'disabled'
|
|
38
|
+
, $el = this.$element
|
|
39
|
+
, data = $el.data()
|
|
40
|
+
, val = $el.is('input') ? 'val' : 'html'
|
|
41
|
+
|
|
42
|
+
state = state + 'Text'
|
|
43
|
+
data.resetText || $el.data('resetText', $el[val]())
|
|
44
|
+
|
|
45
|
+
$el[val](data[state] || this.options[state])
|
|
46
|
+
|
|
47
|
+
// push to event loop to allow forms to submit
|
|
48
|
+
setTimeout(function () {
|
|
49
|
+
state == 'loadingText' ?
|
|
50
|
+
$el.addClass(d).attr(d, d) :
|
|
51
|
+
$el.removeClass(d).removeAttr(d)
|
|
52
|
+
}, 0)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
, toggle: function () {
|
|
56
|
+
var $parent = this.$element.parent('[data-toggle="buttons-radio"]')
|
|
57
|
+
|
|
58
|
+
$parent && $parent
|
|
59
|
+
.find('.active')
|
|
60
|
+
.removeClass('active')
|
|
61
|
+
|
|
62
|
+
this.$element.toggleClass('active')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
/* BUTTON PLUGIN DEFINITION
|
|
69
|
+
* ======================== */
|
|
70
|
+
|
|
71
|
+
$.fn.button = function ( option ) {
|
|
72
|
+
return this.each(function () {
|
|
73
|
+
var $this = $(this)
|
|
74
|
+
, data = $this.data('button')
|
|
75
|
+
, options = typeof option == 'object' && option
|
|
76
|
+
if (!data) $this.data('button', (data = new Button(this, options)))
|
|
77
|
+
if (option == 'toggle') data.toggle()
|
|
78
|
+
else if (option) data.setState(option)
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
$.fn.button.defaults = {
|
|
83
|
+
loadingText: 'loading...'
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
$.fn.button.Constructor = Button
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
/* BUTTON DATA-API
|
|
90
|
+
* =============== */
|
|
91
|
+
|
|
92
|
+
$(function () {
|
|
93
|
+
$('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) {
|
|
94
|
+
$(e.target).button('toggle')
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
}( window.jQuery )
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/* ==========================================================
|
|
2
|
+
* bootstrap-carousel.js v2.0.0
|
|
3
|
+
* http://twitter.github.com/bootstrap/javascript.html#carousel
|
|
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"
|
|
24
|
+
|
|
25
|
+
/* CAROUSEL CLASS DEFINITION
|
|
26
|
+
* ========================= */
|
|
27
|
+
|
|
28
|
+
var Carousel = function (element, options) {
|
|
29
|
+
this.$element = $(element)
|
|
30
|
+
this.options = $.extend({}, $.fn.carousel.defaults, options)
|
|
31
|
+
this.options.slide && this.slide(this.options.slide)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
Carousel.prototype = {
|
|
35
|
+
|
|
36
|
+
cycle: function () {
|
|
37
|
+
this.interval = setInterval($.proxy(this.next, this), this.options.interval)
|
|
38
|
+
return this
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
, to: function (pos) {
|
|
42
|
+
var $active = this.$element.find('.active')
|
|
43
|
+
, children = $active.parent().children()
|
|
44
|
+
, activePos = children.index($active)
|
|
45
|
+
, that = this
|
|
46
|
+
|
|
47
|
+
if (pos > (children.length - 1) || pos < 0) return
|
|
48
|
+
|
|
49
|
+
if (this.sliding) {
|
|
50
|
+
return this.$element.one('slid', function () {
|
|
51
|
+
that.to(pos)
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (activePos == pos) {
|
|
56
|
+
return this.pause().cycle()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos]))
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
, pause: function () {
|
|
63
|
+
clearInterval(this.interval)
|
|
64
|
+
return this
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
, next: function () {
|
|
68
|
+
if (this.sliding) return
|
|
69
|
+
return this.slide('next')
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
, prev: function () {
|
|
73
|
+
if (this.sliding) return
|
|
74
|
+
return this.slide('prev')
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
, slide: function (type, next) {
|
|
78
|
+
var $active = this.$element.find('.active')
|
|
79
|
+
, $next = next || $active[type]()
|
|
80
|
+
, isCycling = this.interval
|
|
81
|
+
, direction = type == 'next' ? 'left' : 'right'
|
|
82
|
+
, fallback = type == 'next' ? 'first' : 'last'
|
|
83
|
+
, that = this
|
|
84
|
+
|
|
85
|
+
this.sliding = true
|
|
86
|
+
|
|
87
|
+
isCycling && this.pause()
|
|
88
|
+
|
|
89
|
+
$next = $next.length ? $next : this.$element.find('.item')[fallback]()
|
|
90
|
+
|
|
91
|
+
if (!$.support.transition && this.$element.hasClass('slide')) {
|
|
92
|
+
this.$element.trigger('slide')
|
|
93
|
+
$active.removeClass('active')
|
|
94
|
+
$next.addClass('active')
|
|
95
|
+
this.sliding = false
|
|
96
|
+
this.$element.trigger('slid')
|
|
97
|
+
} else {
|
|
98
|
+
$next.addClass(type)
|
|
99
|
+
$next[0].offsetWidth // force reflow
|
|
100
|
+
$active.addClass(direction)
|
|
101
|
+
$next.addClass(direction)
|
|
102
|
+
this.$element.trigger('slide')
|
|
103
|
+
this.$element.one($.support.transition.end, function () {
|
|
104
|
+
$next.removeClass([type, direction].join(' ')).addClass('active')
|
|
105
|
+
$active.removeClass(['active', direction].join(' '))
|
|
106
|
+
that.sliding = false
|
|
107
|
+
setTimeout(function () { that.$element.trigger('slid') }, 0)
|
|
108
|
+
})
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
isCycling && this.cycle()
|
|
112
|
+
|
|
113
|
+
return this
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
|
|
119
|
+
/* CAROUSEL PLUGIN DEFINITION
|
|
120
|
+
* ========================== */
|
|
121
|
+
|
|
122
|
+
$.fn.carousel = function ( option ) {
|
|
123
|
+
return this.each(function () {
|
|
124
|
+
var $this = $(this)
|
|
125
|
+
, data = $this.data('carousel')
|
|
126
|
+
, options = typeof option == 'object' && option
|
|
127
|
+
if (!data) $this.data('carousel', (data = new Carousel(this, options)))
|
|
128
|
+
if (typeof option == 'number') data.to(option)
|
|
129
|
+
else if (typeof option == 'string' || (option = options.slide)) data[option]()
|
|
130
|
+
else data.cycle()
|
|
131
|
+
})
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
$.fn.carousel.defaults = {
|
|
135
|
+
interval: 5000
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
$.fn.carousel.Constructor = Carousel
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
/* CAROUSEL DATA-API
|
|
142
|
+
* ================= */
|
|
143
|
+
|
|
144
|
+
$(function () {
|
|
145
|
+
$('body').on('click.carousel.data-api', '[data-slide]', function ( e ) {
|
|
146
|
+
var $this = $(this), href
|
|
147
|
+
, $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
|
|
148
|
+
, options = !$target.data('modal') && $.extend({}, $target.data(), $this.data())
|
|
149
|
+
$target.carousel(options)
|
|
150
|
+
e.preventDefault()
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
}( window.jQuery )
|