amplify 1.1.1 → 1.1.2

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.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ODJiNDE5MWMxOTI4ZTc5Y2VjMWE4YzgwZjEyZWM3YWY5MzE1ZWU5OQ==
5
+ data.tar.gz: !binary |-
6
+ MjVlYzNhNzA2NDVlMTBlYThlMDhhNDViOWNhNDYwMjEzNDIyMzVhZA==
7
+ SHA512:
8
+ metadata.gz: !binary |-
9
+ YTdmMjYzMTVlZWQxNjcwZTNkODlhZGJmMjE1ZGVkYTkyMWQzZjI4N2M4OGIx
10
+ Njc2NWIxMWU3MDJhZDcwMDc4Mjk2YTMyZGFmY2IyYzE5NTZiZWUzNWY5ZmM5
11
+ ZmVhYThhMTI5ZTgzYTFlMjQ2ZDRlNTgxMDdiYzUzMDE3NjA0ZjY=
12
+ data.tar.gz: !binary |-
13
+ YmE4ZTRmOTQyM2YxM2VlODI4MzZkYWQzNWFkZTU1YzlmOTZjZTdmYmE2Yzc2
14
+ ZjZkN2VlMjE5NWI2OWVmNzY5ZmIzY2I4MzU5Y2I3ZmUzMGJjZWJmM2I2NTJi
15
+ MTQ3MzFkZjE4ZDU0NzgxNjNmNmM3YWQ5Mzk5NzdhYjEyY2I0OGI=
@@ -1,3 +1,3 @@
1
1
  module Amplify
2
- VERSION = "1.1.0"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -1,10 +1,10 @@
1
1
  /*!
2
2
  * Amplify Core <%= Amplify::VERSION %>
3
- *
4
- * Copyright 2011 appendTo LLC. (http://appendto.com/team)
3
+ *
4
+ * Copyright 2011 - 2013 appendTo LLC. (http://appendto.com/team)
5
5
  * Dual licensed under the MIT or GPL licenses.
6
6
  * http://appendto.com/open-source-licenses
7
- *
7
+ *
8
8
  * http://amplifyjs.com
9
9
  */
