Skip to content
Browse files

removed mtv.store.coffee; updated Backbone.sync method to work with n…

…ewest Backbone.js
  • Loading branch information...
1 parent 123d134 commit 77ff79ae5c3a1e38ee4f06d5318c41eb9da99eb2 @rnagle rnagle committed Nov 15, 2011
Showing with 10 additions and 63 deletions.
  1. +4 −1 coffee/mtv.coffee
  2. +0 −54 coffee/mtv.store.coffee
  3. +4 −2 devjs/mtv.js
  4. +1 −1 mtv.min.js
  5. +1 −5 wp-plugin.php
View
5 coffee/mtv.coffee
@@ -46,10 +46,13 @@ window.MTV = new Object
# Custom Backbone sync function that works with wordpress ajax
#
if Backbone in window or window['Backbone'] isnt null
- Backbone.sync = (method, model, success, error) ->
+ Backbone.sync = (method, model, options) ->
data = if method is 'create' or method is 'update' then model.toJSON() else null
url = unless method is 'read' then "#{model.url()}/#{method}" else model.url()
+ success = options.success
+ error = options.error
+
MTV.do_ajax url, data, success, error
View
54 coffee/mtv.store.coffee
@@ -1,54 +0,0 @@
-unless $ then $ = jQuery
-
-#
-# Simple storage API
-# Uses HTML5 localStorage if available. Otherwise falls back to cookie storage.
-# Always uses a cookie to expire storage. Defaults to the length of the session.
-#
-window.MTV.Store = new Object
- expires: null # session
-
- get: (key) ->
- if @has_local_storage()
- json_data = if $.cookie(key + '-timer') then localStorage.getItem(key) else null
- else
- json_data = $.cookie(key)
-
- # Deserialize
- if json_data then JSON.parse json_data else no
-
- save: (key, val) ->
- # Prep data
- json_data = JSON.stringify val
-
- if @has_local_storage()
- $.cookie(key + '-timer', 'true',
- expires: @expires
- path: '/'
- )
- localStorage.setItem(key, json_data)
- else
- $.cookie(key, json_data,
- expires: @expires
- path: '/'
- )
-
- remove: (key) ->
- if @has_local_storage()
- $.cookie(key + '-timer', null,
- path: '/'
- )
- localStorage.removeItem(key)
- else
- $.cookie(key, null,
- path: '/'
- )
-
- has_local_storage: `function() {
- try {
- return 'localStorage' in window && window['localStorage'] !== null;
- } catch (e) {
- return false;
- }
- }`
-
View
6 devjs/mtv.js
@@ -67,10 +67,12 @@
}
});
if (__indexOf.call(window, Backbone) >= 0 || window['Backbone'] !== null) {
- Backbone.sync = function(method, model, success, error) {
- var data, url;
+ Backbone.sync = function(method, model, options) {
+ var data, error, success, url;
data = method === 'create' || method === 'update' ? model.toJSON() : null;
url = method !== 'read' ? "" + (model.url()) + "/" + method : model.url();
+ success = options.success;
+ error = options.error;
return MTV.do_ajax(url, data, success, error);
};
}
View
2 mtv.min.js
@@ -1 +1 @@
-(function(){var a,b=function(a,b){return function(){return a.apply(b,arguments)}},c=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(this[b]===a)return b;return-1};a||(a=jQuery),window.MTV=new Object({debugging:function(){return WordPress.DEBUG&&this.hasConsole()?!0:!1},hasConsole:function(){try{return"console"in window&&window.console!==null}catch(a){return!1}},do_ajax:function(c,d,e,f){var g,h;g=JSON.stringify(d),h={url:WordPress.ajaxurl,type:"POST",data:{action:"mtv",path:c,data:g},dataType:"json",success:b(function(a,b,c){this.debugging()&&(console.log("do_ajax: "+b),console.log(a),console.log(c));if(e)return e(a,b,c)},this),error:b(function(a,b,c){this.debugging()&&(console.log("do_ajax: "+b),console.log(a),console.log(c));if(f)return f(a,b,c)},this)};return this.debugging()?setTimeout(b(function(){return a.ajax(h)},this),2e3):a.ajax(h)}});if(c.call(window,Backbone)>=0||window.Backbone!==null)Backbone.sync=function(a,b,c,d){var e,f;e=a==="create"||a==="update"?b.toJSON():null,f=a!=="read"?""+b.url()+"/"+a:b.url();return MTV.do_ajax(f,e,c,d)}}).call(this)
+(function(){var a,b=function(a,b){return function(){return a.apply(b,arguments)}},c=Array.prototype.indexOf||function(a){for(var b=0,c=this.length;b<c;b++)if(this[b]===a)return b;return-1};a||(a=jQuery),window.MTV=new Object({debugging:function(){return WordPress.DEBUG&&this.hasConsole()?!0:!1},hasConsole:function(){try{return"console"in window&&window.console!==null}catch(a){return!1}},do_ajax:function(c,d,e,f){var g,h;g=JSON.stringify(d),h={url:WordPress.ajaxurl,type:"POST",data:{action:"mtv",path:c,data:g},dataType:"json",success:b(function(a,b,c){this.debugging()&&(console.log("do_ajax: "+b),console.log(a),console.log(c));if(e)return e(a,b,c)},this),error:b(function(a,b,c){this.debugging()&&(console.log("do_ajax: "+b),console.log(a),console.log(c));if(f)return f(a,b,c)},this)};return this.debugging()?setTimeout(b(function(){return a.ajax(h)},this),2e3):a.ajax(h)}});if(c.call(window,Backbone)>=0||window.Backbone!==null)Backbone.sync=function(a,b,c){var d,e,f,g;d=a==="create"||a==="update"?b.toJSON():null,g=a!=="read"?""+b.url()+"/"+a:b.url(),f=c.success,e=c.error;return MTV.do_ajax(g,d,f,e)}}).call(this)
View
6 wp-plugin.php
@@ -34,14 +34,10 @@
);
if ( defined('SCRIPT_DEBUG') && SCRIPT_DEBUG ) {
- wp_register_script('mtv',
+ wp_register_script('mtv-all',
plugins_url('/mtv/devjs/mtv.js'),
array('jquery'),
MTV_VERSION);
- wp_register_script('mtv-all',
- '',
- array('mtv'),
- MTV_VERSION);
$js_runtime_settings['DEBUG'] = true;

0 comments on commit 77ff79a

Please sign in to comment.
Something went wrong with that request. Please try again.