pbw 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/MIT-LICENSE +1 -1
- data/Rakefile +7 -0
- data/app/controllers/pbw/application_controller.rb +9 -3
- data/app/controllers/pbw/areas_controller.rb +7 -0
- data/app/controllers/pbw/base_models_controller.rb +106 -0
- data/app/controllers/pbw/capabilities_controller.rb +7 -0
- data/app/controllers/pbw/constraints_controller.rb +7 -0
- data/app/controllers/pbw/item_containers_controller.rb +7 -0
- data/app/controllers/pbw/item_conversions_controller.rb +7 -0
- data/app/controllers/pbw/item_transfers_controller.rb +7 -0
- data/app/controllers/pbw/items_controller.rb +7 -0
- data/app/controllers/pbw/processes_controller.rb +7 -0
- data/app/controllers/pbw/roles_controller.rb +5 -2
- data/app/controllers/pbw/tokens_controller.rb +7 -0
- data/app/controllers/pbw/triggers_controller.rb +7 -0
- data/app/controllers/pbw/user_tokens_controller.rb +7 -0
- data/app/models/pbw/area.rb +17 -0
- data/app/models/pbw/capability.rb +5 -0
- data/app/models/pbw/constraint.rb +6 -0
- data/app/models/pbw/item.rb +15 -0
- data/app/models/pbw/item_container.rb +12 -0
- data/app/models/pbw/item_conversion.rb +9 -0
- data/app/models/pbw/item_transfer.rb +9 -0
- data/app/models/pbw/permission.rb +1 -0
- data/app/models/pbw/process.rb +10 -0
- data/app/models/pbw/role.rb +1 -0
- data/app/models/pbw/rule.rb +11 -0
- data/app/models/pbw/token.rb +16 -0
- data/app/models/pbw/trigger.rb +7 -0
- data/app/models/pbw/user.rb +7 -5
- data/app/models/pbw/user_token.rb +16 -0
- data/app/views/layouts/pbw/application.html.erb +41 -8
- data/config/initializers/devise.rb +80 -4
- data/config/locales/devise.en.yml +59 -0
- data/config/routes.rb +11 -0
- data/lib/generators/pbw/install/install_generator.rb +9 -1
- data/lib/generators/pbw/install/templates/application.html.erb +47 -0
- data/lib/pbw/engine.rb +33 -13
- data/lib/pbw/version.rb +1 -1
- data/public/Foundation-MIT-LICENSE.txt +20 -0
- data/public/config.rb +26 -0
- data/public/humans.txt +8 -0
- data/public/javascripts/foundation/foundation.alerts.js +52 -0
- data/public/javascripts/foundation/foundation.clearing.js +516 -0
- data/public/javascripts/foundation/foundation.cookie.js +74 -0
- data/public/javascripts/foundation/foundation.dropdown.js +178 -0
- data/public/javascripts/foundation/foundation.forms.js +525 -0
- data/public/javascripts/foundation/foundation.interchange.js +271 -0
- data/public/javascripts/foundation/foundation.joyride.js +844 -0
- data/public/javascripts/foundation/foundation.js +447 -0
- data/public/javascripts/foundation/foundation.magellan.js +134 -0
- data/public/javascripts/foundation/foundation.orbit.js +390 -0
- data/public/javascripts/foundation/foundation.placeholder.js +179 -0
- data/public/javascripts/foundation/foundation.reveal.js +330 -0
- data/public/javascripts/foundation/foundation.section.js +422 -0
- data/public/javascripts/foundation/foundation.tooltips.js +208 -0
- data/public/javascripts/foundation/foundation.topbar.js +303 -0
- data/public/javascripts/vendor/custom.modernizr.js +4 -0
- data/public/javascripts/vendor/jquery.js +9807 -0
- data/public/javascripts/vendor/zepto.js +2000 -0
- data/public/robots.txt +4 -0
- data/public/sass/_normalize.scss +402 -0
- data/public/sass/_settings.scss +1271 -0
- data/public/sass/app.scss +48 -0
- data/public/stylesheets/app.css +6686 -0
- metadata +82 -4
- data/app/assets/javascripts/pbw/application.js +0 -13
- data/app/assets/stylesheets/pbw/application.css +0 -13
@@ -0,0 +1,390 @@
|
|
1
|
+
;(function ($, window, document, undefined) {
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
Foundation.libs = Foundation.libs || {};
|
5
|
+
|
6
|
+
Foundation.libs.orbit = {
|
7
|
+
name: 'orbit',
|
8
|
+
|
9
|
+
version: '4.2.0',
|
10
|
+
|
11
|
+
settings: {
|
12
|
+
timer_speed: 10000,
|
13
|
+
pause_on_hover: true,
|
14
|
+
resume_on_mouseout: false,
|
15
|
+
animation_speed: 500,
|
16
|
+
bullets: true,
|
17
|
+
stack_on_small: true,
|
18
|
+
navigation_arrows: true,
|
19
|
+
slide_number: true,
|
20
|
+
container_class: 'orbit-container',
|
21
|
+
stack_on_small_class: 'orbit-stack-on-small',
|
22
|
+
next_class: 'orbit-next',
|
23
|
+
prev_class: 'orbit-prev',
|
24
|
+
timer_container_class: 'orbit-timer',
|
25
|
+
timer_paused_class: 'paused',
|
26
|
+
timer_progress_class: 'orbit-progress',
|
27
|
+
slides_container_class: 'orbit-slides-container',
|
28
|
+
bullets_container_class: 'orbit-bullets',
|
29
|
+
bullets_active_class: 'active',
|
30
|
+
slide_number_class: 'orbit-slide-number',
|
31
|
+
caption_class: 'orbit-caption',
|
32
|
+
active_slide_class: 'active',
|
33
|
+
orbit_transition_class: 'orbit-transitioning'
|
34
|
+
},
|
35
|
+
|
36
|
+
init: function (scope, method, options) {
|
37
|
+
var self = this;
|
38
|
+
Foundation.inherit(self, 'data_options');
|
39
|
+
|
40
|
+
if (typeof method === 'object') {
|
41
|
+
$.extend(true, self.settings, method);
|
42
|
+
}
|
43
|
+
|
44
|
+
if ($(scope).is('[data-orbit]')) {
|
45
|
+
var scoped_self = $.extend(true, {}, self);
|
46
|
+
scoped_self._init(idx, el);
|
47
|
+
}
|
48
|
+
|
49
|
+
$('[data-orbit]', scope).each(function(idx, el) {
|
50
|
+
var scoped_self = $.extend(true, {}, self);
|
51
|
+
scoped_self._init(idx, el);
|
52
|
+
});
|
53
|
+
},
|
54
|
+
|
55
|
+
_container_html: function() {
|
56
|
+
var self = this;
|
57
|
+
return '<div class="' + self.settings.container_class + '"></div>';
|
58
|
+
},
|
59
|
+
|
60
|
+
_bullets_container_html: function($slides) {
|
61
|
+
var self = this,
|
62
|
+
$list = $('<ol class="' + self.settings.bullets_container_class + '"></ol>');
|
63
|
+
$slides.each(function(idx, slide) {
|
64
|
+
var $item = $('<li data-orbit-slide-number="' + (idx+1) + '" class=""></li>');
|
65
|
+
if (idx === 0) {
|
66
|
+
$item.addClass(self.settings.bullets_active_class);
|
67
|
+
}
|
68
|
+
$list.append($item);
|
69
|
+
});
|
70
|
+
return $list;
|
71
|
+
},
|
72
|
+
|
73
|
+
_slide_number_html: function(slide_number, total_slides) {
|
74
|
+
var self = this,
|
75
|
+
$container = $('<div class="' + self.settings.slide_number_class + '"></div>');
|
76
|
+
$container.append('<span>' + slide_number + '</span> of <span>' + total_slides + '</span>');
|
77
|
+
return $container;
|
78
|
+
},
|
79
|
+
|
80
|
+
_timer_html: function() {
|
81
|
+
var self = this;
|
82
|
+
if (typeof self.settings.timer_speed === 'number' && self.settings.timer_speed > 0) {
|
83
|
+
return '<div class="' + self.settings.timer_container_class
|
84
|
+
+ '"><span></span><div class="' + self.settings.timer_progress_class
|
85
|
+
+ '"></div></div>';
|
86
|
+
} else {
|
87
|
+
return '';
|
88
|
+
}
|
89
|
+
},
|
90
|
+
|
91
|
+
_next_html: function() {
|
92
|
+
var self = this;
|
93
|
+
return '<a href="#" class="' + self.settings.next_class + '">Next <span></span></a>';
|
94
|
+
},
|
95
|
+
|
96
|
+
_prev_html: function() {
|
97
|
+
var self = this;
|
98
|
+
return '<a href="#" class="' + self.settings.prev_class + '">Prev <span></span></a>';
|
99
|
+
},
|
100
|
+
|
101
|
+
_init: function (idx, slider) {
|
102
|
+
var self = this,
|
103
|
+
$slides_container = $(slider),
|
104
|
+
$container = $slides_container.wrap(self._container_html()).parent(),
|
105
|
+
$slides = $slides_container.children();
|
106
|
+
|
107
|
+
$.extend(true, self.settings, self.data_options($slides_container));
|
108
|
+
|
109
|
+
if (self.settings.navigation_arrows) {
|
110
|
+
$container.append(self._prev_html());
|
111
|
+
$container.append(self._next_html());
|
112
|
+
}
|
113
|
+
$slides_container.addClass(self.settings.slides_container_class);
|
114
|
+
if (self.settings.stack_on_small) {
|
115
|
+
$container.addClass(self.settings.stack_on_small_class);
|
116
|
+
}
|
117
|
+
if (self.settings.slide_number) {
|
118
|
+
$container.append(self._slide_number_html(1, $slides.length));
|
119
|
+
}
|
120
|
+
$container.append(self._timer_html());
|
121
|
+
if (self.settings.bullets) {
|
122
|
+
$container.after(self._bullets_container_html($slides));
|
123
|
+
}
|
124
|
+
// To better support the "sliding" effect it's easier
|
125
|
+
// if we just clone the first and last slides
|
126
|
+
$slides_container.append($slides.first().clone().attr('data-orbit-slide',''));
|
127
|
+
$slides_container.prepend($slides.last().clone().attr('data-orbit-slide',''));
|
128
|
+
// Make the first "real" slide active
|
129
|
+
$slides_container.css(Foundation.rtl ? 'marginRight' : 'marginLeft', '-100%');
|
130
|
+
$slides.first().addClass(self.settings.active_slide_class);
|
131
|
+
|
132
|
+
self._init_events($slides_container);
|
133
|
+
self._init_dimensions($slides_container);
|
134
|
+
self._start_timer($slides_container);
|
135
|
+
},
|
136
|
+
|
137
|
+
_init_events: function ($slides_container) {
|
138
|
+
var self = this,
|
139
|
+
$container = $slides_container.parent();
|
140
|
+
|
141
|
+
$(window)
|
142
|
+
.on('load.fndtn.orbit', function() {
|
143
|
+
$slides_container.height('');
|
144
|
+
$slides_container.height($slides_container.height($container.height()));
|
145
|
+
$slides_container.trigger('orbit:ready');
|
146
|
+
})
|
147
|
+
.on('resize.fndtn.orbit', function() {
|
148
|
+
$slides_container.height('');
|
149
|
+
$slides_container.height($slides_container.height($container.height()));
|
150
|
+
});
|
151
|
+
|
152
|
+
$(document).on('click.fndtn.orbit', '[data-orbit-link]', function(e) {
|
153
|
+
e.preventDefault();
|
154
|
+
var id = $(e.currentTarget).attr('data-orbit-link'),
|
155
|
+
$slide = $slides_container.find('[data-orbit-slide=' + id + ']').first();
|
156
|
+
|
157
|
+
if ($slide.length === 1) {
|
158
|
+
self._reset_timer($slides_container, true);
|
159
|
+
self._goto($slides_container, $slide.index(), function() {});
|
160
|
+
}
|
161
|
+
});
|
162
|
+
|
163
|
+
$container.siblings('.' + self.settings.bullets_container_class)
|
164
|
+
.on('click.fndtn.orbit', '[data-orbit-slide-number]', function(e) {
|
165
|
+
e.preventDefault();
|
166
|
+
self._reset_timer($slides_container, true);
|
167
|
+
self._goto($slides_container, $(e.currentTarget).data('orbit-slide-number'),function() {});
|
168
|
+
});
|
169
|
+
|
170
|
+
$container
|
171
|
+
.on('mouseenter.fndtn.orbit', function(e) {
|
172
|
+
if (self.settings.pause_on_hover) {
|
173
|
+
self._stop_timer($slides_container);
|
174
|
+
}
|
175
|
+
})
|
176
|
+
.on('mouseleave.fndtn.orbit', function(e) {
|
177
|
+
if (self.settings.resume_on_mouseout) {
|
178
|
+
self._start_timer($slides_container);
|
179
|
+
}
|
180
|
+
})
|
181
|
+
.on('orbit:after-slide-change.fndtn.orbit', function(e, orbit) {
|
182
|
+
var $slide_number = $container.find('.' + self.settings.slide_number_class);
|
183
|
+
|
184
|
+
if ($slide_number.length === 1) {
|
185
|
+
$slide_number.replaceWith(self._slide_number_html(orbit.slide_number, orbit.total_slides));
|
186
|
+
}
|
187
|
+
})
|
188
|
+
.on('orbit:next-slide.fndtn.orbit click.fndtn.orbit', '.' + self.settings.next_class.split(" ").join("."), function(e) {
|
189
|
+
e.preventDefault();
|
190
|
+
self._reset_timer($slides_container, true);
|
191
|
+
self._goto($slides_container, 'next', function() {});
|
192
|
+
})
|
193
|
+
.on('orbit:prev-slide.fndtn.orbit click.fndtn.orbit', '.' + self.settings.prev_class.split(" ").join("."), function(e) {
|
194
|
+
e.preventDefault();
|
195
|
+
self._reset_timer($slides_container, true);
|
196
|
+
self._goto($slides_container, 'prev', function() {});
|
197
|
+
})
|
198
|
+
.on('orbit:toggle-play-pause.fndtn.orbit click.fndtn.orbit touchstart.fndtn.orbit', '.' + self.settings.timer_container_class, function(e) {
|
199
|
+
e.preventDefault();
|
200
|
+
var $timer = $(e.currentTarget).toggleClass(self.settings.timer_paused_class),
|
201
|
+
$slides_container = $timer.closest('.' + self.settings.container_class)
|
202
|
+
.find('.' + self.settings.slides_container_class);
|
203
|
+
|
204
|
+
if ($timer.hasClass(self.settings.timer_paused_class)) {
|
205
|
+
self._stop_timer($slides_container);
|
206
|
+
} else {
|
207
|
+
self._start_timer($slides_container);
|
208
|
+
}
|
209
|
+
})
|
210
|
+
.on('touchstart.fndtn.orbit', function(e) {
|
211
|
+
if (!e.touches) { e = e.originalEvent; }
|
212
|
+
var data = {
|
213
|
+
start_page_x: e.touches[0].pageX,
|
214
|
+
start_page_y: e.touches[0].pageY,
|
215
|
+
start_time: (new Date()).getTime(),
|
216
|
+
delta_x: 0,
|
217
|
+
is_scrolling: undefined
|
218
|
+
};
|
219
|
+
$container.data('swipe-transition', data);
|
220
|
+
e.stopPropagation();
|
221
|
+
})
|
222
|
+
.on('touchmove.fndtn.orbit', function(e) {
|
223
|
+
if (!e.touches) { e = e.originalEvent; }
|
224
|
+
// Ignore pinch/zoom events
|
225
|
+
if(e.touches.length > 1 || e.scale && e.scale !== 1) return;
|
226
|
+
|
227
|
+
var data = $container.data('swipe-transition');
|
228
|
+
if (typeof data === 'undefined') {
|
229
|
+
data = {};
|
230
|
+
}
|
231
|
+
|
232
|
+
data.delta_x = e.touches[0].pageX - data.start_page_x;
|
233
|
+
|
234
|
+
if ( typeof data.is_scrolling === 'undefined') {
|
235
|
+
data.is_scrolling = !!( data.is_scrolling || Math.abs(data.delta_x) < Math.abs(e.touches[0].pageY - data.start_page_y) );
|
236
|
+
}
|
237
|
+
|
238
|
+
if (!data.is_scrolling && !data.active) {
|
239
|
+
e.preventDefault();
|
240
|
+
self._stop_timer($slides_container);
|
241
|
+
var direction = (data.delta_x < 0) ? 'next' : 'prev';
|
242
|
+
data.active = true;
|
243
|
+
self._goto($slides_container, direction, function() {});
|
244
|
+
}
|
245
|
+
})
|
246
|
+
.on('touchend.fndtn.orbit', function(e) {
|
247
|
+
$container.data('swipe-transition', {});
|
248
|
+
e.stopPropagation();
|
249
|
+
});
|
250
|
+
},
|
251
|
+
|
252
|
+
_init_dimensions: function ($slides_container) {
|
253
|
+
var $container = $slides_container.parent(),
|
254
|
+
$slides = $slides_container.children();
|
255
|
+
|
256
|
+
$slides_container.css('width', $slides.length * 100 + '%');
|
257
|
+
$slides.css('width', 100 / $slides.length + '%');
|
258
|
+
$slides_container.height($container.height());
|
259
|
+
$slides_container.css('width', $slides.length * 100 + '%');
|
260
|
+
},
|
261
|
+
|
262
|
+
_start_timer: function ($slides_container) {
|
263
|
+
var self = this,
|
264
|
+
$container = $slides_container.parent();
|
265
|
+
|
266
|
+
var callback = function() {
|
267
|
+
self._reset_timer($slides_container, false);
|
268
|
+
self._goto($slides_container, 'next', function() {
|
269
|
+
self._start_timer($slides_container);
|
270
|
+
});
|
271
|
+
};
|
272
|
+
|
273
|
+
var $timer = $container.find('.' + self.settings.timer_container_class),
|
274
|
+
$progress = $timer.find('.' + self.settings.timer_progress_class),
|
275
|
+
progress_pct = ($progress.width() / $timer.width()),
|
276
|
+
delay = self.settings.timer_speed - (progress_pct * self.settings.timer_speed);
|
277
|
+
|
278
|
+
$progress.animate({'width': '100%'}, delay, 'linear', callback);
|
279
|
+
$slides_container.trigger('orbit:timer-started');
|
280
|
+
},
|
281
|
+
|
282
|
+
_stop_timer: function ($slides_container) {
|
283
|
+
var self = this,
|
284
|
+
$container = $slides_container.parent(),
|
285
|
+
$timer = $container.find('.' + self.settings.timer_container_class),
|
286
|
+
$progress = $timer.find('.' + self.settings.timer_progress_class),
|
287
|
+
progress_pct = $progress.width() / $timer.width();
|
288
|
+
self._rebuild_timer($container, progress_pct * 100 + '%');
|
289
|
+
// $progress.stop();
|
290
|
+
$slides_container.trigger('orbit:timer-stopped');
|
291
|
+
$timer = $container.find('.' + self.settings.timer_container_class);
|
292
|
+
$timer.addClass(self.settings.timer_paused_class);
|
293
|
+
},
|
294
|
+
|
295
|
+
_reset_timer: function($slides_container, is_paused) {
|
296
|
+
var self = this,
|
297
|
+
$container = $slides_container.parent();
|
298
|
+
self._rebuild_timer($container, '0%');
|
299
|
+
if (typeof is_paused === 'boolean' && is_paused) {
|
300
|
+
var $timer = $container.find('.' + self.settings.timer_container_class);
|
301
|
+
$timer.addClass(self.settings.timer_paused_class);
|
302
|
+
}
|
303
|
+
},
|
304
|
+
|
305
|
+
_rebuild_timer: function ($container, width_pct) {
|
306
|
+
// Zepto is unable to stop animations since they
|
307
|
+
// are css-based. This is a workaround for that
|
308
|
+
// limitation, which rebuilds the dom element
|
309
|
+
// thus stopping the animation
|
310
|
+
var self = this,
|
311
|
+
$timer = $container.find('.' + self.settings.timer_container_class),
|
312
|
+
$new_timer = $(self._timer_html()),
|
313
|
+
$new_timer_progress = $new_timer.find('.' + self.settings.timer_progress_class);
|
314
|
+
|
315
|
+
if (typeof Zepto === 'function') {
|
316
|
+
$timer.remove();
|
317
|
+
$container.append($new_timer);
|
318
|
+
$new_timer_progress.css('width', width_pct);
|
319
|
+
} else if (typeof jQuery === 'function') {
|
320
|
+
var $progress = $timer.find('.' + self.settings.timer_progress_class);
|
321
|
+
$progress.css('width', width_pct);
|
322
|
+
$progress.stop();
|
323
|
+
}
|
324
|
+
},
|
325
|
+
|
326
|
+
_goto: function($slides_container, index_or_direction, callback) {
|
327
|
+
var self = this,
|
328
|
+
$container = $slides_container.parent(),
|
329
|
+
$slides = $slides_container.children(),
|
330
|
+
$active_slide = $slides_container.find('.' + self.settings.active_slide_class),
|
331
|
+
active_index = $active_slide.index(),
|
332
|
+
margin_position = Foundation.rtl ? 'marginRight' : 'marginLeft';
|
333
|
+
|
334
|
+
if ($container.hasClass(self.settings.orbit_transition_class)) {
|
335
|
+
return false;
|
336
|
+
}
|
337
|
+
|
338
|
+
if (index_or_direction === 'prev') {
|
339
|
+
if (active_index === 0) {
|
340
|
+
active_index = $slides.length - 1;
|
341
|
+
}
|
342
|
+
else {
|
343
|
+
active_index--;
|
344
|
+
}
|
345
|
+
}
|
346
|
+
else if (index_or_direction === 'next') {
|
347
|
+
active_index = (active_index+1) % $slides.length;
|
348
|
+
}
|
349
|
+
else if (typeof index_or_direction === 'number') {
|
350
|
+
active_index = (index_or_direction % $slides.length);
|
351
|
+
}
|
352
|
+
if (active_index === ($slides.length - 1) && index_or_direction === 'next') {
|
353
|
+
$slides_container.css(margin_position, '0%');
|
354
|
+
active_index = 1;
|
355
|
+
}
|
356
|
+
else if (active_index === 0 && index_or_direction === 'prev') {
|
357
|
+
$slides_container.css(margin_position, '-' + ($slides.length - 1) * 100 + '%');
|
358
|
+
active_index = $slides.length - 2;
|
359
|
+
}
|
360
|
+
// Start transition, make next slide active
|
361
|
+
$container.addClass(self.settings.orbit_transition_class);
|
362
|
+
$active_slide.removeClass(self.settings.active_slide_class);
|
363
|
+
$($slides[active_index]).addClass(self.settings.active_slide_class);
|
364
|
+
// Make next bullet active
|
365
|
+
var $bullets = $container.siblings('.' + self.settings.bullets_container_class);
|
366
|
+
if ($bullets.length === 1) {
|
367
|
+
$bullets.children().removeClass(self.settings.bullets_active_class);
|
368
|
+
$($bullets.children()[active_index-1]).addClass(self.settings.bullets_active_class);
|
369
|
+
}
|
370
|
+
var new_margin_left = '-' + (active_index * 100) + '%';
|
371
|
+
// Check to see if animation will occur, otherwise perform
|
372
|
+
// callbacks manually
|
373
|
+
$slides_container.trigger('orbit:before-slide-change');
|
374
|
+
if ($slides_container.css(margin_position) === new_margin_left) {
|
375
|
+
$container.removeClass(self.settings.orbit_transition_class);
|
376
|
+
$slides_container.trigger('orbit:after-slide-change', [{slide_number: active_index, total_slides: $slides_container.children().length - 2}]);
|
377
|
+
callback();
|
378
|
+
} else {
|
379
|
+
var properties = {};
|
380
|
+
properties[margin_position] = new_margin_left;
|
381
|
+
|
382
|
+
$slides_container.animate(properties, self.settings.animation_speed, 'linear', function() {
|
383
|
+
$container.removeClass(self.settings.orbit_transition_class);
|
384
|
+
$slides_container.trigger('orbit:after-slide-change', [{slide_number: active_index, total_slides: $slides_container.children().length - 2}]);
|
385
|
+
callback();
|
386
|
+
});
|
387
|
+
}
|
388
|
+
}
|
389
|
+
};
|
390
|
+
}(Foundation.zj, this, this.document));
|
@@ -0,0 +1,179 @@
|
|
1
|
+
/*! http://mths.be/placeholder v2.0.7 by @mathias
|
2
|
+
Modified to work with Zepto.js by ZURB
|
3
|
+
*/
|
4
|
+
;(function(window, document, $) {
|
5
|
+
|
6
|
+
var isInputSupported = 'placeholder' in document.createElement('input'),
|
7
|
+
isTextareaSupported = 'placeholder' in document.createElement('textarea'),
|
8
|
+
prototype = $.fn,
|
9
|
+
valHooks = $.valHooks,
|
10
|
+
hooks,
|
11
|
+
placeholder;
|
12
|
+
|
13
|
+
if (isInputSupported && isTextareaSupported) {
|
14
|
+
|
15
|
+
placeholder = prototype.placeholder = function() {
|
16
|
+
return this;
|
17
|
+
};
|
18
|
+
|
19
|
+
placeholder.input = placeholder.textarea = true;
|
20
|
+
|
21
|
+
} else {
|
22
|
+
|
23
|
+
placeholder = prototype.placeholder = function() {
|
24
|
+
var $this = this;
|
25
|
+
$this
|
26
|
+
.filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
|
27
|
+
.not('.placeholder')
|
28
|
+
.bind({
|
29
|
+
'focus.placeholder': clearPlaceholder,
|
30
|
+
'blur.placeholder': setPlaceholder
|
31
|
+
})
|
32
|
+
.data('placeholder-enabled', true)
|
33
|
+
.trigger('blur.placeholder');
|
34
|
+
return $this;
|
35
|
+
};
|
36
|
+
|
37
|
+
placeholder.input = isInputSupported;
|
38
|
+
placeholder.textarea = isTextareaSupported;
|
39
|
+
|
40
|
+
hooks = {
|
41
|
+
'get': function(element) {
|
42
|
+
var $element = $(element);
|
43
|
+
return $element.data('placeholder-enabled') && $element.hasClass('placeholder') ? '' : element.value;
|
44
|
+
},
|
45
|
+
'set': function(element, value) {
|
46
|
+
var $element = $(element);
|
47
|
+
if (!$element.data('placeholder-enabled')) {
|
48
|
+
return element.value = value;
|
49
|
+
}
|
50
|
+
if (value == '') {
|
51
|
+
element.value = value;
|
52
|
+
// Issue #56: Setting the placeholder causes problems if the element continues to have focus.
|
53
|
+
if (element != document.activeElement) {
|
54
|
+
// We can't use `triggerHandler` here because of dummy text/password inputs :(
|
55
|
+
setPlaceholder.call(element);
|
56
|
+
}
|
57
|
+
} else if ($element.hasClass('placeholder')) {
|
58
|
+
clearPlaceholder.call(element, true, value) || (element.value = value);
|
59
|
+
} else {
|
60
|
+
element.value = value;
|
61
|
+
}
|
62
|
+
// `set` can not return `undefined`; see http://jsapi.info/jquery/1.7.1/val#L2363
|
63
|
+
return $element;
|
64
|
+
}
|
65
|
+
};
|
66
|
+
|
67
|
+
isInputSupported || (valHooks.input = hooks);
|
68
|
+
isTextareaSupported || (valHooks.textarea = hooks);
|
69
|
+
|
70
|
+
$(function() {
|
71
|
+
// Look for forms
|
72
|
+
$(document).delegate('form', 'submit.placeholder', function() {
|
73
|
+
// Clear the placeholder values so they don't get submitted
|
74
|
+
var $inputs = $('.placeholder', this).each(clearPlaceholder);
|
75
|
+
setTimeout(function() {
|
76
|
+
$inputs.each(setPlaceholder);
|
77
|
+
}, 10);
|
78
|
+
});
|
79
|
+
});
|
80
|
+
|
81
|
+
// Clear placeholder values upon page reload
|
82
|
+
$(window).bind('beforeunload.placeholder', function() {
|
83
|
+
$('.placeholder').each(function() {
|
84
|
+
this.value = '';
|
85
|
+
});
|
86
|
+
});
|
87
|
+
|
88
|
+
}
|
89
|
+
|
90
|
+
function args(elem) {
|
91
|
+
// Return an object of element attributes
|
92
|
+
var newAttrs = {},
|
93
|
+
rinlinejQuery = /^jQuery\d+$/;
|
94
|
+
$.each(elem.attributes, function(i, attr) {
|
95
|
+
if (attr.specified && !rinlinejQuery.test(attr.name)) {
|
96
|
+
newAttrs[attr.name] = attr.value;
|
97
|
+
}
|
98
|
+
});
|
99
|
+
return newAttrs;
|
100
|
+
}
|
101
|
+
|
102
|
+
function clearPlaceholder(event, value) {
|
103
|
+
var input = this,
|
104
|
+
$input = $(input);
|
105
|
+
if (input.value == $input.attr('placeholder') && $input.hasClass('placeholder')) {
|
106
|
+
if ($input.data('placeholder-password')) {
|
107
|
+
$input = $input.hide().next().show().attr('id', $input.removeAttr('id').data('placeholder-id'));
|
108
|
+
// If `clearPlaceholder` was called from `$.valHooks.input.set`
|
109
|
+
if (event === true) {
|
110
|
+
return $input[0].value = value;
|
111
|
+
}
|
112
|
+
$input.focus();
|
113
|
+
} else {
|
114
|
+
input.value = '';
|
115
|
+
$input.removeClass('placeholder');
|
116
|
+
input == document.activeElement && input.select();
|
117
|
+
}
|
118
|
+
}
|
119
|
+
}
|
120
|
+
|
121
|
+
function setPlaceholder() {
|
122
|
+
var $replacement,
|
123
|
+
input = this,
|
124
|
+
$input = $(input),
|
125
|
+
$origInput = $input,
|
126
|
+
id = this.id;
|
127
|
+
if (input.value == '') {
|
128
|
+
if (input.type == 'password') {
|
129
|
+
if (!$input.data('placeholder-textinput')) {
|
130
|
+
try {
|
131
|
+
$replacement = $input.clone().attr({ 'type': 'text' });
|
132
|
+
} catch(e) {
|
133
|
+
$replacement = $('<input>').attr($.extend(args(this), { 'type': 'text' }));
|
134
|
+
}
|
135
|
+
$replacement
|
136
|
+
.removeAttr('name')
|
137
|
+
.data({
|
138
|
+
'placeholder-password': true,
|
139
|
+
'placeholder-id': id
|
140
|
+
})
|
141
|
+
.bind('focus.placeholder', clearPlaceholder);
|
142
|
+
$input
|
143
|
+
.data({
|
144
|
+
'placeholder-textinput': $replacement,
|
145
|
+
'placeholder-id': id
|
146
|
+
})
|
147
|
+
.before($replacement);
|
148
|
+
}
|
149
|
+
$input = $input.removeAttr('id').hide().prev().attr('id', id).show();
|
150
|
+
// Note: `$input[0] != input` now!
|
151
|
+
}
|
152
|
+
$input.addClass('placeholder');
|
153
|
+
$input[0].value = $input.attr('placeholder');
|
154
|
+
} else {
|
155
|
+
$input.removeClass('placeholder');
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
}(this, document, Foundation.zj));
|
160
|
+
|
161
|
+
;(function ($, window, document, undefined) {
|
162
|
+
'use strict';
|
163
|
+
|
164
|
+
Foundation.libs.placeholder = {
|
165
|
+
name : 'placeholder',
|
166
|
+
|
167
|
+
version : '4.2.2',
|
168
|
+
|
169
|
+
init : function (scope, method, options) {
|
170
|
+
this.scope = scope || this.scope;
|
171
|
+
|
172
|
+
if (typeof method !== 'string') {
|
173
|
+
window.onload = function () {
|
174
|
+
$('input, textarea').placeholder();
|
175
|
+
}
|
176
|
+
}
|
177
|
+
}
|
178
|
+
};
|
179
|
+
}(Foundation.zj, this, this.document));
|