diff --git a/.gitignore b/.gitignore index 16abdd7a..4ed21c61 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ cps/static/[0-9]* .idea/ *.bak *.log.* +tags diff --git a/cps/static/js/context.js b/cps/static/js/context.js new file mode 100644 index 00000000..711a91be --- /dev/null +++ b/cps/static/js/context.js @@ -0,0 +1,147 @@ +/*! + * context.js Library associated with > v0.9.6.2 of intention.js + * http://intentionjs.com/ + * + * Copyright 2011, 2013 Dowjones and other contributors + * Released under the MIT license + * + */ + +(function () { + + 'use strict'; + var context = function($, Intention){ + + // create a brand spankin new intention object + var intent=new Intention(), + // placeholder for the horizontal axis + horizontal_axis, + orientation_axis; + + // throttle funtion used for keeping calls to the resize responive + // callback to a minimum + function throttle(callback, interval){ + var lastExec = new Date(), + timer = null; + + return function(e){ + var d = new Date(); + if (d-lastExec < interval) { + if (timer) { + window.clearTimeout(timer); + } + var callbackWrapper = function(event){ + return function(){ + callback(event); + }; + }; + timer = window.setTimeout(callbackWrapper(e), interval); + return false; + } + callback(e); + lastExec = d; + }; + } + + // catchall + // ======================================================================= + intent.responsive([{name:'base'}]).respond('base'); + + // width context? + // ======================================================================= + horizontal_axis = intent.responsive({ + ID:'width', + contexts: [ + {name:'standard', min:840}, + {name:'tablet', min:510}, + {name:'mobile', min:0}], + // compare the return value of the callback to each context + // return true for a match + matcher: function(test, context){ + if(typeof test === 'string'){ + + return test === context.name; + } + return test>=context.min; + }, + // callback, return value is passed to matcher() + // to compare against current context + measure: function(arg){ + + if(typeof arg === 'string'){ + return arg; + } + + return $(window).width(); + }}); + + // orientation context? + // ======================================================================= + orientation_axis = intent.responsive({ + ID:'orientation', + contexts: [{name:'portrait', rotation: 0}, + {name:'landscape', rotation:90}], + matcher: function(measure, ctx){ + return measure === ctx.rotation; + }, + measure: function(){ + var test = Math.abs(window.orientation); + if(test > 0) { + test = 180 - test; + } + return test; + } + }); + + // ONE TIME CHECK AXES: + // touch device? + // ======================================================================= + intent.responsive({ + ID:'touch', + contexts:[{name:'touch'}], + matcher: function() { + return "ontouchstart" in window; + }}).respond(); + + // retina display? + // ======================================================================= + intent.responsive({ + ID: 'highres', + // contexts + contexts:[{name:'highres'}], + // matching: + matcher: function(){ + return window.devicePixelRatio > 1; + }}).respond(); + + // bind events to the window + $(window).on('resize', throttle(horizontal_axis.respond, 100)) + .on('orientationchange', horizontal_axis.respond) + .on('orientationchange', orientation_axis.respond); + + // register the current width and orientation without waiting for a window + // resize + horizontal_axis.respond(); + orientation_axis.respond(); + + $(function(){ + // at doc ready grab all of the elements in the doc + intent.elements(document); + }); + + // return the intention object so that it can be extended by other plugins + return intent; + }; + + (function (root, factory) { + if (typeof define === 'function' && define.amd) { + // AMD. Register as an anonymous module. + define('context', ['jquery', 'intention'], factory); + } else { + // Browser globals + root.intent = factory(root.jQuery, root.Intention); + } + }(this, function ($, Intention) { + return context($, Intention); + })); +}).call(this); \ No newline at end of file diff --git a/cps/static/js/intention.js b/cps/static/js/intention.js new file mode 100644 index 00000000..69e674f9 --- /dev/null +++ b/cps/static/js/intention.js @@ -0,0 +1,564 @@ +/*! + * intention.js Library v0.9.7.2 + * http://intentionjs.com/ + * + * Copyright 2011, 2013 Dowjones and other contributors + * Released under the MIT license + * + */ + +(function(root, factory) { + + 'use strict'; + + if (typeof define === 'function' && define.amd) { + define('intention', ['jquery', 'underscore'], factory); + } else { + root.Intention = factory(root.jQuery, root._); + } +}(this, function($, _) { + 'use strict'; + + var Intention = function(params){ + var intent = _.extend(this, params, + {_listeners:{}, contexts:[], elms:$(), axes:{}, priority:[]}); + + return intent; + }; + + Intention.prototype = { + + // public methods + responsive:function responsive(contexts, options){ + // for generating random ids for axis when not specified + var idChars = 'abcdefghijklmnopqrstuvwxyz0123456789', + id='', i; + + // create a random id for the axis + for(i=0; i<5; i++){ + id += idChars[Math.floor(Math.random() * idChars.length)]; + } + var defaults = { + // if no matcher function is specified expect to compare a + // string to the ctx.name property + matcher: function(measure, ctx){ + return measure === ctx.name; + }, + // function takes one arg and returns it + measure: _.identity, + ID: id + }; + + if(_.isObject(options) === false) { + options = {}; + } + + if((_.isArray(contexts)) && (_.isArray(contexts[0].contexts))){ + _.each(contexts, function(axis){ + responsive.apply(this, axis); + }, this); + return; + } + + if((_.isArray(contexts) === false) && _.isObject(contexts)){ + options = contexts; + } else { + options.contexts = contexts; + } + + // fill in the options + options = _.extend({}, defaults, options); + + // bind an the respond function to the axis ID and prefix it + // with an underscore so that it does not get whomped accidentally + this.on('_' + options.ID + ':', _.bind( + function(e){ + this.axes = this._contextualize( + options.ID, e.context, this.axes); + this._respond(this.axes, this.elms); + + }, this)); + + var axis = { + ID:options.ID, + current:null, + contexts:options.contexts, + respond:_.bind(this._responder(options.ID, options.contexts, + options.matcher, options.measure), this) + }; + + this.axes[options.ID] = axis; + + this.axes.__keys__ = this.priority; + + this.priority.unshift(options.ID); + + return axis; + }, + + elements: function(scope){ + + // find all responsive elms in a specific dom scope + if(!scope){ + scope = document; + } + + $('[data-intent],[intent],[data-in],[in]', + scope).each(_.bind(function(i, elm){ + this.add($(elm)); + }, this)); + + return this; + }, + + add: function(elms, options){ + + var spec; + + if(!options) { + options = {}; + } + + // is expecting a jquery object + elms.each(_.bind(function(i, elm){ + var exists = false; + this.elms.each(function(i, respElm){ + if(elm === respElm) { + exists=true; + return false; + } + return true; + }); + + if(exists === false){ + // create the elements responsive data + spec = this._fillSpec( + _.extend(options, this._attrsToSpec(elm.attributes, this.axes))); + // make any appropriate changes based on the current contexts + this._makeChanges($(elm), spec, this.axes); + + this.elms.push({ + elm: elm, + spec: spec + }); + } + + }, this)); + + return this; + }, + + remove: function(elms){ + // is expecting a jquery object + var respElms = this.elms; + // elms to remove + elms.each(function(i, elm){ + // elms to check against + respElms.each(function(i, candidate){ + if(elm === candidate.elm){ + respElms.splice(i, 1); + // found the match, break the loop + return false; + } + return true; + }); + }); + return this; + }, + + is: function(ctxName){ + var axes = this.axes; + return _.some(axes.__keys__, function(key){ + return ctxName === axes[key].current; + }); + }, + + current: function(axisName){ + if(this.axes.hasOwnProperty(axisName)){ + return this.axes[axisName].current; + } else { + return false; + } + }, + + // code and concept taken from simple implementation of + // observer pattern outlined here: + // http://www.nczonline.net/blog/2010/03/09/custom-events-in-javascript/ + on: function(type, listener){ + + var events = type.split(' '), + i=0; + + for(i;i - + diff --git a/cps/templates/user_edit.html b/cps/templates/user_edit.html index d8403fc1..bb6368d9 100644 --- a/cps/templates/user_edit.html +++ b/cps/templates/user_edit.html @@ -23,16 +23,14 @@ - {% if not content.role_anonymous() %}
- {% endif %}