From c7e2f89bc4f026e00b1d8a3534bf1c5737d6c755 Mon Sep 17 00:00:00 2001 From: George Schneeloch Date: Tue, 6 Oct 2015 14:38:47 -0400 Subject: [PATCH 1/2] Added spin.js --- bower.json | 14 +- ui/static/bower/spin.js/.bower.json | 28 ++ ui/static/bower/spin.js/.gitignore | 6 + ui/static/bower/spin.js/.jshintrc | 28 ++ ui/static/bower/spin.js/.npmignore | 4 + ui/static/bower/spin.js/.spmignore | 1 + ui/static/bower/spin.js/LICENSE.md | 22 ++ ui/static/bower/spin.js/README.md | 21 ++ ui/static/bower/spin.js/bower.json | 17 ++ ui/static/bower/spin.js/jquery.spin.js | 79 ++++++ ui/static/bower/spin.js/spin.js | 377 +++++++++++++++++++++++++ ui/static/bower/spin.js/spin.min.js | 2 + ui/static/ui/js/require_config.js | 1 + 13 files changed, 593 insertions(+), 7 deletions(-) create mode 100644 ui/static/bower/spin.js/.bower.json create mode 100644 ui/static/bower/spin.js/.gitignore create mode 100644 ui/static/bower/spin.js/.jshintrc create mode 100644 ui/static/bower/spin.js/.npmignore create mode 100644 ui/static/bower/spin.js/.spmignore create mode 100644 ui/static/bower/spin.js/LICENSE.md create mode 100644 ui/static/bower/spin.js/README.md create mode 100644 ui/static/bower/spin.js/bower.json create mode 100644 ui/static/bower/spin.js/jquery.spin.js create mode 100644 ui/static/bower/spin.js/spin.js create mode 100644 ui/static/bower/spin.js/spin.min.js diff --git a/bower.json b/bower.json index 37a60c4f..1ebb9af3 100644 --- a/bower.json +++ b/bower.json @@ -9,17 +9,17 @@ "license": "AGPLv3", "dependencies": { "bootstrap": "~3.3.5", - "requirejs": "~2.1.17", - "icheck": "~1.0.2", "components-font-awesome": "~4.3.0", + "history.js": "~1.8.0", + "icheck": "~1.0.2", + "lodash": "~3.9.3", "modernizr": "~2.8.3", - "retina.js": "~1.3.0", "react": "0.13.3", + "react-infinite": "~0.4.1", + "requirejs": "~2.1.17", + "retina.js": "~1.3.0", "select2": "~4.0.0", "select2-bootstrap-theme": "~0.1.0-beta.4", - "lodash": "~3.9.3", - "react-infinite": "~0.4.1", - "uri.js": "~1.16.0", - "history.js": "~1.8.0" + "uri.js": "~1.16.0" } } diff --git a/ui/static/bower/spin.js/.bower.json b/ui/static/bower/spin.js/.bower.json new file mode 100644 index 00000000..18ad56e4 --- /dev/null +++ b/ui/static/bower/spin.js/.bower.json @@ -0,0 +1,28 @@ +{ + "name": "spin.js", + "main": "spin.js", + "dependencies": {}, + "readme": "README.md", + "repository": { + "type": "git", + "url": "git://github.com/fgnass/spin.js.git" + }, + "ignore": [ + "Gruntfile.js", + "site", + "bower.json", + "component.json", + "package.json" + ], + "homepage": "https://github.com/fgnass/spin.js", + "version": "2.3.2", + "_release": "2.3.2", + "_resolution": { + "type": "version", + "tag": "2.3.2", + "commit": "5a9ea41651105302fe76d15cb294070c5863e759" + }, + "_source": "git://github.com/fgnass/spin.js.git", + "_target": "2.x", + "_originalSource": "spin.js" +} \ No newline at end of file diff --git a/ui/static/bower/spin.js/.gitignore b/ui/static/bower/spin.js/.gitignore new file mode 100644 index 00000000..14fc0137 --- /dev/null +++ b/ui/static/bower/spin.js/.gitignore @@ -0,0 +1,6 @@ +.DS_Store +.grunt +node_modules +site/spin.js +site/spin.min.js +site/jquery.spin.js \ No newline at end of file diff --git a/ui/static/bower/spin.js/.jshintrc b/ui/static/bower/spin.js/.jshintrc new file mode 100644 index 00000000..29cc643a --- /dev/null +++ b/ui/static/bower/spin.js/.jshintrc @@ -0,0 +1,28 @@ +{ + /* Additional globals */ + "predef": [ + "define", + "module", + "require" + ], + + /* Enforcing Options */ + + "immed" : true, // Switches on warnings for immediately invoked functions which are not wrapped in parenthesis + "latedef" : true, // Switches on warnings for using variables or functions prior of their definition + "newcap" : true, // Switches on warnings if uncapitalised constructor function names are being used + "noarg" : true, // Switches on warnings when arguments.caller and arguments.callee are being used + "nonew" : true, // Switches on warnings when no "new" keyword is being used for constructor functions + "regexp" : true, // Switches on warnings for unsafe usage of '.' in regular expressions + "undef" : true, // Switches on warnings when using undeclared variables + "trailing" : true, // Switches on warnings for using trailing whitespace at the end of lines + + /* Relaxing Options */ + + "asi" : true, // Switches off warnings about missing semi-colons + "laxcomma" : true, // Switches off warnings about leading commas in multi-line var declarations + + /* Environments */ + + "browser" : true // Allows the use of undefined globals exposed by modern browsers, i.e. window +} diff --git a/ui/static/bower/spin.js/.npmignore b/ui/static/bower/spin.js/.npmignore new file mode 100644 index 00000000..0d05022e --- /dev/null +++ b/ui/static/bower/spin.js/.npmignore @@ -0,0 +1,4 @@ +site +Gruntfile.js +bower.json +component.json \ No newline at end of file diff --git a/ui/static/bower/spin.js/.spmignore b/ui/static/bower/spin.js/.spmignore new file mode 100644 index 00000000..1320f90e --- /dev/null +++ b/ui/static/bower/spin.js/.spmignore @@ -0,0 +1 @@ +site diff --git a/ui/static/bower/spin.js/LICENSE.md b/ui/static/bower/spin.js/LICENSE.md new file mode 100644 index 00000000..764ddec5 --- /dev/null +++ b/ui/static/bower/spin.js/LICENSE.md @@ -0,0 +1,22 @@ +The MIT License +=============== + +Copyright (c) 2011-2015 Felix Gnass [fgnass at gmail dot com] + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/ui/static/bower/spin.js/README.md b/ui/static/bower/spin.js/README.md new file mode 100644 index 00000000..b2da827e --- /dev/null +++ b/ui/static/bower/spin.js/README.md @@ -0,0 +1,21 @@ +# spin.js [![JS.ORG](https://img.shields.io/badge/js.org-spin-ffb400.svg?style=flat-square)](http://js.org) + +An animated CSS3 loading spinner with VML fallback for IE. + + * No images, no external CSS + * No dependencies + * Highly configurable + * Resolution independent + * Uses VML as fallback in old IEs + * Uses @keyframe animations, falling back to setTimeout() + * Works in all major browsers, including IE6 + * Small footprint (~1.9K gzipped) + * MIT License + +## Usage + +```javascript +new Spinner({color:'#fff', lines: 12}).spin(target); +``` + +For an interactive demo and a list of all supported options please refer to the [project's homepage](http://spin.js.org). diff --git a/ui/static/bower/spin.js/bower.json b/ui/static/bower/spin.js/bower.json new file mode 100644 index 00000000..7a3c5981 --- /dev/null +++ b/ui/static/bower/spin.js/bower.json @@ -0,0 +1,17 @@ +{ + "name": "spin.js", + "main": "spin.js", + "dependencies": {}, + "readme": "README.md", + "repository": { + "type": "git", + "url": "git://github.com/fgnass/spin.js.git" + }, + "ignore": [ + "Gruntfile.js", + "site", + "bower.json", + "component.json", + "package.json" + ] +} diff --git a/ui/static/bower/spin.js/jquery.spin.js b/ui/static/bower/spin.js/jquery.spin.js new file mode 100644 index 00000000..16050bc0 --- /dev/null +++ b/ui/static/bower/spin.js/jquery.spin.js @@ -0,0 +1,79 @@ +/** + * Copyright (c) 2011-2014 Felix Gnass + * Licensed under the MIT license + * http://spin.js.org/ + */ + +/* + +Basic Usage: +============ + +$('#el').spin() // Creates a default Spinner using the text color of #el. +$('#el').spin({ ... }) // Creates a Spinner using the provided options. + +$('#el').spin(false) // Stops and removes the spinner. + +Using Presets: +============== + +$('#el').spin('small') // Creates a 'small' Spinner using the text color of #el. +$('#el').spin('large', '#fff') // Creates a 'large' white Spinner. + +Adding a custom preset: +======================= + +$.fn.spin.presets.flower = { + lines: 9 +, length: 10 +, width: 20 +, radius: 0 +} + +$('#el').spin('flower', 'red') + +*/ + +;(function(factory) { + + if (typeof exports == 'object') { + // CommonJS + factory(require('jquery'), require('spin.js')) + } else if (typeof define == 'function' && define.amd) { + // AMD, register as anonymous module + define(['jquery', 'spin'], factory) + } else { + // Browser globals + if (!window.Spinner) throw new Error('Spin.js not present') + factory(window.jQuery, window.Spinner) + } + +}(function($, Spinner) { + + $.fn.spin = function(opts, color) { + + return this.each(function() { + var $this = $(this) + , data = $this.data() + + if (data.spinner) { + data.spinner.stop() + delete data.spinner + } + if (opts !== false) { + opts = $.extend( + { color: color || $this.css('color') } + , $.fn.spin.presets[opts] || opts + ) + data.spinner = new Spinner(opts).spin(this) + } + }) + } + + $.fn.spin.presets = { + tiny: { lines: 8, length: 2, width: 2, radius: 3 } + , small: { lines: 8, length: 4, width: 3, radius: 5 } + , large: { lines: 10, length: 8, width: 4, radius: 8 } + } + +})); diff --git a/ui/static/bower/spin.js/spin.js b/ui/static/bower/spin.js/spin.js new file mode 100644 index 00000000..1a3258d1 --- /dev/null +++ b/ui/static/bower/spin.js/spin.js @@ -0,0 +1,377 @@ +/** + * Copyright (c) 2011-2014 Felix Gnass + * Licensed under the MIT license + * http://spin.js.org/ + * + * Example: + var opts = { + lines: 12 // The number of lines to draw + , length: 7 // The length of each line + , width: 5 // The line thickness + , radius: 10 // The radius of the inner circle + , scale: 1.0 // Scales overall size of the spinner + , corners: 1 // Roundness (0..1) + , color: '#000' // #rgb or #rrggbb + , opacity: 1/4 // Opacity of the lines + , rotate: 0 // Rotation offset + , direction: 1 // 1: clockwise, -1: counterclockwise + , speed: 1 // Rounds per second + , trail: 100 // Afterglow percentage + , fps: 20 // Frames per second when using setTimeout() + , zIndex: 2e9 // Use a high z-index by default + , className: 'spinner' // CSS class to assign to the element + , top: '50%' // center vertically + , left: '50%' // center horizontally + , shadow: false // Whether to render a shadow + , hwaccel: false // Whether to use hardware acceleration (might be buggy) + , position: 'absolute' // Element positioning + } + var target = document.getElementById('foo') + var spinner = new Spinner(opts).spin(target) + */ +;(function (root, factory) { + + /* CommonJS */ + if (typeof module == 'object' && module.exports) module.exports = factory() + + /* AMD module */ + else if (typeof define == 'function' && define.amd) define(factory) + + /* Browser global */ + else root.Spinner = factory() +}(this, function () { + "use strict" + + var prefixes = ['webkit', 'Moz', 'ms', 'O'] /* Vendor prefixes */ + , animations = {} /* Animation rules keyed by their name */ + , useCssAnimations /* Whether to use CSS animations or setTimeout */ + , sheet /* A stylesheet to hold the @keyframe or VML rules. */ + + /** + * Utility function to create elements. If no tag name is given, + * a DIV is created. Optionally properties can be passed. + */ + function createEl (tag, prop) { + var el = document.createElement(tag || 'div') + , n + + for (n in prop) el[n] = prop[n] + return el + } + + /** + * Appends children and returns the parent. + */ + function ins (parent /* child1, child2, ...*/) { + for (var i = 1, n = arguments.length; i < n; i++) { + parent.appendChild(arguments[i]) + } + + return parent + } + + /** + * Creates an opacity keyframe animation rule and returns its name. + * Since most mobile Webkits have timing issues with animation-delay, + * we create separate rules for each line/segment. + */ + function addAnimation (alpha, trail, i, lines) { + var name = ['opacity', trail, ~~(alpha * 100), i, lines].join('-') + , start = 0.01 + i/lines * 100 + , z = Math.max(1 - (1-alpha) / trail * (100-start), alpha) + , prefix = useCssAnimations.substring(0, useCssAnimations.indexOf('Animation')).toLowerCase() + , pre = prefix && '-' + prefix + '-' || '' + + if (!animations[name]) { + sheet.insertRule( + '@' + pre + 'keyframes ' + name + '{' + + '0%{opacity:' + z + '}' + + start + '%{opacity:' + alpha + '}' + + (start+0.01) + '%{opacity:1}' + + (start+trail) % 100 + '%{opacity:' + alpha + '}' + + '100%{opacity:' + z + '}' + + '}', sheet.cssRules.length) + + animations[name] = 1 + } + + return name + } + + /** + * Tries various vendor prefixes and returns the first supported property. + */ + function vendor (el, prop) { + var s = el.style + , pp + , i + + prop = prop.charAt(0).toUpperCase() + prop.slice(1) + if (s[prop] !== undefined) return prop + for (i = 0; i < prefixes.length; i++) { + pp = prefixes[i]+prop + if (s[pp] !== undefined) return pp + } + } + + /** + * Sets multiple style properties at once. + */ + function css (el, prop) { + for (var n in prop) { + el.style[vendor(el, n) || n] = prop[n] + } + + return el + } + + /** + * Fills in default values. + */ + function merge (obj) { + for (var i = 1; i < arguments.length; i++) { + var def = arguments[i] + for (var n in def) { + if (obj[n] === undefined) obj[n] = def[n] + } + } + return obj + } + + /** + * Returns the line color from the given string or array. + */ + function getColor (color, idx) { + return typeof color == 'string' ? color : color[idx % color.length] + } + + // Built-in defaults + + var defaults = { + lines: 12 // The number of lines to draw + , length: 7 // The length of each line + , width: 5 // The line thickness + , radius: 10 // The radius of the inner circle + , scale: 1.0 // Scales overall size of the spinner + , corners: 1 // Roundness (0..1) + , color: '#000' // #rgb or #rrggbb + , opacity: 1/4 // Opacity of the lines + , rotate: 0 // Rotation offset + , direction: 1 // 1: clockwise, -1: counterclockwise + , speed: 1 // Rounds per second + , trail: 100 // Afterglow percentage + , fps: 20 // Frames per second when using setTimeout() + , zIndex: 2e9 // Use a high z-index by default + , className: 'spinner' // CSS class to assign to the element + , top: '50%' // center vertically + , left: '50%' // center horizontally + , shadow: false // Whether to render a shadow + , hwaccel: false // Whether to use hardware acceleration (might be buggy) + , position: 'absolute' // Element positioning + } + + /** The constructor */ + function Spinner (o) { + this.opts = merge(o || {}, Spinner.defaults, defaults) + } + + // Global defaults that override the built-ins: + Spinner.defaults = {} + + merge(Spinner.prototype, { + /** + * Adds the spinner to the given target element. If this instance is already + * spinning, it is automatically removed from its previous target b calling + * stop() internally. + */ + spin: function (target) { + this.stop() + + var self = this + , o = self.opts + , el = self.el = createEl(null, {className: o.className}) + + css(el, { + position: o.position + , width: 0 + , zIndex: o.zIndex + , left: o.left + , top: o.top + }) + + if (target) { + target.insertBefore(el, target.firstChild || null) + } + + el.setAttribute('role', 'progressbar') + self.lines(el, self.opts) + + if (!useCssAnimations) { + // No CSS animation support, use setTimeout() instead + var i = 0 + , start = (o.lines - 1) * (1 - o.direction) / 2 + , alpha + , fps = o.fps + , f = fps / o.speed + , ostep = (1 - o.opacity) / (f * o.trail / 100) + , astep = f / o.lines + + ;(function anim () { + i++ + for (var j = 0; j < o.lines; j++) { + alpha = Math.max(1 - (i + (o.lines - j) * astep) % f * ostep, o.opacity) + + self.opacity(el, j * o.direction + start, alpha, o) + } + self.timeout = self.el && setTimeout(anim, ~~(1000 / fps)) + })() + } + return self + } + + /** + * Stops and removes the Spinner. + */ + , stop: function () { + var el = this.el + if (el) { + clearTimeout(this.timeout) + if (el.parentNode) el.parentNode.removeChild(el) + this.el = undefined + } + return this + } + + /** + * Internal method that draws the individual lines. Will be overwritten + * in VML fallback mode below. + */ + , lines: function (el, o) { + var i = 0 + , start = (o.lines - 1) * (1 - o.direction) / 2 + , seg + + function fill (color, shadow) { + return css(createEl(), { + position: 'absolute' + , width: o.scale * (o.length + o.width) + 'px' + , height: o.scale * o.width + 'px' + , background: color + , boxShadow: shadow + , transformOrigin: 'left' + , transform: 'rotate(' + ~~(360/o.lines*i + o.rotate) + 'deg) translate(' + o.scale*o.radius + 'px' + ',0)' + , borderRadius: (o.corners * o.scale * o.width >> 1) + 'px' + }) + } + + for (; i < o.lines; i++) { + seg = css(createEl(), { + position: 'absolute' + , top: 1 + ~(o.scale * o.width / 2) + 'px' + , transform: o.hwaccel ? 'translate3d(0,0,0)' : '' + , opacity: o.opacity + , animation: useCssAnimations && addAnimation(o.opacity, o.trail, start + i * o.direction, o.lines) + ' ' + 1 / o.speed + 's linear infinite' + }) + + if (o.shadow) ins(seg, css(fill('#000', '0 0 4px #000'), {top: '2px'})) + ins(el, ins(seg, fill(getColor(o.color, i), '0 0 1px rgba(0,0,0,.1)'))) + } + return el + } + + /** + * Internal method that adjusts the opacity of a single line. + * Will be overwritten in VML fallback mode below. + */ + , opacity: function (el, i, val) { + if (i < el.childNodes.length) el.childNodes[i].style.opacity = val + } + + }) + + + function initVML () { + + /* Utility function to create a VML tag */ + function vml (tag, attr) { + return createEl('<' + tag + ' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">', attr) + } + + // No CSS transforms but VML support, add a CSS rule for VML elements: + sheet.addRule('.spin-vml', 'behavior:url(#default#VML)') + + Spinner.prototype.lines = function (el, o) { + var r = o.scale * (o.length + o.width) + , s = o.scale * 2 * r + + function grp () { + return css( + vml('group', { + coordsize: s + ' ' + s + , coordorigin: -r + ' ' + -r + }) + , { width: s, height: s } + ) + } + + var margin = -(o.width + o.length) * o.scale * 2 + 'px' + , g = css(grp(), {position: 'absolute', top: margin, left: margin}) + , i + + function seg (i, dx, filter) { + ins( + g + , ins( + css(grp(), {rotation: 360 / o.lines * i + 'deg', left: ~~dx}) + , ins( + css( + vml('roundrect', {arcsize: o.corners}) + , { width: r + , height: o.scale * o.width + , left: o.scale * o.radius + , top: -o.scale * o.width >> 1 + , filter: filter + } + ) + , vml('fill', {color: getColor(o.color, i), opacity: o.opacity}) + , vml('stroke', {opacity: 0}) // transparent stroke to fix color bleeding upon opacity change + ) + ) + ) + } + + if (o.shadow) + for (i = 1; i <= o.lines; i++) { + seg(i, -2, 'progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)') + } + + for (i = 1; i <= o.lines; i++) seg(i) + return ins(el, g) + } + + Spinner.prototype.opacity = function (el, i, val, o) { + var c = el.firstChild + o = o.shadow && o.lines || 0 + if (c && i + o < c.childNodes.length) { + c = c.childNodes[i + o]; c = c && c.firstChild; c = c && c.firstChild + if (c) c.opacity = val + } + } + } + + if (typeof document !== 'undefined') { + sheet = (function () { + var el = createEl('style', {type : 'text/css'}) + ins(document.getElementsByTagName('head')[0], el) + return el.sheet || el.styleSheet + }()) + + var probe = css(createEl('group'), {behavior: 'url(#default#VML)'}) + + if (!vendor(probe, 'transform') && probe.adj) initVML() + else useCssAnimations = vendor(probe, 'animation') + } + + return Spinner + +})); diff --git a/ui/static/bower/spin.js/spin.min.js b/ui/static/bower/spin.js/spin.min.js new file mode 100644 index 00000000..bd3ae4f4 --- /dev/null +++ b/ui/static/bower/spin.js/spin.min.js @@ -0,0 +1,2 @@ +// http://spin.js.org/#v2.3.2 +!function(a,b){"object"==typeof module&&module.exports?module.exports=b():"function"==typeof define&&define.amd?define(b):a.Spinner=b()}(this,function(){"use strict";function a(a,b){var c,d=document.createElement(a||"div");for(c in b)d[c]=b[c];return d}function b(a){for(var b=1,c=arguments.length;c>b;b++)a.appendChild(arguments[b]);return a}function c(a,b,c,d){var e=["opacity",b,~~(100*a),c,d].join("-"),f=.01+c/d*100,g=Math.max(1-(1-a)/b*(100-f),a),h=j.substring(0,j.indexOf("Animation")).toLowerCase(),i=h&&"-"+h+"-"||"";return m[e]||(k.insertRule("@"+i+"keyframes "+e+"{0%{opacity:"+g+"}"+f+"%{opacity:"+a+"}"+(f+.01)+"%{opacity:1}"+(f+b)%100+"%{opacity:"+a+"}100%{opacity:"+g+"}}",k.cssRules.length),m[e]=1),e}function d(a,b){var c,d,e=a.style;if(b=b.charAt(0).toUpperCase()+b.slice(1),void 0!==e[b])return b;for(d=0;d',c)}k.addRule(".spin-vml","behavior:url(#default#VML)"),h.prototype.lines=function(a,d){function f(){return e(c("group",{coordsize:k+" "+k,coordorigin:-j+" "+-j}),{width:k,height:k})}function h(a,h,i){b(m,b(e(f(),{rotation:360/d.lines*a+"deg",left:~~h}),b(e(c("roundrect",{arcsize:d.corners}),{width:j,height:d.scale*d.width,left:d.scale*d.radius,top:-d.scale*d.width>>1,filter:i}),c("fill",{color:g(d.color,a),opacity:d.opacity}),c("stroke",{opacity:0}))))}var i,j=d.scale*(d.length+d.width),k=2*d.scale*j,l=-(d.width+d.length)*d.scale*2+"px",m=e(f(),{position:"absolute",top:l,left:l});if(d.shadow)for(i=1;i<=d.lines;i++)h(i,-2,"progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)");for(i=1;i<=d.lines;i++)h(i);return b(a,m)},h.prototype.opacity=function(a,b,c,d){var e=a.firstChild;d=d.shadow&&d.lines||0,e&&b+d>1)+"px"})}for(var i,k=0,l=(f.lines-1)*(1-f.direction)/2;k Date: Tue, 6 Oct 2015 15:13:40 -0400 Subject: [PATCH 2/2] Added loader to listing, resource panel and taxonomy panel --- ui/jstests/test-learning-resource.jsx | 4 +- ui/jstests/test_manage_taxonomies.jsx | 4 +- ui/static/ui/js/learning_resources.jsx | 111 +++++++++++++------------ ui/static/ui/js/listing.js | 24 ++++-- ui/static/ui/js/listing_resources.jsx | 16 ++-- ui/static/ui/js/manage_taxonomies.jsx | 17 +++- ui/static/ui/js/require_config.js | 2 +- ui/static/ui/js/utils.jsx | 53 ++++++++++-- ui/templates/repository.html | 1 + 9 files changed, 150 insertions(+), 82 deletions(-) diff --git a/ui/jstests/test-learning-resource.jsx b/ui/jstests/test-learning-resource.jsx index 76dc9c48..168a5c15 100644 --- a/ui/jstests/test-learning-resource.jsx +++ b/ui/jstests/test-learning-resource.jsx @@ -553,9 +553,9 @@ define(['QUnit', 'jquery', 'react', 'lodash', 'learning_resources', "LearningResourcePanel.loader should populate its stuff", function(assert) { var div = document.createElement("div"); - assert.equal(0, $(div).find("textarea").size()); + assert.ok($(div).html().length === 0); LearningResources.loader("repo", "1", function() {}, function() {}, div); - assert.equal(1, $(div).find("textarea").size()); + assert.ok($(div).html().length > 0); } ); }); diff --git a/ui/jstests/test_manage_taxonomies.jsx b/ui/jstests/test_manage_taxonomies.jsx index b073f33f..ff8b4f76 100644 --- a/ui/jstests/test_manage_taxonomies.jsx +++ b/ui/jstests/test_manage_taxonomies.jsx @@ -2565,12 +2565,12 @@ define(['QUnit', 'jquery', 'lodash', 'manage_taxonomies', 'react', QUnit.test("Test that ManageTaxonomies.loader renders into div", function(assert) { var container = document.createElement("div"); - assert.equal(0, $(container).find("input").size()); + assert.ok($(container).html().length === 0); ManageTaxonomies.loader( "repo", container, function() {}, function() {}, function() {}, function() {} ); - assert.equal(5, $(container).find("input").size()); + assert.ok($(container).html().length > 0); } ); diff --git a/ui/static/ui/js/learning_resources.jsx b/ui/static/ui/js/learning_resources.jsx index 541d20b4..bac39c5c 100644 --- a/ui/static/ui/js/learning_resources.jsx +++ b/ui/static/ui/js/learning_resources.jsx @@ -5,6 +5,7 @@ define('learning_resources', var StatusBox = Utils.StatusBox; var Select2 = Utils.Select2; + var ReactOverlayLoader = Utils.ReactOverlayLoader; var TermListItem = React.createClass({ render: function () { @@ -295,37 +296,41 @@ define('learning_resources', return
+ +
- - -
+
{vocabSelector} {termSelector} -
+
- {termList} + {termList} -
- +
+ -
-

- Preview -

-

- -

- +
+

+ Preview +

+ +

+ + +

+ +
; }, handleDescription: function(event) { @@ -379,9 +384,10 @@ define('learning_resources', componentDidMount: function () { var thiz = this; + this.setState({loaded: false}); $.get("/api/v1/repositories/" + this.props.repoSlug + "/learning_resources/" + - this.props.learningResourceId + "/").done(function (data) { + this.props.learningResourceId + "/").then(function (data) { if (!thiz.isMounted()) { // In time AJAX call happens component may become unmounted return; @@ -397,49 +403,44 @@ define('learning_resources', description: description, previewUrl: previewUrl, }); - Utils.getVocabulariesAndTerms( + return Utils.getVocabulariesAndTerms( thiz.props.repoSlug, learningResourceType) .then(function (results) { - if (!thiz.isMounted()) { - // In time AJAX call happens component may become unmounted - return; - } - - var vocabulariesAndTerms = _.map(results, - function(tuple) { - var vocabulary = tuple.vocabulary; - var terms = tuple.terms; - var selectedTermsInVocab = _.pluck( - _.filter(terms, function(term) { - return _.includes(selectedTerms, term.slug); - }), 'slug'); - return { - vocabulary: vocabulary, - terms: terms, - selectedTerms: selectedTermsInVocab - }; - }); + if (!thiz.isMounted()) { + // In time AJAX call happens component may become unmounted + return; + } - thiz.setState({ - vocabulariesAndTerms: vocabulariesAndTerms, - }); + thiz.setState({loaded: true}); + var vocabulariesAndTerms = _.map(results, + function (tuple) { + var vocabulary = tuple.vocabulary; + var terms = tuple.terms; + var selectedTermsInVocab = _.pluck( + _.filter(terms, function (term) { + return _.includes(selectedTerms, term.slug); + }), 'slug'); + return { + vocabulary: vocabulary, + terms: terms, + selectedTerms: selectedTermsInVocab + }; + }); - if (vocabulariesAndTerms.length) { thiz.setState({ - selectedVocabulary: vocabulariesAndTerms[0].vocabulary + vocabulariesAndTerms: vocabulariesAndTerms, }); - } - }).fail(function () { - thiz.setState({ - message: { - error: "Unable to read information about learning resource." + if (vocabulariesAndTerms.length) { + thiz.setState({ + selectedVocabulary: vocabulariesAndTerms[0].vocabulary + }); } - }); - }); + }); }).fail(function () { thiz.setState({ + loaded: true, message: { error: "Unable to read information about learning resource." } diff --git a/ui/static/ui/js/listing.js b/ui/static/ui/js/listing.js index cefdfe79..4ed556a3 100644 --- a/ui/static/ui/js/listing.js +++ b/ui/static/ui/js/listing.js @@ -12,6 +12,11 @@ define('listing', var repoSlug = listingOptions.repoSlug; var loggedInUsername = listingOptions.loggedInUsername; + // empty results and facetCounts to start with + listingOptions = $.extend({}, listingOptions); + listingOptions.resources = []; + listingOptions.facetCounts = {}; + CSRF.setupCSRF(); var EMAIL_EXTENSION = '@mit.edu'; @@ -165,6 +170,10 @@ define('listing', // The URL in the browser will be updated with these changes in // refreshFromAPI. var queryMap = {}; + + // Controls the loader on the listing page. + var pageLoaded = false; + // Populate queryMap with query string key value pairs. _.each(URI(window.location).query(true), function(v, k) { if (!Array.isArray(v)) { @@ -231,6 +240,8 @@ define('listing', }; refreshFromAPI = function() { + pageLoaded = false; + var newQuery = "?" + URI().search(queryMap).query(); if (newQuery === "?") { // Don't put ? in URL if empty @@ -243,12 +254,9 @@ define('listing', var url = "/api/v1/repositories/" + listingOptions.repoSlug + "/search/" + newQuery; - var setOpacity = function(opacity) { - $("#listing").css({opacity: opacity}); - }; - - setOpacity(0.6); + renderListingResources(); return $.get(url).then(function(collection) { + pageLoaded = true; listingOptions = $.extend({}, listingOptions); listingOptions.resources = collection.results; listingOptions.facetCounts = collection.facet_counts; @@ -264,10 +272,8 @@ define('listing', } renderListingResources(); - - setOpacity(1); }).fail(function(error) { - setOpacity(1); + pageLoaded = true; // Propagate error return $.Deferred().reject(error); @@ -354,7 +360,7 @@ define('listing', container, openExportsPanel, openResourcePanel, updateFacets, updateMissingFacets, selectedFacets, selectedMissingFacets, updateSort, pageNum, numPages, - updatePage + updatePage, pageLoaded ); }; diff --git a/ui/static/ui/js/listing_resources.jsx b/ui/static/ui/js/listing_resources.jsx index 5038a331..b5bf6fbf 100644 --- a/ui/static/ui/js/listing_resources.jsx +++ b/ui/static/ui/js/listing_resources.jsx @@ -4,6 +4,7 @@ define('listing_resources', ['react', 'jquery', 'lodash', 'utils', 'use strict'; var ICheckbox = Utils.ICheckbox; + var ReactOverlayLoader = Utils.ReactOverlayLoader; var Pagination = PaginationModule.Pagination; var getImageFile = function(resourceType) { @@ -138,8 +139,8 @@ define('listing_resources', ['react', 'jquery', 'lodash', 'utils', var facets = []; var makeFacetGroup = function(values) { - if (!values.values.length && - !values.facet.missing_count) { + if (!values || (!values.values.length && + !values.facet.missing_count)) { return null; } var selectedFacets = {}; @@ -160,7 +161,9 @@ define('listing_resources', ['react', 'jquery', 'lodash', 'utils', }; _.each(["course", "run", "resource_type"], function(key) { - facets.push(makeFacetGroup(thiz.props.facetCounts[key])); + if (_.has(thiz.props.facetCounts, key)) { + facets.push(makeFacetGroup(thiz.props.facetCounts[key])); + } }); _.each(this.props.facetCounts, function(values) { @@ -492,7 +495,7 @@ define('listing_resources', ['react', 'jquery', 'lodash', 'utils', var ListingPage = React.createClass({ render: function() { return
-
+
-
@@ -518,6 +520,7 @@ define('listing_resources', ['react', 'jquery', 'lodash', 'utils',
+
; }, clearSelectedExports: function() { @@ -529,7 +532,7 @@ define('listing_resources', ['react', 'jquery', 'lodash', 'utils', loader: function(listingOptions, container, openExportsPanel, openResourcePanel, updateFacets, updateMissingFacets, selectedFacets, selectedMissingFacets, updateSort, - pageNum, numPages, updatePage) { + pageNum, numPages, updatePage, loaded) { return React.render( , container ); diff --git a/ui/static/ui/js/manage_taxonomies.jsx b/ui/static/ui/js/manage_taxonomies.jsx index fdb5967e..480041b7 100644 --- a/ui/static/ui/js/manage_taxonomies.jsx +++ b/ui/static/ui/js/manage_taxonomies.jsx @@ -5,6 +5,7 @@ define('manage_taxonomies', ['react', 'lodash', 'jquery', 'uri', var StatusBox = Utils.StatusBox; var ICheckbox = Utils.ICheckbox; + var ReactOverlayLoader = Utils.ReactOverlayLoader; var TermComponent = React.createClass({ mixins: [React.addons.LinkedStateMixin], @@ -754,6 +755,8 @@ define('manage_taxonomies', ['react', 'lodash', 'jquery', 'uri',
+ +
+ +
@@ -794,6 +801,7 @@ define('manage_taxonomies', ['react', 'lodash', 'jquery', 'uri', componentDidMount: function() { var thiz = this; + this.setState({loaded: false}); Utils.getCollection("/api/v1/learning_resource_types/").then( function(learningResourceTypes) { if (!thiz.isMounted()) { @@ -804,15 +812,20 @@ define('manage_taxonomies', ['react', 'lodash', 'jquery', 'uri', return type.name; }); thiz.setState({learningResourceTypes: types}); - Utils.getVocabulariesAndTerms(thiz.props.repoSlug).then( + return Utils.getVocabulariesAndTerms(thiz.props.repoSlug).then( function(vocabularies) { if (!thiz.isMounted()) { return; } - thiz.setState({vocabularies: vocabularies}); + thiz.setState({ + vocabularies: vocabularies, + loaded: true + }); } ); + }).fail(function() { + thiz.setState({loaded: true}); }); } }); diff --git a/ui/static/ui/js/require_config.js b/ui/static/ui/js/require_config.js index 1b291247..9a76a4fe 100644 --- a/ui/static/ui/js/require_config.js +++ b/ui/static/ui/js/require_config.js @@ -16,7 +16,7 @@ var REQUIRE_PATHS = { SecondLevelDomains: "uri.js/src/SecondLevelDomains", history: "history.js/scripts/compressed/history", historyadapter: "history.js/scripts/compressed/history.adapter.jquery", - + spin: "spin.js/spin.min", csrf: "../ui/js/csrf", listing: "../ui/js/listing", manage_taxonomies: "../ui/js/manage_taxonomies.jsx?noext", diff --git a/ui/static/ui/js/utils.jsx b/ui/static/ui/js/utils.jsx index 2bd999a1..ad080f15 100644 --- a/ui/static/ui/js/utils.jsx +++ b/ui/static/ui/js/utils.jsx @@ -1,5 +1,6 @@ -define("utils", ["jquery", "lodash", "react", "react_infinite", "select2"], - function ($, _, React, Infinite) { +define("utils", ["jquery", "lodash", "react", "react_infinite", "spin", + "select2"], + function ($, _, React, Infinite, Spinner) { 'use strict'; /** @@ -216,7 +217,6 @@ define("utils", ["jquery", "lodash", "react", "react_infinite", "select2"], attachHandler: function() { var node = React.findDOMNode(this); var thiz = this; - $(node).off('ifToggled'); $(node).on('ifToggled', function(e) { thiz.handleChange(e); }); @@ -224,7 +224,10 @@ define("utils", ["jquery", "lodash", "react", "react_infinite", "select2"], checkboxClass: 'icheckbox_square-blue', radioClass: 'iradio_square-blue' }); - $(node).iCheck(this.props.checked ? "check" : "uncheck"); + }, + componentWillUpdate: function() { + var node = React.findDOMNode(this); + $(node).off('ifToggled'); }, componentDidMount: function() { this.attachHandler(); @@ -318,6 +321,45 @@ define("utils", ["jquery", "lodash", "react", "react_infinite", "select2"], } }); + /** + * Adapted from react-loader + * https://github.com/quickleft/react-loader + */ + var ReactOverlayLoader = React.createClass({ + componentDidUpdate: function() { + this.spin(); + }, + componentDidMount: function() { + this.spin(); + }, + spin: function() { + if (this.isMounted() && !this.props.loaded) { + var target = React.findDOMNode(this.refs.loader); + + var spinner = new Spinner(); + spinner.spin(target); + } + }, + render: function() { + var loader; + var opacity = 1; + + if (!this.props.loaded) { + loader =
; + opacity = 0.6; + } + var children; + if (!this.props.hideChildrenOnLoad || this.props.loaded) { + children =
+ {this.props.children} +
; + } + return
{loader} + {children} +
; + } + }); + return { getCollection: _getCollection, /** @@ -352,6 +394,7 @@ define("utils", ["jquery", "lodash", "react", "react_infinite", "select2"], , container ); - } + }, + ReactOverlayLoader: ReactOverlayLoader }; }); diff --git a/ui/templates/repository.html b/ui/templates/repository.html index a13059b3..6701a181 100644 --- a/ui/templates/repository.html +++ b/ui/templates/repository.html @@ -41,6 +41,7 @@ {% block postcontent %} {{ block.super }} {% compress js %} +