state_pattern 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +8 -4
- data/examples/rails_3_button_example/script/rails +0 -0
- data/examples/rails_4_button_example/Gemfile +46 -0
- data/examples/rails_4_button_example/Gemfile.lock +157 -0
- data/examples/rails_4_button_example/README.rdoc +28 -0
- data/examples/{rails_2_3_8_button_example → rails_4_button_example}/Rakefile +2 -6
- data/examples/rails_4_button_example/app/assets/javascripts/application.js +16 -0
- data/examples/rails_4_button_example/app/assets/stylesheets/application.css +15 -0
- data/examples/rails_4_button_example/app/controllers/application_controller.rb +5 -0
- data/examples/{rails_2_3_8_button_example → rails_4_button_example}/app/controllers/buttons_controller.rb +3 -8
- data/examples/rails_4_button_example/app/helpers/application_helper.rb +2 -0
- data/examples/{rails_2_3_8_button_example → rails_4_button_example}/app/models/button.rb +0 -0
- data/examples/{rails_2_3_8_button_example → rails_4_button_example}/app/models/button/off.rb +0 -0
- data/examples/{rails_2_3_8_button_example → rails_4_button_example}/app/models/button/on.rb +0 -0
- data/examples/rails_4_button_example/app/views/buttons/_form.html.erb +21 -0
- data/examples/rails_4_button_example/app/views/buttons/edit.html.erb +6 -0
- data/examples/rails_4_button_example/app/views/buttons/index.html.erb +23 -0
- data/examples/rails_4_button_example/app/views/buttons/new.html.erb +5 -0
- data/examples/{rails_2_3_8_button_example → rails_4_button_example}/app/views/buttons/show.html.erb +1 -1
- data/examples/rails_4_button_example/app/views/layouts/application.html.erb +12 -0
- data/examples/rails_4_button_example/bin/bundle +3 -0
- data/examples/rails_4_button_example/bin/rails +8 -0
- data/examples/rails_4_button_example/bin/rake +8 -0
- data/examples/rails_4_button_example/bin/setup +29 -0
- data/examples/rails_4_button_example/bin/spring +15 -0
- data/examples/rails_4_button_example/config.ru +4 -0
- data/examples/rails_4_button_example/config/application.rb +26 -0
- data/examples/rails_4_button_example/config/boot.rb +3 -0
- data/examples/{rails_2_3_8_button_example → rails_4_button_example}/config/database.yml +0 -0
- data/examples/rails_4_button_example/config/environment.rb +5 -0
- data/examples/rails_4_button_example/config/environments/development.rb +41 -0
- data/examples/rails_4_button_example/config/environments/production.rb +79 -0
- data/examples/rails_4_button_example/config/environments/test.rb +42 -0
- data/examples/rails_4_button_example/config/initializers/assets.rb +11 -0
- data/examples/{rails_2_3_8_button_example → rails_4_button_example}/config/initializers/backtrace_silencers.rb +2 -2
- data/examples/rails_4_button_example/config/initializers/cookies_serializer.rb +3 -0
- data/examples/rails_4_button_example/config/initializers/filter_parameter_logging.rb +4 -0
- data/examples/rails_4_button_example/config/initializers/inflections.rb +16 -0
- data/examples/{rails_2_3_8_button_example → rails_4_button_example}/config/initializers/mime_types.rb +0 -1
- data/examples/rails_4_button_example/config/initializers/session_store.rb +3 -0
- data/examples/rails_4_button_example/config/initializers/wrap_parameters.rb +14 -0
- data/examples/rails_4_button_example/config/locales/en.yml +23 -0
- data/examples/rails_4_button_example/config/routes.rb +5 -0
- data/examples/rails_4_button_example/config/secrets.yml +22 -0
- data/examples/{rails_3_button_example → rails_4_button_example}/db/development.sqlite3 +0 -0
- data/examples/rails_4_button_example/db/schema.rb +21 -0
- data/examples/{rails_2_3_8_button_example → rails_4_button_example}/db/seeds.rb +3 -3
- data/examples/rails_4_button_example/db/test.sqlite3 +0 -0
- data/examples/rails_4_button_example/public/404.html +67 -0
- data/examples/rails_4_button_example/public/422.html +67 -0
- data/examples/rails_4_button_example/public/500.html +66 -0
- data/examples/rails_4_button_example/public/favicon.ico +0 -0
- data/examples/rails_4_button_example/public/robots.txt +5 -0
- data/examples/rails_4_button_example/test/test_helper.rb +10 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/0BJF3aE6L9I-CdqfM1vkFjpFBWqYfezN_FW0Lj8RF4A.cache +2 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/25cnngfH_LUdZUzCkWGHXzOa7gYAIbK1KokOftWRmAQ.cache +0 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/3hl1sZkns5ee8V-i-WR-XsJ9Q1Eb8R4ae2xOpLheBN0.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/AgXtbwKSwhtftp5wI3VQUtwmz6kB4r6m75W7b-iFYZ4.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/BRmY2myye-FTQX-95MjIHm2DL2xKXJlLcGl7Xh1lE_I.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/D4INSAJh2MuaZXOe1khQPTL-_wxRvNDwJb3gTkgnye4.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/ESVS2t_92m256UsCWPucHsMgAf3mK8kYdKuc1047Lwo.cache +3 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/GpmXMnR78YiAOw85MO8NNmw2iLQ79-a_9GExT6Vt0lI.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/GyoBO1Lr-5cRy5clwoTZ5p1jZFNLHymE44cE0tlBKFY.cache +0 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/IEoe5zOhmWy0JaBQe7z0EuqQ7QyiWkdBzstXZjsEKZo.cache +0 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/ISkwmSSt8rrkdRL1GwBn9o4ILWaNnOJyixxf4RX94z4.cache +2 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/Im0488zfiXCJH-KMbI4A7h6A1rax9XpKQnC3DFko1Tg.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/LiJ9_nrPkr74731F6YeBknQUCRFqzKeo-P1LntAfTl8.cache +2 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/N7RuW5y7R05Kmq0ismjda4wp0u1UCLE5TqStjtASNMU.cache +0 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/OuEnX_z_G8Ja1YbbCjd5aQ9O9ry06I8X0EKCdZ0GO04.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/TMI1rsUDvy6QDgEC4o39T2vtzA2PbuzLav-J4rCXSuM.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/VT3u8_h-fkin9_cEH_E8D6BLsz_3vEtZF2KwWX3RZE8.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/X7l7HU-zo5WW5WmIJE9MnY5wKmCphQiqiI0l00JWUA4.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/XU4CHJPKIryEop9D5jhiVfnW-9F5Cxzujoa6zwA9egE.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/aOzh5w6UU36ks31JV_onH2aPBTI5dFTF-zF7-vvKK1c.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/bMj6M9wSBtZfHLG65eW2u9NINz-F2yWF0wvJnx5xBpg.cache +0 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/c8UWC3Xah91Ham9SSBwpt2O02vgnSIUTWNiCyfI5YJ8.cache +2 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/dHBwAzZ_u-AXSdVdNW0B7bIzniKy2EAWcNcrvMTxh_k.cache +2 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/fZ12J5mB4ihVvZDBTocYdXAen7YEXjkzDkaqa3D1mI8.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/fnePkpq2OgSfrlujhk1_fNG6kjuMZ61mDG0c0Ivit9U.cache +0 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/g0XgcH-GeMIj0lwPaHV5IqDcQzJvnR3Xw_8dg0DBVho.cache +0 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/iGYHI6OqKX0w3ivvIXR-boAWL5x81VEM_GqoNJCBr6s.cache +0 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/l4fHH1Zo47D2G0zAnbfyDyaxlUq4_R6O1R_xNoqmHhw.cache +0 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/mKQKN_P_8jYD-Q80hhjvo4e3LImaXAMIThYLqa9Apvw.cache +0 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/mWqYee_LlZoGLCIvrCNU_U1gCixLtE_1c-aRqNkooZE.cache +2 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/my8kgZGxmOFYs4sBIlBx4mPLa3-bz0D1PfUl737ixlU.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/nW-hLkhpsu1Zh2w1u0dXHVkdIslZUKkcvE8CLVIW62Y.cache +0 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/p_8FlTUmjyxhzHW7PiP9gJydL0GWbtF7zMAsolZQt7s.cache +0 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/sRmbkRkNO0Rz5igafyTEwypjH6THAj7wiv24NFKOouw.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/uHtYDCLtnVci3xvC8mW10dfUdR20jK-cAPNTSx-uWBg.cache +0 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/vWSj4lAxWQ9AJD4chDHnsj4iDBTcPAQKSVOIqHe_4Pg.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/ychj6_LlHUXHJTPKIinw5cIDiTrudXh6MR_7zO-kpAw.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/zh122yIBAuJyzL1VU2PIldcpbQl7ecXz-EmuWGZYFrk.cache +1 -0
- data/examples/rails_4_button_example/tmp/cache/assets/development/sprockets/v3.0/zo647VN_kDb913bXE7Ta0qarVlYZJ2iCgNNAmquQftQ.cache +0 -0
- data/lib/state_pattern/active_record.rb +1 -1
- data/test/state_pattern/active_record/active_record_test.rb +1 -0
- data/test/test_helper.rb +2 -5
- metadata +309 -233
- data/examples/rails_2_3_8_button_example/README +0 -243
- data/examples/rails_2_3_8_button_example/app/controllers/application_controller.rb +0 -2
- data/examples/rails_2_3_8_button_example/app/helpers/application_helper.rb +0 -3
- data/examples/rails_2_3_8_button_example/app/views/layouts/application.html.erb +0 -12
- data/examples/rails_2_3_8_button_example/config/boot.rb +0 -110
- data/examples/rails_2_3_8_button_example/config/environment.rb +0 -41
- data/examples/rails_2_3_8_button_example/config/environments/development.rb +0 -17
- data/examples/rails_2_3_8_button_example/config/environments/production.rb +0 -28
- data/examples/rails_2_3_8_button_example/config/environments/test.rb +0 -28
- data/examples/rails_2_3_8_button_example/config/initializers/cookie_verification_secret.rb +0 -7
- data/examples/rails_2_3_8_button_example/config/initializers/inflections.rb +0 -10
- data/examples/rails_2_3_8_button_example/config/initializers/new_rails_defaults.rb +0 -21
- data/examples/rails_2_3_8_button_example/config/initializers/session_store.rb +0 -15
- data/examples/rails_2_3_8_button_example/config/locales/en.yml +0 -5
- data/examples/rails_2_3_8_button_example/config/routes.rb +0 -4
- data/examples/rails_2_3_8_button_example/db/development.sqlite3 +0 -0
- data/examples/rails_2_3_8_button_example/db/migrate/20101009073737_create_buttons.rb +0 -13
- data/examples/rails_2_3_8_button_example/db/schema.rb +0 -20
- data/examples/rails_2_3_8_button_example/db/test.sqlite3 +0 -0
- data/examples/rails_2_3_8_button_example/doc/README_FOR_APP +0 -2
- data/examples/rails_2_3_8_button_example/public/images/rails.png +0 -0
- data/examples/rails_2_3_8_button_example/public/javascripts/application.js +0 -2
- data/examples/rails_2_3_8_button_example/public/javascripts/controls.js +0 -963
- data/examples/rails_2_3_8_button_example/public/javascripts/dragdrop.js +0 -973
- data/examples/rails_2_3_8_button_example/public/javascripts/effects.js +0 -1128
- data/examples/rails_2_3_8_button_example/public/javascripts/prototype.js +0 -4320
- data/examples/rails_2_3_8_button_example/public/javascripts/rails.js +0 -175
- data/examples/rails_2_3_8_button_example/script/about +0 -4
- data/examples/rails_2_3_8_button_example/script/console +0 -3
- data/examples/rails_2_3_8_button_example/script/dbconsole +0 -3
- data/examples/rails_2_3_8_button_example/script/destroy +0 -3
- data/examples/rails_2_3_8_button_example/script/generate +0 -3
- data/examples/rails_2_3_8_button_example/script/performance/benchmarker +0 -3
- data/examples/rails_2_3_8_button_example/script/performance/profiler +0 -3
- data/examples/rails_2_3_8_button_example/script/plugin +0 -3
- data/examples/rails_2_3_8_button_example/script/runner +0 -3
- data/examples/rails_2_3_8_button_example/script/server +0 -3
@@ -1,175 +0,0 @@
|
|
1
|
-
(function() {
|
2
|
-
// Technique from Juriy Zaytsev
|
3
|
-
// http://thinkweb2.com/projects/prototype/detecting-event-support-without-browser-sniffing/
|
4
|
-
function isEventSupported(eventName) {
|
5
|
-
var el = document.createElement('div');
|
6
|
-
eventName = 'on' + eventName;
|
7
|
-
var isSupported = (eventName in el);
|
8
|
-
if (!isSupported) {
|
9
|
-
el.setAttribute(eventName, 'return;');
|
10
|
-
isSupported = typeof el[eventName] == 'function';
|
11
|
-
}
|
12
|
-
el = null;
|
13
|
-
return isSupported;
|
14
|
-
}
|
15
|
-
|
16
|
-
function isForm(element) {
|
17
|
-
return Object.isElement(element) && element.nodeName.toUpperCase() == 'FORM'
|
18
|
-
}
|
19
|
-
|
20
|
-
function isInput(element) {
|
21
|
-
if (Object.isElement(element)) {
|
22
|
-
var name = element.nodeName.toUpperCase()
|
23
|
-
return name == 'INPUT' || name == 'SELECT' || name == 'TEXTAREA'
|
24
|
-
}
|
25
|
-
else return false
|
26
|
-
}
|
27
|
-
|
28
|
-
var submitBubbles = isEventSupported('submit'),
|
29
|
-
changeBubbles = isEventSupported('change')
|
30
|
-
|
31
|
-
if (!submitBubbles || !changeBubbles) {
|
32
|
-
// augment the Event.Handler class to observe custom events when needed
|
33
|
-
Event.Handler.prototype.initialize = Event.Handler.prototype.initialize.wrap(
|
34
|
-
function(init, element, eventName, selector, callback) {
|
35
|
-
init(element, eventName, selector, callback)
|
36
|
-
// is the handler being attached to an element that doesn't support this event?
|
37
|
-
if ( (!submitBubbles && this.eventName == 'submit' && !isForm(this.element)) ||
|
38
|
-
(!changeBubbles && this.eventName == 'change' && !isInput(this.element)) ) {
|
39
|
-
// "submit" => "emulated:submit"
|
40
|
-
this.eventName = 'emulated:' + this.eventName
|
41
|
-
}
|
42
|
-
}
|
43
|
-
)
|
44
|
-
}
|
45
|
-
|
46
|
-
if (!submitBubbles) {
|
47
|
-
// discover forms on the page by observing focus events which always bubble
|
48
|
-
document.on('focusin', 'form', function(focusEvent, form) {
|
49
|
-
// special handler for the real "submit" event (one-time operation)
|
50
|
-
if (!form.retrieve('emulated:submit')) {
|
51
|
-
form.on('submit', function(submitEvent) {
|
52
|
-
var emulated = form.fire('emulated:submit', submitEvent, true)
|
53
|
-
// if custom event received preventDefault, cancel the real one too
|
54
|
-
if (emulated.returnValue === false) submitEvent.preventDefault()
|
55
|
-
})
|
56
|
-
form.store('emulated:submit', true)
|
57
|
-
}
|
58
|
-
})
|
59
|
-
}
|
60
|
-
|
61
|
-
if (!changeBubbles) {
|
62
|
-
// discover form inputs on the page
|
63
|
-
document.on('focusin', 'input, select, texarea', function(focusEvent, input) {
|
64
|
-
// special handler for real "change" events
|
65
|
-
if (!input.retrieve('emulated:change')) {
|
66
|
-
input.on('change', function(changeEvent) {
|
67
|
-
input.fire('emulated:change', changeEvent, true)
|
68
|
-
})
|
69
|
-
input.store('emulated:change', true)
|
70
|
-
}
|
71
|
-
})
|
72
|
-
}
|
73
|
-
|
74
|
-
function handleRemote(element) {
|
75
|
-
var method, url, params;
|
76
|
-
|
77
|
-
var event = element.fire("ajax:before");
|
78
|
-
if (event.stopped) return false;
|
79
|
-
|
80
|
-
if (element.tagName.toLowerCase() === 'form') {
|
81
|
-
method = element.readAttribute('method') || 'post';
|
82
|
-
url = element.readAttribute('action');
|
83
|
-
params = element.serialize();
|
84
|
-
} else {
|
85
|
-
method = element.readAttribute('data-method') || 'get';
|
86
|
-
url = element.readAttribute('href');
|
87
|
-
params = {};
|
88
|
-
}
|
89
|
-
|
90
|
-
new Ajax.Request(url, {
|
91
|
-
method: method,
|
92
|
-
parameters: params,
|
93
|
-
evalScripts: true,
|
94
|
-
|
95
|
-
onComplete: function(request) { element.fire("ajax:complete", request); },
|
96
|
-
onSuccess: function(request) { element.fire("ajax:success", request); },
|
97
|
-
onFailure: function(request) { element.fire("ajax:failure", request); }
|
98
|
-
});
|
99
|
-
|
100
|
-
element.fire("ajax:after");
|
101
|
-
}
|
102
|
-
|
103
|
-
function handleMethod(element) {
|
104
|
-
var method = element.readAttribute('data-method'),
|
105
|
-
url = element.readAttribute('href'),
|
106
|
-
csrf_param = $$('meta[name=csrf-param]')[0],
|
107
|
-
csrf_token = $$('meta[name=csrf-token]')[0];
|
108
|
-
|
109
|
-
var form = new Element('form', { method: "POST", action: url, style: "display: none;" });
|
110
|
-
element.parentNode.insert(form);
|
111
|
-
|
112
|
-
if (method !== 'post') {
|
113
|
-
var field = new Element('input', { type: 'hidden', name: '_method', value: method });
|
114
|
-
form.insert(field);
|
115
|
-
}
|
116
|
-
|
117
|
-
if (csrf_param) {
|
118
|
-
var param = csrf_param.readAttribute('content'),
|
119
|
-
token = csrf_token.readAttribute('content'),
|
120
|
-
field = new Element('input', { type: 'hidden', name: param, value: token });
|
121
|
-
form.insert(field);
|
122
|
-
}
|
123
|
-
|
124
|
-
form.submit();
|
125
|
-
}
|
126
|
-
|
127
|
-
|
128
|
-
document.on("click", "*[data-confirm]", function(event, element) {
|
129
|
-
var message = element.readAttribute('data-confirm');
|
130
|
-
if (!confirm(message)) event.stop();
|
131
|
-
});
|
132
|
-
|
133
|
-
document.on("click", "a[data-remote]", function(event, element) {
|
134
|
-
if (event.stopped) return;
|
135
|
-
handleRemote(element);
|
136
|
-
event.stop();
|
137
|
-
});
|
138
|
-
|
139
|
-
document.on("click", "a[data-method]", function(event, element) {
|
140
|
-
if (event.stopped) return;
|
141
|
-
handleMethod(element);
|
142
|
-
event.stop();
|
143
|
-
});
|
144
|
-
|
145
|
-
document.on("submit", function(event) {
|
146
|
-
var element = event.findElement(),
|
147
|
-
message = element.readAttribute('data-confirm');
|
148
|
-
if (message && !confirm(message)) {
|
149
|
-
event.stop();
|
150
|
-
return false;
|
151
|
-
}
|
152
|
-
|
153
|
-
var inputs = element.select("input[type=submit][data-disable-with]");
|
154
|
-
inputs.each(function(input) {
|
155
|
-
input.disabled = true;
|
156
|
-
input.writeAttribute('data-original-value', input.value);
|
157
|
-
input.value = input.readAttribute('data-disable-with');
|
158
|
-
});
|
159
|
-
|
160
|
-
var element = event.findElement("form[data-remote]");
|
161
|
-
if (element) {
|
162
|
-
handleRemote(element);
|
163
|
-
event.stop();
|
164
|
-
}
|
165
|
-
});
|
166
|
-
|
167
|
-
document.on("ajax:after", "form", function(event, element) {
|
168
|
-
var inputs = element.select("input[type=submit][disabled=true][data-disable-with]");
|
169
|
-
inputs.each(function(input) {
|
170
|
-
input.value = input.readAttribute('data-original-value');
|
171
|
-
input.removeAttribute('data-original-value');
|
172
|
-
input.disabled = false;
|
173
|
-
});
|
174
|
-
});
|
175
|
-
})();
|