rails_admin_content 0.1.3 → 0.2.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.
- checksums.yaml +4 -4
- data/README.md +2 -11
- data/app/assets/images/common/backtop.png +0 -0
- data/app/assets/images/common/bg.gif +0 -0
- data/app/assets/images/common/bg_glow.png +0 -0
- data/app/assets/images/common/black_opacity12.png +0 -0
- data/app/assets/images/common/black_opacity20.png +0 -0
- data/app/assets/images/common/header_bg.png +0 -0
- data/app/assets/images/common/header_logo.png +0 -0
- data/app/assets/images/common/header_site.png +0 -0
- data/app/assets/images/common/home_center.png +0 -0
- data/app/assets/images/common/ra_backtop.png +0 -0
- data/app/assets/images/common/ra_tools.png +0 -0
- data/app/assets/images/common/sidebar_ie_bg.png +0 -0
- data/app/assets/images/common/sidebar_search.png +0 -0
- data/app/assets/javascripts/develop/manages.js.coffee +56 -18
- data/app/assets/javascripts/rails_admin_content.js +2 -1
- data/app/assets/stylesheets/develop/application/common.css.sass +780 -0
- data/app/assets/stylesheets/develop/application/forbidden.css.sass +24 -0
- data/app/assets/stylesheets/develop/application/login.css.sass +153 -0
- data/app/assets/stylesheets/develop/application.css.scss +6 -0
- data/app/assets/stylesheets/rails_admin_content.css +3 -5
- data/app/assets/stylesheets/site.css +2 -323
- data/app/controllers/rails_admin_content/develop/manages_controller.rb +1 -0
- data/app/views/layouts/rails_admin_content/admin.html.slim +42 -51
- data/app/views/rails_admin_content/develop/manages/_filter.html.slim +20 -22
- data/app/views/rails_admin_content/develop/manages/_header.html.slim +31 -0
- data/app/views/rails_admin_content/develop/manages/edit.html.slim +13 -15
- data/app/views/rails_admin_content/develop/manages/edit_column.html.slim +1 -1
- data/app/views/rails_admin_content/develop/manages/new.html.slim +10 -10
- data/app/views/rails_admin_content/develop/manages/query.html.slim +3 -2
- data/app/views/rails_admin_content/develop/manages/show.html.slim +24 -24
- data/lib/assets/javascripts/jquery/jquery.color.js +123 -0
- data/lib/assets/javascripts/jquery/jquery.cookie.js +96 -0
- data/lib/rails_admin_content/client.rb +4 -0
- data/lib/rails_admin_content/mysql/adapters/client.rb +2 -0
- data/lib/rails_admin_content/version.rb +1 -1
- metadata +64 -9
- data/app/views/rails_admin_content/develop/manages/_menv.html.slim +0 -8
- data/app/views/rails_admin_content/develop/manages/_navbar.html.slim +0 -27
- data/lib/assets/codemirror/charisma-app.css +0 -501
- data/lib/assets/codemirror/matchbrackets.js +0 -82
- data/lib/assets/codemirror/solarized.css +0 -207
- data/lib/assets/codemirror/twilight.css +0 -26
- data/lib/assets/javascripts/bootstrap/bootstrap-alert.js +0 -100
@@ -1,58 +1,49 @@
|
|
1
1
|
doctype html
|
2
2
|
html
|
3
3
|
head
|
4
|
-
|
5
|
-
|
4
|
+
meta http-equiv="Content-Type" content="text/html; charset=utf-8"
|
5
|
+
title Rails Admin
|
6
6
|
= stylesheet_link_tag "rails_admin_content", media: "all"
|
7
7
|
= javascript_include_tag 'rails_admin_content'
|
8
8
|
= csrf_meta_tag
|
9
|
-
body
|
10
|
-
#
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
=
|
9
|
+
body.bgcolor16
|
10
|
+
#body.railsadmin
|
11
|
+
= render 'header'
|
12
|
+
.Container
|
13
|
+
.sidebar
|
14
|
+
.searchbox
|
15
|
+
form
|
16
|
+
.search
|
17
|
+
input.text type="text" value="" id="seaerch-T" placeholder="搜索文档"
|
18
|
+
input.submit type="submit" title="搜索文档" value="" onclick="return false"
|
19
|
+
.section
|
20
|
+
/ h3 账号
|
21
|
+
ul.link_list
|
22
|
+
- RailsAdminContent::Client.get_tables.each do |table|
|
23
|
+
li data-field="#{table.values.first}"
|
24
|
+
= link_to table.values.first.to_s.truncate(30), develop_manage_path(table.values.first), title: "[#{table.keys.first}] #{table.values.first}", class: "#{'current' if params[:id] == table.values.first}"
|
25
|
+
.main
|
26
|
+
.section
|
27
|
+
- if action_name =~ /show/
|
28
|
+
h1
|
29
|
+
= params[:id]
|
30
|
+
.formbox
|
31
|
+
= render 'filter'
|
32
|
+
- if action_name =~ /query/
|
33
|
+
h1
|
34
|
+
.formbox
|
35
|
+
= render 'form'
|
36
|
+
= yield
|
24
37
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
.
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
= flash[:notice]
|
38
|
-
.container-fluid
|
39
|
-
.row-fluid
|
40
|
-
.span2
|
41
|
-
= render 'menv'
|
42
|
-
.content.span10
|
43
|
-
|
44
|
-
- if action_name =~ /show/
|
45
|
-
= render 'filter'
|
46
|
-
- elsif action_name =~ /query/
|
47
|
-
= render 'form'
|
48
|
-
.span11 style="width:100%;margin: 0px;"
|
49
|
-
= yield
|
50
|
-
- if @entries.present?
|
51
|
-
#edit_tools
|
52
|
-
span
|
53
|
-
label 当前选择<span id="select_num">0</span>条
|
54
|
-
span
|
55
|
-
= link_to 'ⓧ', "#", class: 'btn deselect', title: '取消选择'
|
56
|
-
= link_to '✘', "", class: 'btn', title: '删除', disabled: true, id: "btn_delete"
|
57
|
-
span
|
58
|
-
= @entries.present? ? custom_paginate(@entries, spage: @page, stint: @per) : '0条数据'
|
38
|
+
.clear
|
39
|
+
.ra_tools
|
40
|
+
.fadeout
|
41
|
+
.tools_box
|
42
|
+
.manipulate
|
43
|
+
- if action_name =~ /show/
|
44
|
+
= link_to '+', new_develop_manage_path(id: RailsAdminContent::Client.table_name),class: 'tool_01'
|
45
|
+
= link_to '-', "", class: 'tool_02', title: '删除', id: 'btn_del'
|
46
|
+
/ a.tool_02 href="#" -
|
47
|
+
/ a.tool_03 href="#" v
|
48
|
+
= custom_paginate(@entries, spage: @page, stint: @per) if @entries.present?
|
49
|
+
a.layout_scrolltop id="layout_scrolltop" style="visibility: visible;"
|
@@ -1,25 +1,23 @@
|
|
1
1
|
.span12
|
2
|
-
.
|
3
|
-
|
4
|
-
= hidden_field_tag 'current_condition', params[:calc].present? && params[:calc].keys.join(",")
|
5
|
-
= form_tag "", method: :post, class: 'form-search', method: :get
|
2
|
+
= hidden_field_tag 'current_condition', params[:calc].present? && params[:calc].keys.join(",")
|
3
|
+
= form_tag "", method: :post, class: 'form-search', method: :get
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
5
|
+
- RailsAdminContent::Client.desc_table(params[:id]).each do |column|
|
6
|
+
div class="span7 #{column["Field"]} check_edit" style="#{params[:calc].present? && params[:calc].has_key?(column["Field"]) ? '' : 'display:none;' }"
|
7
|
+
.span4
|
8
|
+
= label_tag do
|
9
|
+
= check_box_tag "check_box[#{column['Field']}]", '', true, class: 'check_box_edit', name: '', 'data-field' => column['Field']
|
10
|
+
|
|
11
|
+
= column["Field"]
|
12
|
+
.span3
|
13
|
+
= select_tag "calc[#{column['Field']}]", options_for_select(RailsAdminContent::Client.select_field(column["Type"]), params[:calc].present? ? params[:calc][column['Field']] : nil), 'data-field' => "calc[#{column['Field']}]", class: 'span6 calc'
|
14
|
+
.span3
|
15
|
+
- column["Type"] = 'varchar' if column["Type"] == 'text'
|
16
|
+
- column["Default"] = params[:field][column["Field"]] if params[:field].present?
|
17
|
+
= content_field(column)
|
20
18
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
.span8
|
20
|
+
= field_set_tag "Selection" do
|
21
|
+
= select_tag 'select_field', options_for_select_column_data(params[:id]), class: 'span2', name: '', :prompt => "Select Filter"
|
22
|
+
= button_tag 'Apply', class: 'btn'
|
23
|
+
= link_to 'Clear', '#', class: 'btn clear'
|
@@ -0,0 +1,31 @@
|
|
1
|
+
css:
|
2
|
+
body{
|
3
|
+
font-family: "Microsoft YaHei",'微软雅黑',msyh;
|
4
|
+
}
|
5
|
+
.HeaderContainer
|
6
|
+
a.logo title="Home"
|
7
|
+
ul.topbar
|
8
|
+
li
|
9
|
+
= link_to 'Home', develop_manages_path, class: "#{'current' if action_name =~ /index/}", title: 'Home'
|
10
|
+
- unless action_name =~ /index|query/
|
11
|
+
li
|
12
|
+
= link_to 'Content', develop_manage_path(RailsAdminContent::Client.table_name), class: "#{ 'current' if action_name =~ /show/ && controller_name =~ /manages/ }", title: 'Content'
|
13
|
+
li
|
14
|
+
= link_to 'Structure', edit_column_develop_manage_path(RailsAdminContent::Client.table_name), class: "#{ 'current' if action_name =~ /edit_column/ && controller_name =~ /manages/ }", title: 'Structure'
|
15
|
+
|
16
|
+
li
|
17
|
+
= link_to 'Table', details_develop_manage_path(RailsAdminContent::Client.table_name), class: "#{ 'current' if action_name =~ /details/ && controller_name =~ /manages/ }", title: 'Table info'
|
18
|
+
li
|
19
|
+
= link_to 'Query', query_develop_manages_path, class: 'btn-icon', title: 'Query'
|
20
|
+
a Help
|
21
|
+
.userinfo
|
22
|
+
ul
|
23
|
+
li.site
|
24
|
+
a.set title="设置"
|
25
|
+
.sitebox
|
26
|
+
.list
|
27
|
+
- (1...20).each do |i|
|
28
|
+
=link_to "bgcolor#{i}", '#', class: "color bgcolor#{i}"
|
29
|
+
.hr
|
30
|
+
.sitesignout
|
31
|
+
= link_to 'Sign out'
|
@@ -1,17 +1,15 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
= form_tag(develop_manage_path(params[:id]), method: :put)
|
4
|
-
=
|
5
|
-
|
6
|
-
|
7
|
-
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
h1
|
2
|
+
= params[:table_name]
|
3
|
+
= form_tag(develop_manage_path(params[:id]), method: :put, class: 'formbox formitem')
|
4
|
+
= hidden_field_tag 'table_name', params[:table_name]
|
5
|
+
- columns = RailsAdminContent::Client.conn.origin_query("DESC #{params[:table_name]}").each
|
6
|
+
- RailsAdminContent::Client.conn.origin_query("SELECT * FROM #{params[:table_name]} WHERE id = #{params[:id]}").each[0].map do |key,value|
|
7
|
+
- if key == "id"
|
8
|
+
= hidden_field_tag :id, value
|
9
|
+
- else
|
10
|
+
fieldset
|
11
11
|
= label_tag "field[#{key}]", key
|
12
12
|
= content_field(columns.select{|c| c["Field"] == key }.first ,value)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
.span2
|
17
|
-
= link_to 'Back', :back, class: 'btn'
|
13
|
+
fieldset.ff-item-top
|
14
|
+
= submit_tag 'Save'
|
15
|
+
= link_to 'Back', :back
|
@@ -1,10 +1,10 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
1
|
+
h1
|
2
|
+
= params[:id]
|
3
|
+
= form_tag develop_manages_path, class: "formbox formitem"
|
4
|
+
= hidden_field_tag 'table_name', params[:id]
|
5
|
+
- RailsAdminContent::Client.conn.origin_query("DESC #{params[:id]}").each.map do |column|
|
6
|
+
- next if column["Field"] == "id"
|
7
|
+
= label_tag "field[#{column["Field"]}]", column["Field"]
|
8
|
+
= content_field column
|
9
|
+
.controllers
|
10
|
+
= submit_tag 'Save', class: 'btn btn-primary'
|
@@ -1,5 +1,5 @@
|
|
1
1
|
- if @entries.present? && @entries.first
|
2
|
-
.
|
2
|
+
.tablescroll
|
3
3
|
| #{@content}
|
4
4
|
.details#grid_search
|
5
5
|
form action="#{develop_manage_path(RailsAdminContent::Client.table_name)}" method="delete" id="details_form" remote="true"
|
@@ -7,7 +7,8 @@
|
|
7
7
|
table#edit_tables.table-bordered.table.table-hover
|
8
8
|
thead
|
9
9
|
tr#th-title
|
10
|
-
th
|
10
|
+
th
|
11
|
+
input type="checkbox" class="checkbox toggle" id="toggle_check"
|
11
12
|
- @entries.first.keys.each do |entry|
|
12
13
|
th
|
13
14
|
= entry
|
@@ -1,27 +1,27 @@
|
|
1
1
|
|
2
|
-
.
|
2
|
+
.tablescroll
|
3
3
|
| #{@content}
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
4
|
+
form action="#{develop_manage_path(params[:id])}" method="delete" id="details_form" remote="true"
|
5
|
+
input type="hidden" value="#{RailsAdminContent::Client.table_name}" name="table_name"
|
6
|
+
table.table
|
7
|
+
thead
|
8
|
+
tr#th-title
|
9
|
+
th
|
10
|
+
input type="checkbox" class="checkbox toggle" id="toggle_check" checked=""
|
11
|
+
- @fields.map do |element|
|
12
|
+
th
|
13
|
+
= element["Field"]
|
14
|
+
- if @entries.present? && @entries.first
|
15
|
+
tbody
|
16
|
+
- @entries.each do |content|
|
17
|
+
tr class="tr_#{content.first[1]}"
|
18
|
+
td
|
19
|
+
label
|
20
|
+
input type="checkbox" class="edit_checkbox" value="#{content.first[1]}" name="edit_id[]"
|
21
|
+
- content.each do |key,value|
|
18
22
|
td
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
- if key == "id"
|
25
|
-
= link_to value, edit_develop_manage_path(value,table_name: RailsAdminContent::Client.table_name), title: 'edit'
|
26
|
-
- else
|
27
|
-
= format(value)
|
23
|
+
span class="#{edited(key,value)}" data-field="#{key}" data-table="#{RailsAdminContent::Client.table_name}" data-title="#{value}" data-url="#{update_field_develop_manage_path(content.values.first)}"
|
24
|
+
- if key == "id"
|
25
|
+
= link_to value, edit_develop_manage_path(value,table_name: RailsAdminContent::Client.table_name), title: 'edit'
|
26
|
+
- else
|
27
|
+
= format(value)
|
@@ -0,0 +1,123 @@
|
|
1
|
+
/*
|
2
|
+
* jQuery Color Animations
|
3
|
+
* Copyright 2007 John Resig
|
4
|
+
* Released under the MIT and GPL licenses.
|
5
|
+
*/
|
6
|
+
|
7
|
+
(function(jQuery){
|
8
|
+
|
9
|
+
// We override the animation for all of these color styles
|
10
|
+
jQuery.each(['backgroundColor', 'borderBottomColor', 'borderLeftColor', 'borderRightColor', 'borderTopColor', 'color', 'outlineColor'], function(i,attr){
|
11
|
+
jQuery.fx.step[attr] = function(fx){
|
12
|
+
if ( fx.state == 0 ) {
|
13
|
+
fx.start = getColor( fx.elem, attr );
|
14
|
+
fx.end = getRGB( fx.end );
|
15
|
+
}
|
16
|
+
|
17
|
+
fx.elem.style[attr] = "rgb(" + [
|
18
|
+
Math.max(Math.min( parseInt((fx.pos * (fx.end[0] - fx.start[0])) + fx.start[0]), 255), 0),
|
19
|
+
Math.max(Math.min( parseInt((fx.pos * (fx.end[1] - fx.start[1])) + fx.start[1]), 255), 0),
|
20
|
+
Math.max(Math.min( parseInt((fx.pos * (fx.end[2] - fx.start[2])) + fx.start[2]), 255), 0)
|
21
|
+
].join(",") + ")";
|
22
|
+
}
|
23
|
+
});
|
24
|
+
|
25
|
+
// Color Conversion functions from highlightFade
|
26
|
+
// By Blair Mitchelmore
|
27
|
+
// http://jquery.offput.ca/highlightFade/
|
28
|
+
|
29
|
+
// Parse strings looking for color tuples [255,255,255]
|
30
|
+
function getRGB(color) {
|
31
|
+
var result;
|
32
|
+
|
33
|
+
// Check if we're already dealing with an array of colors
|
34
|
+
if ( color && color.constructor == Array && color.length == 3 )
|
35
|
+
return color;
|
36
|
+
|
37
|
+
// Look for rgb(num,num,num)
|
38
|
+
if (result = /rgb\(\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*,\s*([0-9]{1,3})\s*\)/.exec(color))
|
39
|
+
return [parseInt(result[1]), parseInt(result[2]), parseInt(result[3])];
|
40
|
+
|
41
|
+
// Look for rgb(num%,num%,num%)
|
42
|
+
if (result = /rgb\(\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*,\s*([0-9]+(?:\.[0-9]+)?)\%\s*\)/.exec(color))
|
43
|
+
return [parseFloat(result[1])*2.55, parseFloat(result[2])*2.55, parseFloat(result[3])*2.55];
|
44
|
+
|
45
|
+
// Look for #a0b1c2
|
46
|
+
if (result = /#([a-fA-F0-9]{2})([a-fA-F0-9]{2})([a-fA-F0-9]{2})/.exec(color))
|
47
|
+
return [parseInt(result[1],16), parseInt(result[2],16), parseInt(result[3],16)];
|
48
|
+
|
49
|
+
// Look for #fff
|
50
|
+
if (result = /#([a-fA-F0-9])([a-fA-F0-9])([a-fA-F0-9])/.exec(color))
|
51
|
+
return [parseInt(result[1]+result[1],16), parseInt(result[2]+result[2],16), parseInt(result[3]+result[3],16)];
|
52
|
+
|
53
|
+
// Otherwise, we're most likely dealing with a named color
|
54
|
+
return colors[jQuery.trim(color).toLowerCase()];
|
55
|
+
}
|
56
|
+
|
57
|
+
function getColor(elem, attr) {
|
58
|
+
var color;
|
59
|
+
|
60
|
+
do {
|
61
|
+
color = jQuery.curCSS(elem, attr);
|
62
|
+
|
63
|
+
// Keep going until we find an element that has color, or we hit the body
|
64
|
+
if ( color != '' && color != 'transparent' || jQuery.nodeName(elem, "body") )
|
65
|
+
break;
|
66
|
+
|
67
|
+
attr = "backgroundColor";
|
68
|
+
} while ( elem = elem.parentNode );
|
69
|
+
|
70
|
+
return getRGB(color);
|
71
|
+
};
|
72
|
+
|
73
|
+
// Some named colors to work with
|
74
|
+
// From Interface by Stefan Petre
|
75
|
+
// http://interface.eyecon.ro/
|
76
|
+
|
77
|
+
var colors = {
|
78
|
+
aqua:[0,255,255],
|
79
|
+
azure:[240,255,255],
|
80
|
+
beige:[245,245,220],
|
81
|
+
black:[0,0,0],
|
82
|
+
blue:[0,0,255],
|
83
|
+
brown:[165,42,42],
|
84
|
+
cyan:[0,255,255],
|
85
|
+
darkblue:[0,0,139],
|
86
|
+
darkcyan:[0,139,139],
|
87
|
+
darkgrey:[169,169,169],
|
88
|
+
darkgreen:[0,100,0],
|
89
|
+
darkkhaki:[189,183,107],
|
90
|
+
darkmagenta:[139,0,139],
|
91
|
+
darkolivegreen:[85,107,47],
|
92
|
+
darkorange:[255,140,0],
|
93
|
+
darkorchid:[153,50,204],
|
94
|
+
darkred:[139,0,0],
|
95
|
+
darksalmon:[233,150,122],
|
96
|
+
darkviolet:[148,0,211],
|
97
|
+
fuchsia:[255,0,255],
|
98
|
+
gold:[255,215,0],
|
99
|
+
green:[0,128,0],
|
100
|
+
indigo:[75,0,130],
|
101
|
+
khaki:[240,230,140],
|
102
|
+
lightblue:[173,216,230],
|
103
|
+
lightcyan:[224,255,255],
|
104
|
+
lightgreen:[144,238,144],
|
105
|
+
lightgrey:[211,211,211],
|
106
|
+
lightpink:[255,182,193],
|
107
|
+
lightyellow:[255,255,224],
|
108
|
+
lime:[0,255,0],
|
109
|
+
magenta:[255,0,255],
|
110
|
+
maroon:[128,0,0],
|
111
|
+
navy:[0,0,128],
|
112
|
+
olive:[128,128,0],
|
113
|
+
orange:[255,165,0],
|
114
|
+
pink:[255,192,203],
|
115
|
+
purple:[128,0,128],
|
116
|
+
violet:[128,0,128],
|
117
|
+
red:[255,0,0],
|
118
|
+
silver:[192,192,192],
|
119
|
+
white:[255,255,255],
|
120
|
+
yellow:[255,255,0]
|
121
|
+
};
|
122
|
+
|
123
|
+
})(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
|
+
};
|