mutiny-rails 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +18 -0
- data/lib/mutiny-rails.rb +6 -0
- data/lib/mutiny/rails/engine.rb +7 -0
- data/lib/mutiny/rails/version.rb +5 -0
- data/vendor/assets/javascripts/mutiny.js +208 -0
- data/vendor/assets/javascripts/mutiny.min.js +2 -0
- metadata +67 -0
data/LICENSE
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
Copyright (C) 2012-2013 Enova
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
4
|
+
this software and associated documentation files (the "Software"), to deal in
|
5
|
+
the Software without restriction, including without limitation the rights to
|
6
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
7
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
8
|
+
subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in all
|
11
|
+
copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
15
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
16
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
17
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
18
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/lib/mutiny-rails.rb
ADDED
@@ -0,0 +1,208 @@
|
|
1
|
+
/*! Mutiny v0.1.0 - http://mutinyjs.com/ */
|
2
|
+
var Mutiny = {
|
3
|
+
init: function(dataAttr) {
|
4
|
+
dataAttr = dataAttr || "mutiny";
|
5
|
+
$("[data-" + dataAttr + "]").mutiny(dataAttr);
|
6
|
+
}
|
7
|
+
};
|
8
|
+
|
9
|
+
$.fn.mutiny = function(dataAttr) {
|
10
|
+
var mutiny_call = function($instigator, name, instance_options) {
|
11
|
+
if (Mutiny[name] === undefined) {
|
12
|
+
throw '"' + name + '" not found';
|
13
|
+
}
|
14
|
+
var options = $.extend({}, Mutiny[name].defaults);
|
15
|
+
if (typeof instance_options === "string") {
|
16
|
+
options[Mutiny[name].string_arg] = instance_options;
|
17
|
+
} else {
|
18
|
+
$.extend(options, instance_options);
|
19
|
+
}
|
20
|
+
Mutiny[name].init($instigator, options);
|
21
|
+
};
|
22
|
+
dataAttr = dataAttr || "mutiny";
|
23
|
+
this.each(function(i, e) {
|
24
|
+
var $e = $(e);
|
25
|
+
var data = $e.data(dataAttr);
|
26
|
+
switch (typeof data) {
|
27
|
+
case "string":
|
28
|
+
mutiny_call($e, data, {});
|
29
|
+
break;
|
30
|
+
|
31
|
+
case "object":
|
32
|
+
for (var directive in data) {
|
33
|
+
mutiny_call($e, directive, data[directive]);
|
34
|
+
}
|
35
|
+
break;
|
36
|
+
|
37
|
+
default:
|
38
|
+
throw "Unsupported data";
|
39
|
+
}
|
40
|
+
});
|
41
|
+
return this;
|
42
|
+
};
|
43
|
+
|
44
|
+
$(function() {
|
45
|
+
Mutiny.init();
|
46
|
+
});
|
47
|
+
|
48
|
+
Mutiny.accordion = {
|
49
|
+
defaults: {
|
50
|
+
autoHeight: false,
|
51
|
+
collapsible: true,
|
52
|
+
active: false
|
53
|
+
},
|
54
|
+
_hrefIndex: function($search, href) {
|
55
|
+
var active_index = -1;
|
56
|
+
$search.find("a").each(function(index, anchorEl) {
|
57
|
+
if ($(anchorEl).attr("href") == href) {
|
58
|
+
active_index = index;
|
59
|
+
return false;
|
60
|
+
}
|
61
|
+
});
|
62
|
+
return active_index;
|
63
|
+
},
|
64
|
+
init: function($instigator, options) {
|
65
|
+
var hash = window.location.hash || undefined;
|
66
|
+
var $menu = options.menu ? $(options.menu) : undefined;
|
67
|
+
if (hash) {
|
68
|
+
var active_index = this._hrefIndex($menu || $instigator, hash);
|
69
|
+
if (active_index > -1) {
|
70
|
+
options.active = active_index;
|
71
|
+
}
|
72
|
+
}
|
73
|
+
if ($menu) {
|
74
|
+
var self = this;
|
75
|
+
$menu.find("a").click(function(event) {
|
76
|
+
var toggle_index = self._hrefIndex($menu, $(event.target).attr("href"));
|
77
|
+
if (toggle_index > -1) {
|
78
|
+
$instigator.accordion("activate", toggle_index);
|
79
|
+
}
|
80
|
+
});
|
81
|
+
}
|
82
|
+
$instigator.accordion(options);
|
83
|
+
}
|
84
|
+
};
|
85
|
+
|
86
|
+
Mutiny.datepicker = {
|
87
|
+
init: function($instigator, options) {
|
88
|
+
$instigator.datepicker();
|
89
|
+
}
|
90
|
+
};
|
91
|
+
|
92
|
+
Mutiny.slider = {
|
93
|
+
defaults: {
|
94
|
+
range: "min"
|
95
|
+
},
|
96
|
+
_createFormatSpan: function(format, value, className) {
|
97
|
+
if (value === null || value === "") {
|
98
|
+
value = " ";
|
99
|
+
}
|
100
|
+
var inner = format.replace("%s", "<span>" + value + "</span>");
|
101
|
+
if (className) {
|
102
|
+
return '<span class="' + className + '">' + inner + "</span>";
|
103
|
+
} else {
|
104
|
+
return "<span>" + inner + "</span>";
|
105
|
+
}
|
106
|
+
},
|
107
|
+
init: function($instigator, options) {
|
108
|
+
var $ui;
|
109
|
+
if (options.target) {
|
110
|
+
$ui = $(options.target);
|
111
|
+
} else {
|
112
|
+
var id = $instigator.attr("id");
|
113
|
+
var extras = "";
|
114
|
+
if (id) {
|
115
|
+
extras = ' id="' + id + '-mutiny-slider"';
|
116
|
+
}
|
117
|
+
$ui = $("<div" + extras + "></div>").insertAfter($instigator);
|
118
|
+
}
|
119
|
+
options.value = $instigator.val();
|
120
|
+
options.slide = function(event, slider) {
|
121
|
+
$instigator.val(slider.value).change();
|
122
|
+
};
|
123
|
+
if ($instigator.is("select")) {
|
124
|
+
var $options = $instigator.find("option");
|
125
|
+
options.min = Number($options.first().val());
|
126
|
+
options.max = Number($options.last().val());
|
127
|
+
options.step = (options.max - options.min) / ($options.length - 1);
|
128
|
+
} else {
|
129
|
+
options.min = Number($instigator.attr("min") || $instigator.data("min"));
|
130
|
+
options.max = Number($instigator.attr("max") || $instigator.data("max"));
|
131
|
+
options.step = Number($instigator.attr("step") || $instigator.data("step"));
|
132
|
+
}
|
133
|
+
$instigator.change(function() {
|
134
|
+
var val = Number($instigator.val());
|
135
|
+
if (val > options.max) {
|
136
|
+
val = options.max;
|
137
|
+
}
|
138
|
+
if (val < options.min) {
|
139
|
+
val = options.min;
|
140
|
+
}
|
141
|
+
if (isNaN(val)) {
|
142
|
+
val = options.value;
|
143
|
+
}
|
144
|
+
$instigator.val(val);
|
145
|
+
$ui.slider("value", val);
|
146
|
+
});
|
147
|
+
if (options.minLabel) {
|
148
|
+
$ui.append(this._createFormatSpan(options.minLabel, options.min, "min-label"));
|
149
|
+
}
|
150
|
+
if (options.maxLabel) {
|
151
|
+
$ui.append(this._createFormatSpan(options.maxLabel, options.max, "max-label"));
|
152
|
+
}
|
153
|
+
$ui.slider(options);
|
154
|
+
if (options.valueLabel) {
|
155
|
+
var $valueLabel = $(this._createFormatSpan(options.valueLabel, options.value, "valueLabel")).appendTo($ui.find(".ui-slider-handle"));
|
156
|
+
var $value = $valueLabel.find("span");
|
157
|
+
$instigator.change(function() {
|
158
|
+
$value.html($instigator.val());
|
159
|
+
});
|
160
|
+
}
|
161
|
+
}
|
162
|
+
};
|
163
|
+
|
164
|
+
Mutiny.toggler = {
|
165
|
+
defaults: {
|
166
|
+
style: {
|
167
|
+
display: "none"
|
168
|
+
},
|
169
|
+
preventDefault: false,
|
170
|
+
instigatorClass: "active"
|
171
|
+
},
|
172
|
+
string_arg: "target",
|
173
|
+
init: function($instigator, options) {
|
174
|
+
var $target = $(options.target);
|
175
|
+
var targetFunc;
|
176
|
+
if (options["class"]) {
|
177
|
+
targetFunc = function(on) {
|
178
|
+
$target.toggleClass(options["class"], on);
|
179
|
+
};
|
180
|
+
} else {
|
181
|
+
var noStyle = {};
|
182
|
+
for (var key in options.style) {
|
183
|
+
noStyle[key] = $target.css(key);
|
184
|
+
}
|
185
|
+
targetFunc = function(on) {
|
186
|
+
$target.css(on ? options.style : noStyle);
|
187
|
+
};
|
188
|
+
}
|
189
|
+
if ($instigator.is("input[type=radio]")) {
|
190
|
+
var name = $instigator.attr("name");
|
191
|
+
$('input[name="' + name + '"]').change(function(event) {
|
192
|
+
var active = $instigator.is(":checked");
|
193
|
+
$instigator.toggleClass(options.instigatorClass, active);
|
194
|
+
targetFunc(active);
|
195
|
+
});
|
196
|
+
} else {
|
197
|
+
var active = false;
|
198
|
+
$instigator.click(function(event) {
|
199
|
+
active = !active;
|
200
|
+
$instigator.toggleClass(options.instigatorClass, active);
|
201
|
+
targetFunc(active);
|
202
|
+
if (options.preventDefault) {
|
203
|
+
event.preventDefault();
|
204
|
+
}
|
205
|
+
});
|
206
|
+
}
|
207
|
+
}
|
208
|
+
};
|
@@ -0,0 +1,2 @@
|
|
1
|
+
/*! Mutiny v0.1.0 - http://mutinyjs.com/ */
|
2
|
+
var Mutiny={init:function(a){a=a||"mutiny",$("[data-"+a+"]").mutiny(a)}};$.fn.mutiny=function(a){var t=function(a,t,n){if(void 0===Mutiny[t])throw'"'+t+'" not found';var e=$.extend({},Mutiny[t].defaults);"string"==typeof n?e[Mutiny[t].string_arg]=n:$.extend(e,n),Mutiny[t].init(a,e)};return a=a||"mutiny",this.each(function(n,e){var i=$(e),r=i.data(a);switch(typeof r){case"string":t(i,r,{});break;case"object":for(var s in r)t(i,s,r[s]);break;default:throw"Unsupported data"}}),this},$(function(){Mutiny.init()}),Mutiny.accordion={defaults:{autoHeight:!1,collapsible:!0,active:!1},_hrefIndex:function(a,t){var n=-1;return a.find("a").each(function(a,e){return $(e).attr("href")==t?(n=a,!1):void 0}),n},init:function(a,t){var n=window.location.hash||void 0,e=t.menu?$(t.menu):void 0;if(n){var i=this._hrefIndex(e||a,n);i>-1&&(t.active=i)}if(e){var r=this;e.find("a").click(function(t){var n=r._hrefIndex(e,$(t.target).attr("href"));n>-1&&a.accordion("activate",n)})}a.accordion(t)}},Mutiny.datepicker={init:function(a){a.datepicker()}},Mutiny.slider={defaults:{range:"min"},_createFormatSpan:function(a,t,n){(null===t||""===t)&&(t=" ");var e=a.replace("%s","<span>"+t+"</span>");return n?'<span class="'+n+'">'+e+"</span>":"<span>"+e+"</span>"},init:function(a,t){var n;if(t.target)n=$(t.target);else{var e=a.attr("id"),i="";e&&(i=' id="'+e+'-mutiny-slider"'),n=$("<div"+i+"></div>").insertAfter(a)}if(t.value=a.val(),t.slide=function(t,n){a.val(n.value).change()},a.is("select")){var r=a.find("option");t.min=Number(r.first().val()),t.max=Number(r.last().val()),t.step=(t.max-t.min)/(r.length-1)}else t.min=Number(a.attr("min")||a.data("min")),t.max=Number(a.attr("max")||a.data("max")),t.step=Number(a.attr("step")||a.data("step"));if(a.change(function(){var e=Number(a.val());e>t.max&&(e=t.max),t.min>e&&(e=t.min),isNaN(e)&&(e=t.value),a.val(e),n.slider("value",e)}),t.minLabel&&n.append(this._createFormatSpan(t.minLabel,t.min,"min-label")),t.maxLabel&&n.append(this._createFormatSpan(t.maxLabel,t.max,"max-label")),n.slider(t),t.valueLabel){var s=$(this._createFormatSpan(t.valueLabel,t.value,"valueLabel")).appendTo(n.find(".ui-slider-handle")),l=s.find("span");a.change(function(){l.html(a.val())})}}},Mutiny.toggler={defaults:{style:{display:"none"},preventDefault:!1,instigatorClass:"active"},string_arg:"target",init:function(a,t){var n,e=$(t.target);if(t["class"])n=function(a){e.toggleClass(t["class"],a)};else{var i={};for(var r in t.style)i[r]=e.css(r);n=function(a){e.css(a?t.style:i)}}if(a.is("input[type=radio]")){var s=a.attr("name");$('input[name="'+s+'"]').change(function(){var e=a.is(":checked");a.toggleClass(t.instigatorClass,e),n(e)})}else{var l=!1;a.click(function(e){l=!l,a.toggleClass(t.instigatorClass,l),n(l),t.preventDefault&&e.preventDefault()})}}};
|
metadata
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mutiny-rails
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Benjamin Feng
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-01-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 3.1.0
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 3.1.0
|
30
|
+
description: This gem provides the official release of Mutiny from http://github.com/enova/mutiny
|
31
|
+
email: bfeng@enova.com
|
32
|
+
executables: []
|
33
|
+
extensions: []
|
34
|
+
extra_rdoc_files: []
|
35
|
+
files:
|
36
|
+
- lib/mutiny/rails/engine.rb
|
37
|
+
- lib/mutiny/rails/version.rb
|
38
|
+
- lib/mutiny-rails.rb
|
39
|
+
- vendor/assets/javascripts/mutiny.js
|
40
|
+
- vendor/assets/javascripts/mutiny.min.js
|
41
|
+
- LICENSE
|
42
|
+
homepage: http://github.com/enova/mutiny-rails
|
43
|
+
licenses: []
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options: []
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
requirements: []
|
61
|
+
rubyforge_project:
|
62
|
+
rubygems_version: 1.8.23
|
63
|
+
signing_key:
|
64
|
+
specification_version: 3
|
65
|
+
summary: Mutiny within Rails 3.1
|
66
|
+
test_files: []
|
67
|
+
has_rdoc:
|