10
10
  (function( global, undefined ) {
@@ -14,6 +14,10 @@ var slice = [].slice,
14
14
 
15
15
  var amplify = global.amplify = {
16
16
  publish: function( topic ) {
17
+ if ( typeof topic !== "string" ) {
18
+ throw new Error( "You must provide a valid topic to publish." );
19
+ }
20
+
17
21
  var args = slice.call( arguments, 1 ),
18
22
  topicSubscriptions,
19
23
  subscription,
@@ -37,6 +41,10 @@ var amplify = global.amplify = {
37
41
  },
38
42
 
39
43
  subscribe: function( topic, context, callback, priority ) {
44
+ if ( typeof topic !== "string" ) {
45
+ throw new Error( "You must provide a valid topic to create a subscription." );
46
+ }
47
+
40
48
  if ( arguments.length === 3 && typeof callback === "number" ) {
41
49
  priority = callback;
42
50
  callback = context;
@@ -58,14 +66,14 @@ var amplify = global.amplify = {
58
66
  if ( !subscriptions[ topic ] ) {
59
67
  subscriptions[ topic ] = [];
60
68
  }
61
-
69
+
62
70
  var i = subscriptions[ topic ].length - 1,
63
71
  subscriptionInfo = {
64
72
  callback: callback,
65
73
  context: context,
66
74
  priority: priority
67
75
  };
68
-
76
+
69
77
  for ( ; i >= 0; i-- ) {
70
78
  if ( subscriptions[ topic ][ i ].priority <= priority ) {
71
79
  subscriptions[ topic ].splice( i + 1, 0, subscriptionInfo );
@@ -82,7 +90,16 @@ var amplify = global.amplify = {
82
90
  return callback;
83
91
  },
84
92
 
85
- unsubscribe: function( topic, callback ) {
93
+ unsubscribe: function( topic, context, callback ) {
94
+ if ( typeof topic !== "string" ) {
95
+ throw new Error( "You must provide a valid topic to remove a subscription." );
96
+ }
97
+
98
+ if ( arguments.length === 2 ) {
99
+ callback = context;
100
+ context = null;
101
+ }
102
+
86
103
  if ( !subscriptions[ topic ] ) {
87
104
  return;
88
105
  }
@@ -92,11 +109,16 @@ var amplify = global.amplify = {
92
109
 
93
110
  for ( ; i < length; i++ ) {
94
111
  if ( subscriptions[ topic ][ i ].callback === callback ) {
95
- subscriptions[ topic ].splice( i, 1 );
96
- break;
112
+ if ( !context || subscriptions[ topic ][ i ].context === context ) {
113
+ subscriptions[ topic ].splice( i, 1 );
114
+
115
+ // Adjust counter and length for removed item
116
+ i--;
117
+ length--;
118
+ }
97
119
  }
98
120
  }
99
121
  }
100
122
  };
101
123
 
102
- }( this ) );
124
+ }( this ) );
@@ -1,14 +1,18 @@
1
1
  //= require amplify/core
2
+
2
3
  /*!
3
4
  * Amplify Request <%= Amplify::VERSION %>
4
- *
5
- * Copyright 2011 appendTo LLC. (http://appendto.com/team)
5
+ *
6
+ * Copyright 2011 - 2013 appendTo LLC. (http://appendto.com/team)
6
7
  * Dual licensed under the MIT or GPL licenses.
7
8
  * http://appendto.com/open-source-licenses
8
- *
9
+ *
9
10
  * http://amplifyjs.com
10
11
  */
12
+ /*global amplify*/
13
+
11
14
  (function( amplify, undefined ) {
15
+ 'use strict';
12
16
 
13
17
  function noop() {}
14
18
  function isFunction( obj ) {
@@ -54,12 +58,14 @@ amplify.request = function( resourceId, data, callback ) {
54
58
  resource = amplify.request.resources[ settings.resourceId ],
55
59
  success = settings.success || noop,
56
60
  error = settings.error || noop;
61
+
57
62
  settings.success = async( function( data, status ) {
58
63
  status = status || "success";
59
64
  amplify.publish( "request.success", settings, data, status );
60
65
  amplify.publish( "request.complete", settings, data, status );
61
66
  success( data, status );
62
67
  });
68
+
63
69
  settings.error = async( function( data, status ) {
64
70
  status = status || "error";
65
71
  amplify.publish( "request.error", settings, data, status );
@@ -103,13 +109,11 @@ amplify.request.define = function( resourceId, type, settings ) {
103
109
  }( amplify ) );
104
110
 
105
111
 
106
-
107
-
108
-
109
112
  (function( amplify, $, undefined ) {
113
+ 'use strict';
110
114
 
111
115
  var xhrProps = [ "status", "statusText", "responseText", "responseXML", "readyState" ],
112
- rurlData = /\{([^\}]+)\}/g;
116
+ rurlData = /\{([^\}]+)\}/g;
113
117
 
114
118
  amplify.request.types.ajax = function( defnSettings ) {
115
119
  defnSettings = $.extend({
@@ -117,7 +121,7 @@ amplify.request.types.ajax = function( defnSettings ) {
117
121
  }, defnSettings );
118
122
 
119
123
  return function( settings, request ) {
120
- var xhr,
124
+ var xhr, handleResponse,
121
125
  url = defnSettings.url,
122
126
  abort = request.abort,
123
127
  ajaxSettings = $.extend( true, {}, defnSettings, { data: settings.data } ),
@@ -134,7 +138,7 @@ amplify.request.types.ajax = function( defnSettings ) {
134
138
  return xhr.getResponseHeader( key );
135
139
  },
136
140
  overrideMimeType: function( type ) {
137
- return xhr.overrideMideType( type );
141
+ return xhr.overrideMimeType( type );
138
142
  },
139
143
  abort: function() {
140
144
  aborted = true;
@@ -152,28 +156,7 @@ amplify.request.types.ajax = function( defnSettings ) {
152
156
  }
153
157
  };
154
158
 
155
- amplify.publish( "request.ajax.preprocess",
156
- defnSettings, settings, ajaxSettings, ampXHR );
157
-
158
- $.extend( ajaxSettings, {
159
- success: function( data, status ) {
160
- handleResponse( data, status );
161
- },
162
- error: function( _xhr, status ) {
163
- handleResponse( null, status );
164
- },
165
- beforeSend: function( _xhr, _ajaxSettings ) {
166
- xhr = _xhr;
167
- ajaxSettings = _ajaxSettings;
168
- var ret = defnSettings.beforeSend ?
169
- defnSettings.beforeSend.call( this, ampXHR, ajaxSettings ) : true;
170
- return ret && amplify.publish( "request.before.ajax",
171
- defnSettings, settings, ajaxSettings, ampXHR );
172
- }
173
- });
174
- $.ajax( ajaxSettings );
175
-
176
- function handleResponse( data, status ) {
159
+ handleResponse = function( data, status ) {
177
160
  $.each( xhrProps, function( i, key ) {
178
161
  try {
179
162
  ampXHR[ key ] = xhr[ key ];
@@ -200,8 +183,62 @@ amplify.request.types.ajax = function( defnSettings ) {
200
183
  // this can happen if a request is aborted
201
184
  // TODO: figure out if this breaks polling or multi-part responses
202
185
  handleResponse = $.noop;
186
+ };
187
+
188
+ amplify.publish( "request.ajax.preprocess",
189
+ defnSettings, settings, ajaxSettings, ampXHR );
190
+
191
+ $.extend( ajaxSettings, {
192
+ isJSONP: function () {
193
+ return (/jsonp/gi).test(this.dataType);
194
+ },
195
+ cacheURL: function () {
196
+ if (!this.isJSONP()) {
197
+ return this.url;
198
+ }
199
+
200
+ var callbackName = 'callback';
201
+
202
+ // possible for the callback function name to be overridden
203
+ if (this.hasOwnProperty('jsonp')) {
204
+ if (this.jsonp !== false) {
205
+ callbackName = this.jsonp;
206
+ } else {
207
+ if (this.hasOwnProperty('jsonpCallback')) {
208
+ callbackName = this.jsonpCallback;
209
+ }
210
+ }
211
+ }
212
+
213
+ // search and replace callback parameter in query string with empty string
214
+ var callbackRegex = new RegExp('&?' + callbackName + '=[^&]*&?', 'gi');
215
+ return this.url.replace(callbackRegex, '');
216
+ },
217
+ success: function( data, status ) {
218
+ handleResponse( data, status );
219
+ },
220
+ error: function( _xhr, status ) {
221
+ handleResponse( null, status );
222
+ },
223
+ beforeSend: function( _xhr, _ajaxSettings ) {
224
+ xhr = _xhr;
225
+ ajaxSettings = _ajaxSettings;
226
+ var ret = defnSettings.beforeSend ?
227
+ defnSettings.beforeSend.call( this, ampXHR, ajaxSettings ) : true;
228
+ return ret && amplify.publish( "request.before.ajax",
229
+ defnSettings, settings, ajaxSettings, ampXHR );
230
+ }
231
+ });
232
+
233
+ // cache all JSONP requests
234
+ if (ajaxSettings.cache && ajaxSettings.isJSONP()) {
235
+ $.extend(ajaxSettings, {
236
+ cache: true
237
+ });
203
238
  }
204
239
 
240
+ $.ajax( ajaxSettings );
241
+
205
242
  request.abort = function() {
206
243
  ampXHR.abort();
207
244
  abort.call( this );
@@ -223,8 +260,8 @@ amplify.subscribe( "request.ajax.preprocess", function( defnSettings, settings,
223
260
 
224
261
  ajaxSettings.url = ajaxSettings.url.replace( rurlData, function ( m, key ) {
225
262
  if ( key in data ) {
226
- mappedKeys.push( key );
227
- return data[ key ];
263
+ mappedKeys.push( key );
264
+ return data[ key ];
228
265
  }
229
266
  });
230
267
 
@@ -265,13 +302,9 @@ var cache = amplify.request.cache = {
265
302
  _key: function( resourceId, url, data ) {
266
303
  data = url + data;
267
304
  var length = data.length,
268
- i = 0,
269
- checksum = chunk();
270
-
271
- while ( i < length ) {
272
- checksum ^= chunk();
273
- }
305
+ i = 0;
274
306
 
307
+ /*jshint bitwise:false*/
275
308
  function chunk() {
276
309
  return data.charCodeAt( i++ ) << 24 |
277
310
  data.charCodeAt( i++ ) << 16 |
@@ -279,6 +312,12 @@ var cache = amplify.request.cache = {
279
312
  data.charCodeAt( i++ ) << 0;
280
313
  }
281
314
 
315
+ var checksum = chunk();
316
+ while ( i < length ) {
317
+ checksum ^= chunk();
318
+ }
319
+ /*jshint bitwise:true*/
320
+
282
321
  return "request-" + resourceId + "-" + checksum;
283
322
  },
284
323
 
@@ -287,7 +326,7 @@ var cache = amplify.request.cache = {
287
326
  return function( resource, settings, ajaxSettings, ampXHR ) {
288
327
  // data is already converted to a string by the time we get here
289
328
  var cacheKey = cache._key( settings.resourceId,
290
- ajaxSettings.url, ajaxSettings.data ),
329
+ ajaxSettings.cacheURL(), ajaxSettings.data ),
291
330
  duration = resource.cache;
292
331
 
293
332
  if ( cacheKey in memoryStore ) {
@@ -312,7 +351,7 @@ if ( amplify.store ) {
312
351
  $.each( amplify.store.types, function( type ) {
313
352
  cache[ type ] = function( resource, settings, ajaxSettings, ampXHR ) {
314
353
  var cacheKey = cache._key( settings.resourceId,
315
- ajaxSettings.url, ajaxSettings.data ),
354
+ ajaxSettings.cacheURL(), ajaxSettings.data ),
316
355
  cached = amplify.store[ type ]( cacheKey );
317
356
 
318
357
  if ( cached ) {
@@ -320,7 +359,7 @@ if ( amplify.store ) {
320
359
  return false;
321
360
  }
322
361
  var success = ampXHR.success;
323
- ampXHR.success = function( data ) {
362
+ ampXHR.success = function( data ) {
324
363
  amplify.store[ type ]( cacheKey, data, { expires: resource.cache.expires } );
325
364
  success.apply( this, arguments );
326
365
  };
@@ -351,6 +390,8 @@ amplify.request.decoders = {
351
390
  } else if ( data.status === "error" ) {
352
391
  delete data.status;
353
392
  error( data, "error" );
393
+ } else {
394
+ error( null, "error" );
354
395
  }
355
396
  }
356
397
  };
@@ -358,11 +399,11 @@ amplify.request.decoders = {
358
399
  amplify.subscribe( "request.before.ajax", function( resource, settings, ajaxSettings, ampXHR ) {
359
400
  var _success = ampXHR.success,
360
401
  _error = ampXHR.error,
361
- decoder = $.isFunction( resource.decoder )
362
- ? resource.decoder
363
- : resource.decoder in amplify.request.decoders
364
- ? amplify.request.decoders[ resource.decoder ]
365
- : amplify.request.decoders._default;
402
+ decoder = $.isFunction( resource.decoder ) ?
403
+ resource.decoder :
404
+ resource.decoder in amplify.request.decoders ?
405
+ amplify.request.decoders[ resource.decoder ] :
406
+ amplify.request.decoders._default;
366
407
 
367
408
  if ( !decoder ) {
368
409
  return;
@@ -382,4 +423,4 @@ amplify.subscribe( "request.before.ajax", function( resource, settings, ajaxSett
382
423
  };
383
424
  });
384
425
 
385
- }( amplify, jQuery ) );
426
+ }( amplify, jQuery ) );
@@ -1,15 +1,15 @@
1
1
  /*!
2
2
  * Amplify Store - Persistent Client-Side Storage <%= Amplify::VERSION %>
3
- *
4
- * Copyright 2011 appendTo LLC. (http://appendto.com/team)
3
+ *
4
+ * Copyright 2011 - 2013 appendTo LLC. (http://appendto.com/team)
5
5
  * Dual licensed under the MIT or GPL licenses.
6
6
  * http://appendto.com/open-source-licenses
7
- *
7
+ *
8
8
  * http://amplifyjs.com
9
9
  */
10
10
  (function( amplify, undefined ) {
11
11
 
12
- var store = amplify.store = function( key, value, options, type ) {
12
+ var store = amplify.store = function( key, value, options ) {
13
13
  var type = store.type;
14
14
  if ( options && options.type && options.type in store.types ) {
15
15
  type = options.type;
@@ -30,9 +30,9 @@ store.addType = function( type, storage ) {
30
30
  options.type = type;
31
31
  return store( key, value, options );
32
32
  };
33
- }
33
+ };
34
34
  store.error = function() {
35
- return "amplify.store quota exceeded";
35
+ return "amplify.store quota exceeded";
36
36
  };
37
37
 
38
38
  var rprefix = /^__amplify__/;
@@ -112,11 +112,14 @@ function createFromStorageInterface( storageType, storage ) {
112
112
  // localStorage + sessionStorage
113
113
  // IE 8+, Firefox 3.5+, Safari 4+, Chrome 4+, Opera 10.5+, iPhone 2+, Android 2+
114
114
  for ( var webStorageType in { localStorage: 1, sessionStorage: 1 } ) {
115
- // try/catch for file protocol in Firefox
115
+ // try/catch for file protocol in Firefox and Private Browsing in Safari 5
116
116
  try {
117
- if ( window[ webStorageType ].getItem ) {
118
- createFromStorageInterface( webStorageType, window[ webStorageType ] );
119
- }
117
+ // Safari 5 in Private Browsing mode exposes localStorage
118
+ // but doesn't allow storing data, so we attempt to store and remove an item.
119
+ // This will unfortunately give us a false negative if we're at the limit.
120
+ window[ webStorageType ].setItem( "__amplify__", "x" );
121
+ window[ webStorageType ].removeItem( "__amplify__" );
122
+ createFromStorageInterface( webStorageType, window[ webStorageType ] );
120
123
  } catch( e ) {}
121
124
  }
122
125
 
@@ -195,7 +198,9 @@ if ( !store.types.localStorage && window.globalStorage ) {
195
198
  // http://www.w3.org/TR/REC-xml/#NT-Name
196
199
  // simplified to assume the starting character is valid
197
200
  // also removed colon as it is invalid in HTML attribute names
198
- key = key.replace( /[^-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u37f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g, "-" );
201
+ key = key.replace( /[^\-._0-9A-Za-z\xb7\xc0-\xd6\xd8-\xf6\xf8-\u037d\u037f-\u1fff\u200c-\u200d\u203f\u2040\u2070-\u218f]/g, "-" );
202
+ // adjust invalid starting character to deal with our simplified sanitization
203
+ key = key.replace( /^-/, "_-" );
199
204
 
200
205
  if ( value === undefined ) {
201
206
  attr = div.getAttribute( key );
@@ -290,4 +295,4 @@ if ( !store.types.localStorage && window.globalStorage ) {
290
295
  });
291
296
  }() );
292
297
 
293
- }( this.amplify = this.amplify || {} ) );
298
+ }( this.amplify = this.amplify || {} ) );
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amplify
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.1
5
- prerelease:
4
+ version: 1.1.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Scott González
@@ -15,30 +14,36 @@ authors:
15
14
  autorequire:
16
15
  bindir: bin
17
16
  cert_chain: []
18
- date: 2012-02-28 00:00:00.000000000Z
17
+ date: 2013-12-05 00:00:00.000000000 Z
19
18
  dependencies:
20
19
  - !ruby/object:Gem::Dependency
21
20
  name: jquery-rails
22
- requirement: &70318371991200 !ruby/object:Gem::Requirement
23
- none: false
21
+ requirement: !ruby/object:Gem::Requirement
24
22
  requirements:
25
- - - ~>
23
+ - - ! '>='
26
24
  - !ruby/object:Gem::Version
27
- version: '1.0'
25
+ version: '0'
28
26
  type: :runtime
29
27
  prerelease: false
30
- version_requirements: *70318371991200
28
+ version_requirements: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
31
33
  - !ruby/object:Gem::Dependency
32
34
  name: sprockets
33
- requirement: &70318371990720 !ruby/object:Gem::Requirement
34
- none: false
35
+ requirement: !ruby/object:Gem::Requirement
35
36
  requirements:
36
37
  - - ~>
37
38
  - !ruby/object:Gem::Version
38
39
  version: '2'
39
40
  type: :runtime
40
41
  prerelease: false
41
- version_requirements: *70318371990720
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ~>
45
+ - !ruby/object:Gem::Version
46
+ version: '2'
42
47
  description: AmplifyJS is a set of components designed to solve common web application
43
48
  problems with a simplistic API.
44
49
  email: alassek@lyconic.com
@@ -57,26 +62,25 @@ homepage: http://amplifyjs.com
57
62
  licenses:
58
63
  - MIT
59
64
  - GPL-2
65
+ metadata: {}
60
66
  post_install_message:
61
67
  rdoc_options: []
62
68
  require_paths:
63
69
  - lib
64
70
  required_ruby_version: !ruby/object:Gem::Requirement
65
- none: false
66
71
  requirements:
67
72
  - - ! '>='
68
73
  - !ruby/object:Gem::Version
69
74
  version: '0'
70
75
  required_rubygems_version: !ruby/object:Gem::Requirement
71
- none: false
72
76
  requirements:
73
77
  - - ! '>='
74
78
  - !ruby/object:Gem::Version
75
79
  version: '0'
76
80
  requirements: []
77
81
  rubyforge_project:
78
- rubygems_version: 1.8.8
82
+ rubygems_version: 2.1.10
79
83
  signing_key:
80
- specification_version: 3
84
+ specification_version: 4
81
85
  summary: A Javascript Component Library
82
86
  test_files: []