bumble 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +16 -0
- data/.rvmrc +1 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/Readme.mdown +8 -0
- data/app/controllers/bumble_controller.rb +45 -0
- data/app/controllers/comments_controller.rb +99 -0
- data/app/controllers/password_resets_controller.rb +34 -0
- data/app/controllers/posts_controller.rb +103 -0
- data/app/controllers/user_sessions_controller.rb +22 -0
- data/app/controllers/users_controller.rb +60 -0
- data/app/helpers/bumble_helper.rb +50 -0
- data/app/models/asset.rb +57 -0
- data/app/models/comment.rb +78 -0
- data/app/models/notifier.rb +35 -0
- data/app/models/post.rb +57 -0
- data/app/models/posts/blog.rb +3 -0
- data/app/models/posts/code.rb +3 -0
- data/app/models/posts/image.rb +3 -0
- data/app/models/posts/link.rb +7 -0
- data/app/models/posts/quote.rb +3 -0
- data/app/models/posts/video.rb +4 -0
- data/app/models/user.rb +35 -0
- data/app/models/user_session.rb +2 -0
- data/app/views/comments/_comment.html.haml +14 -0
- data/app/views/comments/_form.html.haml +9 -0
- data/app/views/comments/edit.html.haml +7 -0
- data/app/views/comments/index.atom.builder +15 -0
- data/app/views/comments/new.html.haml +7 -0
- data/app/views/layouts/_sidebar.html.haml +20 -0
- data/app/views/layouts/bumble.html.haml +35 -0
- data/app/views/notifier/activation_confirmation.erb +5 -0
- data/app/views/notifier/activation_instructions.erb +5 -0
- data/app/views/notifier/new_comment_alert.erb +8 -0
- data/app/views/notifier/password_reset_instructions.erb +8 -0
- data/app/views/password_resets/edit.html.haml +10 -0
- data/app/views/password_resets/new.html.haml +7 -0
- data/app/views/posts/_form.html.haml +10 -0
- data/app/views/posts/_post.html.haml +16 -0
- data/app/views/posts/_preview.html.haml +8 -0
- data/app/views/posts/edit.html.haml +10 -0
- data/app/views/posts/forms/_blog.html.haml +4 -0
- data/app/views/posts/forms/_code.html.haml +6 -0
- data/app/views/posts/forms/_image.html.haml +9 -0
- data/app/views/posts/forms/_link.html.haml +6 -0
- data/app/views/posts/forms/_quote.html.haml +4 -0
- data/app/views/posts/forms/_video.html.haml +6 -0
- data/app/views/posts/index.atom.builder +15 -0
- data/app/views/posts/index.html.haml +21 -0
- data/app/views/posts/new.html.haml +8 -0
- data/app/views/posts/search.html.haml +27 -0
- data/app/views/posts/show.html.haml +22 -0
- data/app/views/posts/types/_blog.html.haml +4 -0
- data/app/views/posts/types/_code.html.haml +7 -0
- data/app/views/posts/types/_image.html.haml +3 -0
- data/app/views/posts/types/_link.html.haml +3 -0
- data/app/views/posts/types/_quote.html.haml +2 -0
- data/app/views/posts/types/_video.html.haml +5 -0
- data/app/views/user_sessions/new.html.haml +10 -0
- data/app/views/users/_form.html.haml +12 -0
- data/app/views/users/_user.html.haml +3 -0
- data/app/views/users/delete.html.haml +5 -0
- data/app/views/users/edit.html.haml +8 -0
- data/app/views/users/index.html.haml +3 -0
- data/app/views/users/new.html.haml +7 -0
- data/app/views/users/show.html.haml +6 -0
- data/bumble.gemspec +31 -0
- data/config/initializers/bumble.rb +9 -0
- data/config/initializers/haml.rb +2 -0
- data/config/initializers/html5_forms.rb +163 -0
- data/config/initializers/inflections.rb +10 -0
- data/config/initializers/mime_types.rb +5 -0
- data/config/initializers/will_paginate.rb +3 -0
- data/config/routes.rb +29 -0
- data/lib/bumble.rb +18 -0
- data/lib/bumble/version.rb +3 -0
- data/lib/generators/bumble/assets_generator.rb +10 -0
- data/lib/generators/bumble/migrations_generator.rb +40 -0
- data/lib/generators/bumble/templates/assets/images/.gitignore +0 -0
- data/lib/generators/bumble/templates/assets/images/close.png +0 -0
- data/lib/generators/bumble/templates/assets/images/email.png +0 -0
- data/lib/generators/bumble/templates/assets/images/feed.png +0 -0
- data/lib/generators/bumble/templates/assets/images/image.png +0 -0
- data/lib/generators/bumble/templates/assets/images/loading.gif +0 -0
- data/lib/generators/bumble/templates/assets/images/preview.png +0 -0
- data/lib/generators/bumble/templates/assets/images/shortcut.png +0 -0
- data/lib/generators/bumble/templates/assets/images/youtube.png +0 -0
- data/lib/generators/bumble/templates/assets/javascripts/admin.js +95 -0
- data/lib/generators/bumble/templates/assets/javascripts/bumble.js +76 -0
- data/lib/generators/bumble/templates/assets/javascripts/iphone.js +7 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.autogrow.js +37 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.cookie.js +96 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.form.js +665 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.hint.js +44 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.jgrow.js +85 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.js +154 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.ui.core.js +18 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.ui.tabs.js +13 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.ui.widget.js +18 -0
- data/lib/generators/bumble/templates/assets/javascripts/jquery.validate.js +16 -0
- data/lib/generators/bumble/templates/assets/javascripts/modernizr.js +13 -0
- data/lib/generators/bumble/templates/assets/javascripts/ui.core.js +289 -0
- data/lib/generators/bumble/templates/assets/javascripts/ui.tabs.js +593 -0
- data/lib/generators/bumble/templates/migrations/add_approved_to_comments.rb +15 -0
- data/lib/generators/bumble/templates/migrations/add_delta_to_posts.rb +9 -0
- data/lib/generators/bumble/templates/migrations/add_missing_indexes.rb +24 -0
- data/lib/generators/bumble/templates/migrations/add_url_to_users.rb +9 -0
- data/lib/generators/bumble/templates/migrations/create_assets.rb +18 -0
- data/lib/generators/bumble/templates/migrations/create_comments.rb +19 -0
- data/lib/generators/bumble/templates/migrations/create_posts.rb +25 -0
- data/lib/generators/bumble/templates/migrations/create_users.rb +28 -0
- data/lib/generators/bumble/templates/migrations/full_text_search.rb +13 -0
- data/public/stylesheets/sass/bumble.sass +423 -0
- data/public/stylesheets/sass/iphone.sass +79 -0
- data/public/stylesheets/sass/print.sass +2 -0
- data/public/stylesheets/sass/reset.sass +49 -0
- data/test/factories.rb +28 -0
- data/test/functional/comments_controller_test.rb +177 -0
- data/test/functional/password_resets_controller_test.rb +61 -0
- data/test/functional/posts_controller_test.rb +181 -0
- data/test/test_helper.rb +113 -0
- data/test/unit/comment_test.rb +18 -0
- data/test/unit/post_test.rb +18 -0
- data/test/unit/user_test.rb +37 -0
- metadata +403 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
# Be sure to restart your server when you modify this file.
|
2
|
+
|
3
|
+
# Add new inflection rules using the following format
|
4
|
+
# (all these examples are active by default):
|
5
|
+
# ActiveSupport::Inflector.inflections do |inflect|
|
6
|
+
# inflect.plural /^(ox)$/i, '\1en'
|
7
|
+
# inflect.singular /^(ox)en/i, '\1'
|
8
|
+
# inflect.irregular 'person', 'people'
|
9
|
+
# inflect.uncountable %w( fish sheep )
|
10
|
+
# end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
Rails.application.routes.draw do
|
2
|
+
# match 'sitemap.xml' => 'posts#sitemap', :as => :sitemap
|
3
|
+
|
4
|
+
resources :posts do
|
5
|
+
collection do
|
6
|
+
get :search
|
7
|
+
end
|
8
|
+
resources :comments
|
9
|
+
end
|
10
|
+
|
11
|
+
resources :comments do
|
12
|
+
member do
|
13
|
+
get :approve
|
14
|
+
get :reject
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
resources :password_resets
|
19
|
+
resources :users do
|
20
|
+
member do
|
21
|
+
get :delete
|
22
|
+
end
|
23
|
+
end
|
24
|
+
match '/login' => 'user_sessions#new', :as => :login, :via => 'get'
|
25
|
+
match '/logout' => 'user_sessions#destroy', :as => :logout
|
26
|
+
resource :user_session
|
27
|
+
match '/activate/:activation_code' => 'users#activate', :as => :activate
|
28
|
+
root :to => 'posts#index'
|
29
|
+
end
|
data/lib/bumble.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'bumble/version'
|
2
|
+
require 'pathname'
|
3
|
+
require 'rails'
|
4
|
+
require 'haml'
|
5
|
+
require 'authlogic'
|
6
|
+
require 'texticle'
|
7
|
+
require 'will_paginate'
|
8
|
+
require 'gravtastic'
|
9
|
+
require 'dynamic_form'
|
10
|
+
require 'paperclip'
|
11
|
+
require 'rdiscount'
|
12
|
+
require 'akismetor'
|
13
|
+
|
14
|
+
module Bumble
|
15
|
+
class Engine < Rails::Engine
|
16
|
+
config.autoload_paths << File.expand_path("../../app/models/posts", __FILE__)
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
module Bumble
|
2
|
+
class MigrationsGenerator < Rails::Generators::Base
|
3
|
+
|
4
|
+
source_root File.expand_path('../templates', __FILE__)
|
5
|
+
|
6
|
+
include Rails::Generators::Migration
|
7
|
+
|
8
|
+
def generate_migrations
|
9
|
+
generate_migration('create_users')
|
10
|
+
generate_migration('create_posts')
|
11
|
+
generate_migration('create_comments')
|
12
|
+
generate_migration('add_url_to_users')
|
13
|
+
generate_migration('add_delta_to_posts')
|
14
|
+
generate_migration('add_approved_to_comments')
|
15
|
+
generate_migration('add_missing_indexes')
|
16
|
+
generate_migration('create_assets')
|
17
|
+
generate_migration('full_text_search')
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
def generate_migration(name)
|
23
|
+
begin
|
24
|
+
migration_template "migrations/#{name}.rb", "db/migrate/#{name}.rb"
|
25
|
+
sleep 1 # to make sure all migrations have a different number
|
26
|
+
rescue
|
27
|
+
puts "Skiping migration: #{name}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
# Implement the required interface for Rails::Generators::Migration.
|
32
|
+
def self.next_migration_number(dirname) #:nodoc:
|
33
|
+
if ActiveRecord::Base.timestamped_migrations
|
34
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
35
|
+
else
|
36
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
File without changes
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
Binary file
|
@@ -0,0 +1,95 @@
|
|
1
|
+
$(document).ready(function(){
|
2
|
+
// ajax delete
|
3
|
+
$('a.delete').live('click', function(){
|
4
|
+
var elem = $(this);
|
5
|
+
if (confirm("Are you sure?")){
|
6
|
+
$.post($(this).attr('href'), "_method=delete",function(){
|
7
|
+
elem.closest('div').slideUp();
|
8
|
+
});
|
9
|
+
}
|
10
|
+
return false;
|
11
|
+
}).attr("rel", "nofollow");
|
12
|
+
|
13
|
+
// new post form tabs
|
14
|
+
$("#new_post").tabs({cookie: {}});
|
15
|
+
|
16
|
+
if ($.cookie("hide_new_post") == 'false') {
|
17
|
+
$('#new_post').show();
|
18
|
+
$('a.open').hide();
|
19
|
+
}
|
20
|
+
else {
|
21
|
+
$('#new_post').hide();
|
22
|
+
$('a.open').show();
|
23
|
+
}
|
24
|
+
|
25
|
+
$('.ui-tabs-nav').bind('tabsselect', function(event, ui) {
|
26
|
+
$('label.error').remove();
|
27
|
+
$('a.more').show();
|
28
|
+
$('div.more').hide();
|
29
|
+
$('.ui-tabs-nav').hintFields();
|
30
|
+
});
|
31
|
+
|
32
|
+
$('a.open').click(function(){
|
33
|
+
$('a.open').fadeOut();
|
34
|
+
$('#new_post').slideDown();
|
35
|
+
$.cookie("hide_new_post", 'false');
|
36
|
+
return false;
|
37
|
+
});
|
38
|
+
|
39
|
+
$('a.close').click(function(){
|
40
|
+
$('#new_post').slideUp(function(){
|
41
|
+
$('a.open').fadeIn();
|
42
|
+
});
|
43
|
+
$.cookie("hide_new_post", 'true');
|
44
|
+
$('.preview').remove();
|
45
|
+
return false;
|
46
|
+
});
|
47
|
+
|
48
|
+
// extra post options
|
49
|
+
$('#new_post div.more').hide();
|
50
|
+
$('#new_post a.more').click(function(){
|
51
|
+
$('#new_post div.more').slideDown();
|
52
|
+
$(this).hide();
|
53
|
+
return false;
|
54
|
+
});
|
55
|
+
|
56
|
+
// setup validation and ajax post forms
|
57
|
+
$(".new_post").each(function(){
|
58
|
+
$(this).validate({
|
59
|
+
rules: {
|
60
|
+
'video[video_embed]': {
|
61
|
+
required: "#video_link_url:blank"
|
62
|
+
}
|
63
|
+
},
|
64
|
+
submitHandler: function(form){
|
65
|
+
$(form).ajaxSubmit({
|
66
|
+
beforeSubmit: function(){
|
67
|
+
$('.new_post .submit').after('<img src="/images/loading.gif" class="loading" />');
|
68
|
+
$('.new_post :submit').attr('disabled', 'disabled');
|
69
|
+
},
|
70
|
+
complete: function(){
|
71
|
+
$('.loading').remove();
|
72
|
+
$('.new_post :submit').removeAttr('disabled');
|
73
|
+
},
|
74
|
+
success: function(data){
|
75
|
+
$('.preview').remove();
|
76
|
+
$('#posts').prepend(data);
|
77
|
+
if ($('.preview').size() === 0){
|
78
|
+
$(form).resetForm();
|
79
|
+
if ($('.pagination').size() > 0){
|
80
|
+
$('#posts .post:last').remove();
|
81
|
+
}
|
82
|
+
}
|
83
|
+
$(form).hintFields();
|
84
|
+
},
|
85
|
+
error:function(request, textStatus, errorThrown) {
|
86
|
+
var message = (request.status == 401 || request.status == 403) ?
|
87
|
+
request.responseText : "An unknown error occurred. Support has been contacted.";
|
88
|
+
alert(message);
|
89
|
+
}
|
90
|
+
|
91
|
+
});
|
92
|
+
}
|
93
|
+
});
|
94
|
+
});
|
95
|
+
});
|
@@ -0,0 +1,76 @@
|
|
1
|
+
jQuery.fn.hintFields = function(){
|
2
|
+
for (var i = 0, l = this.length; i < l; i++){
|
3
|
+
if (!Modernizr.input.placeholder){ $('input:text', this[i]).hint();}
|
4
|
+
$('textarea', this[i]).hint();
|
5
|
+
}
|
6
|
+
};
|
7
|
+
|
8
|
+
$(document).ready(function(){
|
9
|
+
// validator defaults
|
10
|
+
jQuery.validator.setDefaults({
|
11
|
+
errorPlacement: function(error, element){ error.insertBefore(element); },
|
12
|
+
ignoreTitle: true
|
13
|
+
});
|
14
|
+
|
15
|
+
if ($.browser.webkit){
|
16
|
+
$('input[type="search"]').attr({autosave: location.host, results: 10})
|
17
|
+
}
|
18
|
+
|
19
|
+
// rails ajax setup
|
20
|
+
jQuery.ajaxSetup({
|
21
|
+
'beforeSend': function(xhr){ xhr.setRequestHeader("Accept","text/javascript"); }
|
22
|
+
});
|
23
|
+
|
24
|
+
// crf protection for ajax requests
|
25
|
+
$(document).ajaxSend(function(event, request, settings) {
|
26
|
+
if (typeof(AUTH_TOKEN) == "undefined") {return;}
|
27
|
+
// settings.data is a serialized string like "foo=bar&baz=boink" (or null)
|
28
|
+
settings.data = settings.data || "";
|
29
|
+
settings.data += (settings.data ? "&" : "") + "authenticity_token=" + encodeURIComponent(AUTH_TOKEN);
|
30
|
+
});
|
31
|
+
|
32
|
+
// open external links in a new window
|
33
|
+
$('a[rel="external"]').click( function(){
|
34
|
+
window.open($(this).attr('href'));
|
35
|
+
return false;
|
36
|
+
});
|
37
|
+
|
38
|
+
// text field hints
|
39
|
+
$('form').hintFields();
|
40
|
+
|
41
|
+
// slide open/closed the formatting help div
|
42
|
+
$('a.help').click(function(){
|
43
|
+
$('#formatting').toggle(100);
|
44
|
+
return false;
|
45
|
+
});
|
46
|
+
|
47
|
+
// expanding textareas
|
48
|
+
// $('textarea').simpleautogrow();
|
49
|
+
|
50
|
+
// setup validation and ajax comments forms
|
51
|
+
$(".new_comment").validate({
|
52
|
+
submitHandler: function(form){
|
53
|
+
$(form).ajaxSubmit({
|
54
|
+
beforeSubmit: function(){$('.new_comment input[type="submit"]').after('<img src="/images/loading.gif" class="loading" />');},
|
55
|
+
complete: function(){$('.loading').remove();},
|
56
|
+
success: function(data) {
|
57
|
+
$('#comments').append(data);
|
58
|
+
$('.blank').remove();
|
59
|
+
$(form).resetForm().hintFields();
|
60
|
+
},
|
61
|
+
error:function(request, textStatus, errorThrown) {
|
62
|
+
var message = (request.status == 401 || request.status == 403 || request.status == 406) ?
|
63
|
+
request.responseText : "An unknown error occurred. Support has been contacted.";
|
64
|
+
alert(message);
|
65
|
+
if (request.status == 406) {
|
66
|
+
$(form).resetForm().hintFields();
|
67
|
+
}
|
68
|
+
}
|
69
|
+
});
|
70
|
+
}
|
71
|
+
});
|
72
|
+
|
73
|
+
// fade out flash
|
74
|
+
setTimeout(function(){$(".flash").fadeOut(1000);},10000);
|
75
|
+
|
76
|
+
});
|
@@ -0,0 +1,37 @@
|
|
1
|
+
/*
|
2
|
+
* Simple Auto Expanding Text Area (0.1.2-dev)
|
3
|
+
* by Antti Kaihola (antti.kaihola.fi)
|
4
|
+
* akaihol+jquery@ambitone.com
|
5
|
+
*
|
6
|
+
* Copyright (c) 2009 Antti Kaihola (antti.kaihola.fi)
|
7
|
+
* Licensed under the MIT and BSD licenses.
|
8
|
+
*
|
9
|
+
* NOTE: This script requires jQuery to work. Download jQuery at
|
10
|
+
* www.jquery.com
|
11
|
+
*/
|
12
|
+
|
13
|
+
(function(jQuery) {
|
14
|
+
|
15
|
+
jQuery.fn.simpleautogrow = function() {
|
16
|
+
return this.each(function() { new jQuery.simpleautogrow(this); }); };
|
17
|
+
|
18
|
+
jQuery.simpleautogrow = function (e) {
|
19
|
+
var self = this;
|
20
|
+
var $e = this.textarea = jQuery(e)
|
21
|
+
.css({overflow: 'hidden', display: 'block'})
|
22
|
+
.bind('focus', function() {
|
23
|
+
this.timer = window.setInterval(function() {self.checkExpand(); }, 200); })
|
24
|
+
.bind('blur', function() { clearInterval(this.timer); });
|
25
|
+
this.border = $e.outerHeight() - $e.innerHeight();
|
26
|
+
this.clone = $e.clone().css({position: 'absolute', visibility: 'hidden'}).attr('name', '')
|
27
|
+
$e.height(e.scrollHeight + this.border)
|
28
|
+
.after(this.clone);
|
29
|
+
this.checkExpand(); };
|
30
|
+
|
31
|
+
jQuery.simpleautogrow.prototype.checkExpand = function() {
|
32
|
+
var target_height = this.clone[0].scrollHeight + this.border;
|
33
|
+
if (this.textarea.outerHeight() != target_height)
|
34
|
+
this.textarea.height(target_height + 'px');
|
35
|
+
this.clone.attr('value', this.textarea.attr('value')).height(0); };
|
36
|
+
|
37
|
+
})(jQuery);
|
@@ -0,0 +1,96 @@
|
|
1
|
+
/**
|
2
|
+
* Cookie plugin
|
3
|
+
*
|
4
|
+
* Copyright (c) 2006 Klaus Hartl (stilbuero.de)
|
5
|
+
* Dual licensed under the MIT and GPL licenses:
|
6
|
+
* http://www.opensource.org/licenses/mit-license.php
|
7
|
+
* http://www.gnu.org/licenses/gpl.html
|
8
|
+
*
|
9
|
+
*/
|
10
|
+
|
11
|
+
/**
|
12
|
+
* Create a cookie with the given name and value and other optional parameters.
|
13
|
+
*
|
14
|
+
* @example $.cookie('the_cookie', 'the_value');
|
15
|
+
* @desc Set the value of a cookie.
|
16
|
+
* @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
|
17
|
+
* @desc Create a cookie with all available options.
|
18
|
+
* @example $.cookie('the_cookie', 'the_value');
|
19
|
+
* @desc Create a session cookie.
|
20
|
+
* @example $.cookie('the_cookie', null);
|
21
|
+
* @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
|
22
|
+
* used when the cookie was set.
|
23
|
+
*
|
24
|
+
* @param String name The name of the cookie.
|
25
|
+
* @param String value The value of the cookie.
|
26
|
+
* @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
|
27
|
+
* @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
|
28
|
+
* If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
|
29
|
+
* If set to null or omitted, the cookie will be a session cookie and will not be retained
|
30
|
+
* when the the browser exits.
|
31
|
+
* @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
|
32
|
+
* @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
|
33
|
+
* @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
|
34
|
+
* require a secure protocol (like HTTPS).
|
35
|
+
* @type undefined
|
36
|
+
*
|
37
|
+
* @name $.cookie
|
38
|
+
* @cat Plugins/Cookie
|
39
|
+
* @author Klaus Hartl/klaus.hartl@stilbuero.de
|
40
|
+
*/
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Get the value of a cookie with the given name.
|
44
|
+
*
|
45
|
+
* @example $.cookie('the_cookie');
|
46
|
+
* @desc Get the value of a cookie.
|
47
|
+
*
|
48
|
+
* @param String name The name of the cookie.
|
49
|
+
* @return The value of the cookie.
|
50
|
+
* @type String
|
51
|
+
*
|
52
|
+
* @name $.cookie
|
53
|
+
* @cat Plugins/Cookie
|
54
|
+
* @author Klaus Hartl/klaus.hartl@stilbuero.de
|
55
|
+
*/
|
56
|
+
jQuery.cookie = function(name, value, options) {
|
57
|
+
if (typeof value != 'undefined') { // name and value given, set cookie
|
58
|
+
options = options || {};
|
59
|
+
if (value === null) {
|
60
|
+
value = '';
|
61
|
+
options.expires = -1;
|
62
|
+
}
|
63
|
+
var expires = '';
|
64
|
+
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
|
65
|
+
var date;
|
66
|
+
if (typeof options.expires == 'number') {
|
67
|
+
date = new Date();
|
68
|
+
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
|
69
|
+
} else {
|
70
|
+
date = options.expires;
|
71
|
+
}
|
72
|
+
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
|
73
|
+
}
|
74
|
+
// CAUTION: Needed to parenthesize options.path and options.domain
|
75
|
+
// in the following expressions, otherwise they evaluate to undefined
|
76
|
+
// in the packed version for some reason...
|
77
|
+
var path = options.path ? '; path=' + (options.path) : '';
|
78
|
+
var domain = options.domain ? '; domain=' + (options.domain) : '';
|
79
|
+
var secure = options.secure ? '; secure' : '';
|
80
|
+
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
|
81
|
+
} else { // only name given, get cookie
|
82
|
+
var cookieValue = null;
|
83
|
+
if (document.cookie && document.cookie != '') {
|
84
|
+
var cookies = document.cookie.split(';');
|
85
|
+
for (var i = 0; i < cookies.length; i++) {
|
86
|
+
var cookie = jQuery.trim(cookies[i]);
|
87
|
+
// Does this cookie string begin with the name we want?
|
88
|
+
if (cookie.substring(0, name.length + 1) == (name + '=')) {
|
89
|
+
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
|
90
|
+
break;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
}
|
94
|
+
return cookieValue;
|
95
|
+
}
|
96
|
+
};
|