pageflow 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of pageflow might be problematic. Click here for more details.

@@ -0,0 +1,175 @@
1
+ /*! http://mths.be/placeholder v2.0.7 by @mathias */
2
+ ;(function(window, document, $) {
3
+
4
+ var isInputSupported = 'placeholder' in document.createElement('input');
5
+ var isTextareaSupported = 'placeholder' in document.createElement('textarea');
6
+ var prototype = $.fn;
7
+ var valHooks = $.valHooks;
8
+ var propHooks = $.propHooks;
9
+ var hooks;
10
+ var placeholder;
11
+
12
+ if (isInputSupported && isTextareaSupported) {
13
+
14
+ placeholder = prototype.placeholder = function() {
15
+ return this;
16
+ };
17
+
18
+ placeholder.input = placeholder.textarea = true;
19
+
20
+ } else {
21
+
22
+ placeholder = prototype.placeholder = function() {
23
+ var $this = this;
24
+ $this
25
+ .filter((isInputSupported ? 'textarea' : ':input') + '[placeholder]')
26
+ .not('.placeholder')
27
+ .bind({
28
+ 'focus.placeholder': clearPlaceholder,
29
+ 'blur.placeholder': setPlaceholder
30
+ })
31
+ .data('placeholder-enabled', true)
32
+ .trigger('blur.placeholder');
33
+ return $this;
34
+ };
35
+
36
+ placeholder.input = isInputSupported;
37
+ placeholder.textarea = isTextareaSupported;
38
+
39
+ hooks = {
40
+ 'get': function(element) {
41
+ var $element = $(element);
42
+
43
+ var $passwordInput = $element.data('placeholder-password');
44
+ if ($passwordInput) {
45
+ return $passwordInput[0].value;
46
+ }
47
+
48
+ return $element.data('placeholder-enabled') && $element.hasClass('placeholder') ? '' : element.value;
49
+ },
50
+ 'set': function(element, value) {
51
+ var $element = $(element);
52
+
53
+ var $passwordInput = $element.data('placeholder-password');
54
+ if ($passwordInput) {
55
+ return $passwordInput[0].value = value;
56
+ }
57
+
58
+ if (!$element.data('placeholder-enabled')) {
59
+ return element.value = value;
60
+ }
61
+ if (value == '') {
62
+ element.value = value;
63
+ // Issue #56: Setting the placeholder causes problems if the element continues to have focus.
64
+ if (element != document.activeElement) {
65
+ // We can't use `triggerHandler` here because of dummy text/password inputs :(
66
+ setPlaceholder.call(element);
67
+ }
68
+ } else if ($element.hasClass('placeholder')) {
69
+ clearPlaceholder.call(element, true, value) || (element.value = value);
70
+ } else {
71
+ element.value = value;
72
+ }
73
+ // `set` can not return `undefined`; see http://jsapi.info/jquery/1.7.1/val#L2363
74
+ return $element;
75
+ }
76
+ };
77
+
78
+ if (!isInputSupported) {
79
+ valHooks.input = hooks;
80
+ propHooks.value = hooks;
81
+ }
82
+ if (!isTextareaSupported) {
83
+ valHooks.textarea = hooks;
84
+ propHooks.value = hooks;
85
+ }
86
+
87
+ $(function() {
88
+ // Look for forms
89
+ $(document).delegate('form', 'submit.placeholder', function() {
90
+ // Clear the placeholder values so they don't get submitted
91
+ var $inputs = $('.placeholder', this).each(clearPlaceholder);
92
+ setTimeout(function() {
93
+ $inputs.each(setPlaceholder);
94
+ }, 10);
95
+ });
96
+ });
97
+
98
+ // Clear placeholder values upon page reload
99
+ $(window).bind('beforeunload.placeholder', function() {
100
+ $('.placeholder').each(function() {
101
+ this.value = '';
102
+ });
103
+ });
104
+
105
+ }
106
+
107
+ function args(elem) {
108
+ // Return an object of element attributes
109
+ var newAttrs = {};
110
+ var rinlinejQuery = /^jQuery\d+$/;
111
+ $.each(elem.attributes, function(i, attr) {
112
+ if (attr.specified && !rinlinejQuery.test(attr.name)) {
113
+ newAttrs[attr.name] = attr.value;
114
+ }
115
+ });
116
+ return newAttrs;
117
+ }
118
+
119
+ function clearPlaceholder(event, value) {
120
+ var input = this;
121
+ var $input = $(input);
122
+ if (input.value == $input.attr('placeholder') && $input.hasClass('placeholder')) {
123
+ if ($input.data('placeholder-password')) {
124
+ $input = $input.hide().next().show().attr('id', $input.removeAttr('id').data('placeholder-id'));
125
+ // If `clearPlaceholder` was called from `$.valHooks.input.set`
126
+ if (event === true) {
127
+ return $input[0].value = value;
128
+ }
129
+ $input.focus();
130
+ } else {
131
+ input.value = '';
132
+ $input.removeClass('placeholder');
133
+ input == document.activeElement && input.select();
134
+ }
135
+ }
136
+ }
137
+
138
+ function setPlaceholder() {
139
+ var $replacement;
140
+ var input = this;
141
+ var $input = $(input);
142
+ var id = this.id;
143
+ if (input.value == '') {
144
+ if (input.type == 'password') {
145
+ if (!$input.data('placeholder-textinput')) {
146
+ try {
147
+ $replacement = $input.clone().attr({ 'type': 'text' });
148
+ } catch(e) {
149
+ $replacement = $('<input>').attr($.extend(args(this), { 'type': 'text' }));
150
+ }
151
+ $replacement
152
+ .removeAttr('name')
153
+ .data({
154
+ 'placeholder-password': $input,
155
+ 'placeholder-id': id
156
+ })
157
+ .bind('focus.placeholder', clearPlaceholder);
158
+ $input
159
+ .data({
160
+ 'placeholder-textinput': $replacement,
161
+ 'placeholder-id': id
162
+ })
163
+ .before($replacement);
164
+ }
165
+ $input = $input.removeAttr('id').hide().prev().attr('id', id).show();
166
+ // Note: `$input[0] != input` now!
167
+ }
168
+ $input.addClass('placeholder');
169
+ $input[0].value = $input.attr('placeholder');
170
+ } else {
171
+ $input.removeClass('placeholder');
172
+ }
173
+ }
174
+
175
+ }(this, document, jQuery));
@@ -0,0 +1,312 @@
1
+ /*!
2
+ * jQuery Simulate v@VERSION - simulate browser mouse and keyboard events
3
+ * https://github.com/jquery/jquery-simulate
4
+ *
5
+ * Copyright 2012 jQuery Foundation and other contributors
6
+ * Released under the MIT license.
7
+ * http://jquery.org/license
8
+ *
9
+ * Date: @DATE
10
+ */
11
+
12
+ ;(function( $, undefined ) {
13
+
14
+ var rkeyEvent = /^key/,
15
+ rmouseEvent = /^(?:mouse|contextmenu)|click/;
16
+
17
+ $.fn.simulate = function( type, options ) {
18
+ return this.each(function() {
19
+ new $.simulate( this, type, options );
20
+ });
21
+ };
22
+
23
+ $.simulate = function( elem, type, options ) {
24
+ var method = $.camelCase( "simulate-" + type );
25
+
26
+ this.target = elem;
27
+ this.options = options;
28
+
29
+ if ( this[ method ] ) {
30
+ this[ method ]();
31
+ } else {
32
+ this.simulateEvent( elem, type, options );
33
+ }
34
+ };
35
+
36
+ $.extend( $.simulate, {
37
+
38
+ keyCode: {
39
+ BACKSPACE: 8,
40
+ COMMA: 188,
41
+ DELETE: 46,
42
+ DOWN: 40,
43
+ END: 35,
44
+ ENTER: 13,
45
+ ESCAPE: 27,
46
+ HOME: 36,
47
+ LEFT: 37,
48
+ NUMPAD_ADD: 107,
49
+ NUMPAD_DECIMAL: 110,
50
+ NUMPAD_DIVIDE: 111,
51
+ NUMPAD_ENTER: 108,
52
+ NUMPAD_MULTIPLY: 106,
53
+ NUMPAD_SUBTRACT: 109,
54
+ PAGE_DOWN: 34,
55
+ PAGE_UP: 33,
56
+ PERIOD: 190,
57
+ RIGHT: 39,
58
+ SPACE: 32,
59
+ TAB: 9,
60
+ UP: 38
61
+ },
62
+
63
+ buttonCode: {
64
+ LEFT: 0,
65
+ MIDDLE: 1,
66
+ RIGHT: 2
67
+ }
68
+ });
69
+
70
+ $.extend( $.simulate.prototype, {
71
+
72
+ simulateEvent: function( elem, type, options ) {
73
+ var event = this.createEvent( type, options );
74
+ this.dispatchEvent( elem, type, event, options );
75
+ },
76
+
77
+ createEvent: function( type, options ) {
78
+ if ( rkeyEvent.test( type ) ) {
79
+ return this.keyEvent( type, options );
80
+ }
81
+
82
+ if ( rmouseEvent.test( type ) ) {
83
+ return this.mouseEvent( type, options );
84
+ }
85
+ },
86
+
87
+ mouseEvent: function( type, options ) {
88
+ var event, eventDoc, doc, body;
89
+ options = $.extend({
90
+ bubbles: true,
91
+ cancelable: (type !== "mousemove"),
92
+ view: window,
93
+ detail: 0,
94
+ screenX: 0,
95
+ screenY: 0,
96
+ clientX: 1,
97
+ clientY: 1,
98
+ ctrlKey: false,
99
+ altKey: false,
100
+ shiftKey: false,
101
+ metaKey: false,
102
+ button: 0,
103
+ relatedTarget: undefined
104
+ }, options );
105
+
106
+ if ( document.createEvent ) {
107
+ event = document.createEvent( "MouseEvents" );
108
+ event.initMouseEvent( type, options.bubbles, options.cancelable,
109
+ options.view, options.detail,
110
+ options.screenX, options.screenY, options.clientX, options.clientY,
111
+ options.ctrlKey, options.altKey, options.shiftKey, options.metaKey,
112
+ options.button, options.relatedTarget || document.body.parentNode );
113
+
114
+ // IE 9+ creates events with pageX and pageY set to 0.
115
+ // Trying to modify the properties throws an error,
116
+ // so we define getters to return the correct values.
117
+ if ( event.pageX === 0 && event.pageY === 0 && Object.defineProperty ) {
118
+ eventDoc = event.relatedTarget.ownerDocument || document;
119
+ doc = eventDoc.documentElement;
120
+ body = eventDoc.body;
121
+
122
+ Object.defineProperty( event, "pageX", {
123
+ get: function() {
124
+ return options.clientX +
125
+ ( doc && doc.scrollLeft || body && body.scrollLeft || 0 ) -
126
+ ( doc && doc.clientLeft || body && body.clientLeft || 0 );
127
+ }
128
+ });
129
+ Object.defineProperty( event, "pageY", {
130
+ get: function() {
131
+ return options.clientY +
132
+ ( doc && doc.scrollTop || body && body.scrollTop || 0 ) -
133
+ ( doc && doc.clientTop || body && body.clientTop || 0 );
134
+ }
135
+ });
136
+ }
137
+ } else if ( document.createEventObject ) {
138
+ event = document.createEventObject();
139
+ $.extend( event, options );
140
+ // standards event.button uses constants defined here: http://msdn.microsoft.com/en-us/library/ie/ff974877(v=vs.85).aspx
141
+ // old IE event.button uses constants defined here: http://msdn.microsoft.com/en-us/library/ie/ms533544(v=vs.85).aspx
142
+ // so we actually need to map the standard back to oldIE
143
+ event.button = {
144
+ 0: 1,
145
+ 1: 4,
146
+ 2: 2
147
+ }[ event.button ] || event.button;
148
+ }
149
+
150
+ return event;
151
+ },
152
+
153
+ keyEvent: function( type, options ) {
154
+ var event;
155
+ options = $.extend({
156
+ bubbles: true,
157
+ cancelable: true,
158
+ view: window,
159
+ ctrlKey: false,
160
+ altKey: false,
161
+ shiftKey: false,
162
+ metaKey: false,
163
+ keyCode: 0,
164
+ charCode: undefined
165
+ }, options );
166
+
167
+ if ( document.createEvent ) {
168
+ try {
169
+ event = document.createEvent( "KeyEvents" );
170
+ event.initKeyEvent( type, options.bubbles, options.cancelable, options.view,
171
+ options.ctrlKey, options.altKey, options.shiftKey, options.metaKey,
172
+ options.keyCode, options.charCode );
173
+ // initKeyEvent throws an exception in WebKit
174
+ // see: http://stackoverflow.com/questions/6406784/initkeyevent-keypress-only-works-in-firefox-need-a-cross-browser-solution
175
+ // and also https://bugs.webkit.org/show_bug.cgi?id=13368
176
+ // fall back to a generic event until we decide to implement initKeyboardEvent
177
+ } catch( err ) {
178
+ event = document.createEvent( "Events" );
179
+ event.initEvent( type, options.bubbles, options.cancelable );
180
+ $.extend( event, {
181
+ view: options.view,
182
+ ctrlKey: options.ctrlKey,
183
+ altKey: options.altKey,
184
+ shiftKey: options.shiftKey,
185
+ metaKey: options.metaKey,
186
+ keyCode: options.keyCode,
187
+ charCode: options.charCode
188
+ });
189
+ }
190
+ } else if ( document.createEventObject ) {
191
+ event = document.createEventObject();
192
+ $.extend( event, options );
193
+ }
194
+
195
+ if ( !!/msie [\w.]+/.exec( navigator.userAgent.toLowerCase() ) || (({}).toString.call( window.opera ) === "[object Opera]") ) {
196
+ event.keyCode = (options.charCode > 0) ? options.charCode : options.keyCode;
197
+ event.charCode = undefined;
198
+ }
199
+
200
+ return event;
201
+ },
202
+
203
+ dispatchEvent: function( elem, type, event ) {
204
+ if ( elem.dispatchEvent ) {
205
+ elem.dispatchEvent( event );
206
+ } else if ( elem.fireEvent ) {
207
+ elem.fireEvent( "on" + type, event );
208
+ }
209
+ },
210
+
211
+ simulateFocus: function() {
212
+ var focusinEvent,
213
+ triggered = false,
214
+ element = $( this.target );
215
+
216
+ function trigger() {
217
+ triggered = true;
218
+ }
219
+
220
+ element.bind( "focus", trigger );
221
+ element[ 0 ].focus();
222
+
223
+ if ( !triggered ) {
224
+ focusinEvent = $.Event( "focusin" );
225
+ focusinEvent.preventDefault();
226
+ element.trigger( focusinEvent );
227
+ element.triggerHandler( "focus" );
228
+ }
229
+ element.unbind( "focus", trigger );
230
+ },
231
+
232
+ simulateBlur: function() {
233
+ var focusoutEvent,
234
+ triggered = false,
235
+ element = $( this.target );
236
+
237
+ function trigger() {
238
+ triggered = true;
239
+ }
240
+
241
+ element.bind( "blur", trigger );
242
+ element[ 0 ].blur();
243
+
244
+ // blur events are async in IE
245
+ setTimeout(function() {
246
+ // IE won't let the blur occur if the window is inactive
247
+ if ( element[ 0 ].ownerDocument.activeElement === element[ 0 ] ) {
248
+ element[ 0 ].ownerDocument.body.focus();
249
+ }
250
+
251
+ // Firefox won't trigger events if the window is inactive
252
+ // IE doesn't trigger events if we had to manually focus the body
253
+ if ( !triggered ) {
254
+ focusoutEvent = $.Event( "focusout" );
255
+ focusoutEvent.preventDefault();
256
+ element.trigger( focusoutEvent );
257
+ element.triggerHandler( "blur" );
258
+ }
259
+ element.unbind( "blur", trigger );
260
+ }, 1 );
261
+ }
262
+ });
263
+
264
+
265
+
266
+ /** complex events **/
267
+
268
+ function findCenter( elem ) {
269
+ var offset,
270
+ document = $( elem.ownerDocument );
271
+ elem = $( elem );
272
+ offset = elem.offset();
273
+
274
+ return {
275
+ x: offset.left + elem.outerWidth() / 2 - document.scrollLeft(),
276
+ y: offset.top + elem.outerHeight() / 2 - document.scrollTop()
277
+ };
278
+ }
279
+
280
+ $.extend( $.simulate.prototype, {
281
+ simulateDrag: function() {
282
+ var i = 0,
283
+ target = this.target,
284
+ options = this.options,
285
+ center = findCenter( target ),
286
+ x = Math.floor( center.x ),
287
+ y = Math.floor( center.y ),
288
+ dx = options.dx || 0,
289
+ dy = options.dy || 0,
290
+ moves = options.moves || 3,
291
+ coord = { clientX: x, clientY: y };
292
+
293
+ this.simulateEvent( target, "mousedown", coord );
294
+
295
+ for ( ; i < moves ; i++ ) {
296
+ x += dx / moves;
297
+ y += dy / moves;
298
+
299
+ coord = {
300
+ clientX: Math.round( x ),
301
+ clientY: Math.round( y )
302
+ };
303
+
304
+ this.simulateEvent( document, "mousemove", coord );
305
+ }
306
+
307
+ this.simulateEvent( target, "mouseup", coord );
308
+ this.simulateEvent( target, "click", coord );
309
+ }
310
+ });
311
+
312
+ })( jQuery );