From 740a9bb8efe7100243bf1e7584951e4be7e18ffd Mon Sep 17 00:00:00 2001 From: fergalmoran Date: Thu, 2 May 2013 13:56:02 +0100 Subject: [PATCH] Minified syphon before compressor --- spa/management/commands/processmix.py | 2 +- static/js/app/site.js | 3 + static/js/libs/backbone/backbone.syphon.js | 468 +-------------------- templates/base.html | 2 +- 4 files changed, 6 insertions(+), 469 deletions(-) diff --git a/spa/management/commands/processmix.py b/spa/management/commands/processmix.py index 81be1ca..fece7d7 100644 --- a/spa/management/commands/processmix.py +++ b/spa/management/commands/processmix.py @@ -28,4 +28,4 @@ class Command(NoArgsCommand): mix.delete() print me.message except Exception, ex: - raise CommandError(ex.message) \ No newline at end of file + raise CommandError(ex.message) diff --git a/static/js/app/site.js b/static/js/app/site.js index f39515d..631d853 100644 --- a/static/js/app/site.js +++ b/static/js/app/site.js @@ -25,8 +25,11 @@ if (com.podnoms.settings.isDebug) { $('#ajax-request').hide(); } }); +}else{ + $('#ajax-request').hide(); } + $(document).ajaxSend(function (event, xhr, settings) { function getCookie(name) { var cookieValue = null; diff --git a/static/js/libs/backbone/backbone.syphon.js b/static/js/libs/backbone/backbone.syphon.js index 13aa4a9..95efe7f 100644 --- a/static/js/libs/backbone/backbone.syphon.js +++ b/static/js/libs/backbone/backbone.syphon.js @@ -2,470 +2,4 @@ // Copyright (c)2012 Derick Bailey, Muted Solutions, LLC. // Distributed under MIT license // http://github.com/derickbailey/backbone.syphon -Backbone.Syphon = (function (Backbone, $, _) { - var Syphon = {}; - - // Ignore Element Types - // -------------------- - - // Tell Syphon to ignore all elements of these types. You can - // push new types to ignore directly in to this array. - Syphon.ignoredTypes = ["button", "submit", "reset", "fieldset"]; - - // Syphon - // ------ - - // Get a JSON object that represents - // all of the form inputs, in this view. - // Alternately, pass a form element directly - // in place of the view. - Syphon.serialize = function (view, options) { - var data = {}; - - // Build the configuration - var config = buildConfig(options); - - // Get all of the elements to process - var elements = getInputElements(view, config); - - // Process all of the elements - _.each(elements, function (el) { - var $el = $(el); - var type = getElementType($el); - - // Get the key for the input - var keyExtractor = config.keyExtractors.get(type); - var key = keyExtractor($el); - - // Get the value for the input - var inputReader = config.inputReaders.get(type); - var value = inputReader($el); - - // Get the key assignment validator and make sure - // it's valid before assigning the value to the key - var validKeyAssignment = config.keyAssignmentValidators.get(type); - if (validKeyAssignment($el, key, value)) { - var keychain = config.keySplitter(key); - data = assignKeyValue(data, keychain, value); - } - }); - - // Done; send back the results. - return data; - }; - - // Use the given JSON object to populate - // all of the form inputs, in this view. - // Alternately, pass a form element directly - // in place of the view. - Syphon.deserialize = function (view, data, options) { - // Build the configuration - var config = buildConfig(options); - - // Get all of the elements to process - var elements = getInputElements(view, config); - - // Flatten the data structure that we are deserializing - var flattenedData = flattenData(config, data); - - // Process all of the elements - _.each(elements, function (el) { - var $el = $(el); - var type = getElementType($el); - - // Get the key for the input - var keyExtractor = config.keyExtractors.get(type); - var key = keyExtractor($el); - - // Get the input writer and the value to write - var inputWriter = config.inputWriters.get(type); - var value = flattenedData[key]; - - // Write the value to the input - inputWriter($el, value); - }); - }; - - // Helpers - // ------- - - // Retrieve all of the form inputs - // from the form - var getInputElements = function (view, config) { - var form = getForm(view); - var elements = form.elements; - - elements = _.reject(elements, function (el) { - var reject; - var type = getElementType(el); - var extractor = config.keyExtractors.get(type); - var identifier = extractor($(el)); - - var foundInIgnored = _.include(config.ignoredTypes, type); - var foundInInclude = _.include(config.include, identifier); - var foundInExclude = _.include(config.exclude, identifier); - - if (foundInInclude) { - reject = false; - } else { - if (config.include) { - reject = true; - } else { - reject = (foundInExclude || foundInIgnored); - } - } - - return reject; - }); - - return elements; - }; - - // Determine what type of element this is. It - // will either return the `type` attribute of - // an `` element, or the `tagName` of - // the element when the element is not an ``. - var getElementType = function (el) { - var typeAttr; - var $el = $(el); - var tagName = $el[0].tagName; - var type = tagName; - - if (tagName.toLowerCase() === "input") { - typeAttr = $el.attr("type"); - if (typeAttr) { - type = typeAttr; - } else { - type = "text"; - } - } - - // Always return the type as lowercase - // so it can be matched to lowercase - // type registrations. - return type.toLowerCase(); - }; - - // If a form element is given, just return it. - // Otherwise, get the form element from the view. - var getForm = function (viewOrForm) { - if (_.isUndefined(viewOrForm.$el) && viewOrForm.tagName.toLowerCase() === 'form') { - return viewOrForm; - } else { - return viewOrForm.$el.is("form") ? viewOrForm.el : viewOrForm.$("form")[0]; - } - }; - - // Build a configuration object and initialize - // default values. - var buildConfig = function (options) { - var config = _.clone(options) || {}; - - config.ignoredTypes = _.clone(Syphon.ignoredTypes); - config.inputReaders = config.inputReaders || Syphon.InputReaders; - config.inputWriters = config.inputWriters || Syphon.InputWriters; - config.keyExtractors = config.keyExtractors || Syphon.KeyExtractors; - config.keySplitter = config.keySplitter || Syphon.KeySplitter; - config.keyJoiner = config.keyJoiner || Syphon.KeyJoiner; - config.keyAssignmentValidators = config.keyAssignmentValidators || Syphon.KeyAssignmentValidators; - - return config; - }; - - // Assigns `value` to a parsed JSON key. - // - // The first parameter is the object which will be - // modified to store the key/value pair. - // - // The second parameter accepts an array of keys as a - // string with an option array containing a - // single string as the last option. - // - // The third parameter is the value to be assigned. - // - // Examples: - // - // `["foo", "bar", "baz"] => {foo: {bar: {baz: "value"}}}` - // - // `["foo", "bar", ["baz"]] => {foo: {bar: {baz: ["value"]}}}` - // - // When the final value is an array with a string, the key - // becomes an array, and values are pushed in to the array, - // allowing multiple fields with the same name to be - // assigned to the array. - var assignKeyValue = function (obj, keychain, value) { - if (!keychain) { - return obj; - } - - var key = keychain.shift(); - - // build the current object we need to store data - if (!obj[key]) { - obj[key] = _.isArray(key) ? [] : {}; - } - - // if it's the last key in the chain, assign the value directly - if (keychain.length === 0) { - if (_.isArray(obj[key])) { - obj[key].push(value); - } else { - obj[key] = value; - } - } - - // recursive parsing of the array, depth-first - if (keychain.length > 0) { - assignKeyValue(obj[key], keychain, value); - } - - return obj; - }; - - // Flatten the data structure in to nested strings, using the - // provided `KeyJoiner` function. - // - // Example: - // - // This input: - // - // ```js - // { - // widget: "wombat", - // foo: { - // bar: "baz", - // baz: { - // quux: "qux" - // }, - // quux: ["foo", "bar"] - // } - // } - // ``` - // - // With a KeyJoiner that uses [ ] square brackets, - // should produce this output: - // - // ```js - // { - // "widget": "wombat", - // "foo[bar]": "baz", - // "foo[baz][quux]": "qux", - // "foo[quux]": ["foo", "bar"] - // } - // ``` - var flattenData = function (config, data, parentKey) { - var flatData = {}; - - _.each(data, function (value, keyName) { - var hash = {}; - - // If there is a parent key, join it with - // the current, child key. - if (parentKey) { - keyName = config.keyJoiner(parentKey, keyName); - } - - if (_.isArray(value)) { - keyName += "[]"; - hash[keyName] = value; - } else if (_.isObject(value)) { - hash = flattenData(config, value, keyName); - } else { - hash[keyName] = value; - } - - // Store the resulting key/value pairs in the - // final flattened data object - _.extend(flatData, hash); - }); - - return flatData; - }; - - return Syphon; -})(Backbone, jQuery, _); - -// Type Registry -// ------------- - -// Type Registries allow you to register something to -// an input type, and retrieve either the item registered -// for a specific type or the default registration -Backbone.Syphon.TypeRegistry = function () { - this.registeredTypes = {}; -}; - -// Borrow Backbone's `extend` keyword for our TypeRegistry -Backbone.Syphon.TypeRegistry.extend = Backbone.Model.extend; - -_.extend(Backbone.Syphon.TypeRegistry.prototype, { - - // Get the registered item by type. If nothing is - // found for the specified type, the default is - // returned. - get: function (type) { - var item = this.registeredTypes[type]; - - if (!item) { - item = this.registeredTypes["default"]; - } - - return item; - }, - - // Register a new item for a specified type - register: function (type, item) { - this.registeredTypes[type] = item; - }, - - // Register a default item to be used when no - // item for a specified type is found - registerDefault: function (item) { - this.registeredTypes["default"] = item; - }, - - // Remove an item from a given type registration - unregister: function (type) { - if (this.registeredTypes[type]) { - delete this.registeredTypes[type]; - } - } -}); - - -// Key Extractors -// -------------- - -// Key extractors produce the "key" in `{key: "value"}` -// pairs, when serializing. -Backbone.Syphon.KeyExtractorSet = Backbone.Syphon.TypeRegistry.extend(); - -// Built-in Key Extractors -Backbone.Syphon.KeyExtractors = new Backbone.Syphon.KeyExtractorSet(); - -// The default key extractor, which uses the -// input element's "id" attribute -Backbone.Syphon.KeyExtractors.registerDefault(function ($el) { - return $el.prop("name"); -}); - - -// Input Readers -// ------------- - -// Input Readers are used to extract the value from -// an input element, for the serialized object result -Backbone.Syphon.InputReaderSet = Backbone.Syphon.TypeRegistry.extend(); - -// Built-in Input Readers -Backbone.Syphon.InputReaders = new Backbone.Syphon.InputReaderSet(); - -// The default input reader, which uses an input -// element's "value" -Backbone.Syphon.InputReaders.registerDefault(function ($el) { - return $el.val(); -}); - -// Checkbox reader, returning a boolean value for -// whether or not the checkbox is checked. -Backbone.Syphon.InputReaders.register("checkbox", function ($el) { - var checked = $el.prop("checked"); - return checked; -}); - - -// Input Writers -// ------------- - -// Input Writers are used to insert a value from an -// object into an input element. -Backbone.Syphon.InputWriterSet = Backbone.Syphon.TypeRegistry.extend(); - -// Built-in Input Writers -Backbone.Syphon.InputWriters = new Backbone.Syphon.InputWriterSet(); - -// The default input writer, which sets an input -// element's "value" -Backbone.Syphon.InputWriters.registerDefault(function ($el, value) { - $el.val(value); -}); - -// Checkbox writer, set whether or not the checkbox is checked -// depending on the boolean value. -Backbone.Syphon.InputWriters.register("checkbox", function ($el, value) { - $el.prop("checked", value); -}); - -// Radio button writer, set whether or not the radio button is -// checked. The button should only be checked if it's value -// equals the given value. -Backbone.Syphon.InputWriters.register("radio", function ($el, value) { - $el.prop("checked", $el.val() === value); -}); - -// Key Assignment Validators -// ------------------------- - -// Key Assignment Validators are used to determine whether or not a -// key should be assigned to a value, after the key and value have been -// extracted from the element. This is the last opportunity to prevent -// bad data from getting serialized to your object. - -Backbone.Syphon.KeyAssignmentValidatorSet = Backbone.Syphon.TypeRegistry.extend(); - -// Build-in Key Assignment Validators -Backbone.Syphon.KeyAssignmentValidators = new Backbone.Syphon.KeyAssignmentValidatorSet(); - -// Everything is valid by default -Backbone.Syphon.KeyAssignmentValidators.registerDefault(function () { - return true; -}); - -// But only the "checked" radio button for a given -// radio button group is valid -Backbone.Syphon.KeyAssignmentValidators.register("radio", function ($el, key, value) { - return $el.prop("checked"); -}); - - -// Backbone.Syphon.KeySplitter -// --------------------------- - -// This function is used to split DOM element keys in to an array -// of parts, which are then used to create a nested result structure. -// returning `["foo", "bar"]` results in `{foo: { bar: "value" }}`. -// -// Override this method to use a custom key splitter, such as: -// ``, `return key.split(".")` -Backbone.Syphon.KeySplitter = function (key) { - var matches = key.match(/[^\[\]]+/g); - - if (key.indexOf("[]") === key.length - 2) { - lastKey = matches.pop(); - matches.push([lastKey]); - } - - return matches; -} - - -// Backbone.Syphon.KeyJoiner -// ------------------------- - -// Take two segments of a key and join them together, to create the -// de-normalized key name, when deserializing a data structure back -// in to a form. -// -// Example: -// -// With this data strucutre `{foo: { bar: {baz: "value", quux: "another"} } }`, -// the key joiner will be called with these parameters, and assuming the -// join happens with "[ ]" square brackets, the specified output: -// -// `KeyJoiner("foo", "bar")` //=> "foo[bar]" -// `KeyJoiner("foo[bar]", "baz")` //=> "foo[bar][baz]" -// `KeyJoiner("foo[bar]", "quux")` //=> "foo[bar][quux]" - -Backbone.Syphon.KeyJoiner = function (parentKey, childKey) { - return parentKey + "[" + childKey + "]"; -} \ No newline at end of file +Backbone.Syphon=function(a,b,c){var d={};d.ignoredTypes=["button","submit","reset","fieldset"],d.serialize=function(a,d){var g={},j=h(d),k=e(a,j);return c.each(k,function(a){var c=b(a),d=f(c),e=j.keyExtractors.get(d),h=e(c),k=j.inputReaders.get(d),l=k(c),m=j.keyAssignmentValidators.get(d);if(m(c,h,l)){var n=j.keySplitter(h);g=i(g,n,l)}}),g},d.deserialize=function(a,d,g){var i=h(g),k=e(a,i),l=j(i,d);c.each(k,function(a){var c=b(a),d=f(c),e=i.keyExtractors.get(d),g=e(c),h=i.inputWriters.get(d),j=l[g];h(c,j)})};var e=function(a,d){var e=g(a),h=e.elements;return h=c.reject(h,function(a){var e,g=f(a),h=d.keyExtractors.get(g),i=h(b(a)),j=c.include(d.ignoredTypes,g),k=c.include(d.include,i),l=c.include(d.exclude,i);return k?e=!1:d.include?e=!0:e=l||j,e}),h},f=function(a){var c,d=b(a),e=d[0].tagName,f=e;return e.toLowerCase()==="input"&&(c=d.attr("type"),c?f=c:f="text"),f.toLowerCase()},g=function(a){return c.isUndefined(a.$el)&&a.tagName.toLowerCase()==="form"?a:a.$el.is("form")?a.el:a.$("form")[0]},h=function(a){var b=c.clone(a)||{};return b.ignoredTypes=c.clone(d.ignoredTypes),b.inputReaders=b.inputReaders||d.InputReaders,b.inputWriters=b.inputWriters||d.InputWriters,b.keyExtractors=b.keyExtractors||d.KeyExtractors,b.keySplitter=b.keySplitter||d.KeySplitter,b.keyJoiner=b.keyJoiner||d.KeyJoiner,b.keyAssignmentValidators=b.keyAssignmentValidators||d.KeyAssignmentValidators,b},i=function(a,b,d){if(!b)return a;var e=b.shift();return a[e]||(a[e]=c.isArray(e)?[]:{}),b.length===0&&(c.isArray(a[e])?a[e].push(d):a[e]=d),b.length>0&&i(a[e],b,d),a},j=function(a,b,d){var e={};return c.each(b,function(b,f){var g={};d&&(f=a.keyJoiner(d,f)),c.isArray(b)?(f+="[]",g[f]=b):c.isObject(b)?g=j(a,b,f):g[f]=b,c.extend(e,g)}),e};return d}(Backbone,jQuery,_),Backbone.Syphon.TypeRegistry=function(){this.registeredTypes={}},Backbone.Syphon.TypeRegistry.extend=Backbone.Model.extend,_.extend(Backbone.Syphon.TypeRegistry.prototype,{get:function(a){var b=this.registeredTypes[a];return b||(b=this.registeredTypes["default"]),b},register:function(a,b){this.registeredTypes[a]=b},registerDefault:function(a){this.registeredTypes["default"]=a},unregister:function(a){this.registeredTypes[a]&&delete this.registeredTypes[a]}}),Backbone.Syphon.KeyExtractorSet=Backbone.Syphon.TypeRegistry.extend(),Backbone.Syphon.KeyExtractors=new Backbone.Syphon.KeyExtractorSet,Backbone.Syphon.KeyExtractors.registerDefault(function(a){return a.prop("name")}),Backbone.Syphon.InputReaderSet=Backbone.Syphon.TypeRegistry.extend(),Backbone.Syphon.InputReaders=new Backbone.Syphon.InputReaderSet,Backbone.Syphon.InputReaders.registerDefault(function(a){return a.val()}),Backbone.Syphon.InputReaders.register("checkbox",function(a){var b=a.prop("checked");return b}),Backbone.Syphon.InputWriterSet=Backbone.Syphon.TypeRegistry.extend(),Backbone.Syphon.InputWriters=new Backbone.Syphon.InputWriterSet,Backbone.Syphon.InputWriters.registerDefault(function(a,b){a.val(b)}),Backbone.Syphon.InputWriters.register("checkbox",function(a,b){a.prop("checked",b)}),Backbone.Syphon.InputWriters.register("radio",function(a,b){a.prop("checked",a.val()===b)}),Backbone.Syphon.KeyAssignmentValidatorSet=Backbone.Syphon.TypeRegistry.extend(),Backbone.Syphon.KeyAssignmentValidators=new Backbone.Syphon.KeyAssignmentValidatorSet,Backbone.Syphon.KeyAssignmentValidators.registerDefault(function(){return!0}),Backbone.Syphon.KeyAssignmentValidators.register("radio",function(a,b,c){return a.prop("checked")}),Backbone.Syphon.KeySplitter=function(a){var b=a.match(/[^\[\]]+/g);return a.indexOf("[]")===a.length-2&&(lastKey=b.pop(),b.push([lastKey])),b},Backbone.Syphon.KeyJoiner=function(a,b){return a+"["+b+"]"}; diff --git a/templates/base.html b/templates/base.html index 34a8a6c..58d236f 100644 --- a/templates/base.html +++ b/templates/base.html @@ -71,9 +71,9 @@ - +