From dbeaf1f1d8c499ce06b9bfe4374356ed02d2d957 Mon Sep 17 00:00:00 2001 From: Buu Nguyen Date: Thu, 22 May 2014 21:30:08 -0700 Subject: [PATCH] Remove spin.js, use CSS animation for progress indicator --- src/Info.plist | 1 - src/firefox.js | 3 +- src/inject.css | 46 ++++-- src/inject.js | 16 +-- src/lib/js/spin.js | 350 --------------------------------------------- src/manifest.json | 1 - 6 files changed, 37 insertions(+), 380 deletions(-) delete mode 100644 src/lib/js/spin.js diff --git a/src/Info.plist b/src/Info.plist index 7b5dc92..81833ed 100755 --- a/src/Info.plist +++ b/src/Info.plist @@ -24,7 +24,6 @@ Start - lib/js/spin.js lib/js/jquery.js lib/js/jquery-ui.js lib/js/jstree.js diff --git a/src/firefox.js b/src/firefox.js index e34a394..6adedd7 100644 --- a/src/firefox.js +++ b/src/firefox.js @@ -3,8 +3,7 @@ var data = require('sdk/self').data pageMod.PageMod({ include: '*.github.com', - contentScriptFile: [data.url('lib/js/spin.js'), - data.url('lib/js/jquery.js'), + contentScriptFile: [data.url('lib/js/jquery.js'), data.url('lib/js/jquery-ui.js'), data.url('lib/js/jstree.js'), data.url('lib/js/jquery.pjax.js'), diff --git a/src/inject.css b/src/inject.css index 12bd601..91a88ad 100755 --- a/src/inject.css +++ b/src/inject.css @@ -156,17 +156,18 @@ html { margin: 6px; } .octotree_options input { - width: 237px; + width: 100%; + max-width: 350px; } .octotree_options .error { color: #900; } -.octotree_options button { - margin-right: 5px; +.octotree_options .button { + margin-right: 5px; } /* Toggle button */ -.octotree_toggle { +a.octotree_toggle { position: fixed !important; top: 5px; right: auto; @@ -174,7 +175,7 @@ html { left: 5px; width: 30px; height: 30px; - padding: 6px 10px !important; + padding: 6px 6px !important; color: black; text-align: center; line-height: 1; @@ -182,28 +183,47 @@ html { transition: left .3s ease, color 0.1s ease-in; -webkit-transition: left .3s ease, color 0.1s ease-in; } -.octotree_toggle:hover { +a.octotree_toggle:hover { color: #4183C4; } -.octotree_toggle > span { +a.octotree_toggle > span { font: normal normal 16px octicons; line-height: 1; display: inline-block; text-decoration: none; - -webkit-font-smoothing: antialiased; } -.octotree_toggle > span:after { +a.octotree_toggle > span:after { content: '\f078'; } -.octotree .octotree_toggle > span:after { +.octotree a.octotree_toggle > span:after { content: '\f0a4'; } -.octotree_toggle.spinning > span:after { - content: ' '; +a.octotree_toggle.loading > span:after { + content: ''; +} + +a.octotree_toggle.loading .loader { + border-radius: 50%; + border: 2px solid #000; + border-top: 2px solid rgba(0,0,0,0); + border-left: 2px solid rgba(0,0,0,0); + width: 16px; + height: 16px; + animation: loading .5s infinite linear; + -webkit-animation: loading .5s infinite linear; +} +@keyframes loading { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); }; +} + +@-webkit-keyframes loading { + 0% { -webkit-transform: rotate(0deg); } + 100% { -webkit-transform: rotate(360deg); }; } /* Popup (customize from Twitter Bootstrap) */ @@ -243,7 +263,7 @@ html { } .octotree_popup > .arrow:after { border-width: 5px; - content: ' '; + content: ''; top: 1px; margin-left: -5px; border-top-width: 0; diff --git a/src/inject.js b/src/inject.js index b898bc1..9c02cbf 100755 --- a/src/inject.js +++ b/src/inject.js @@ -40,7 +40,7 @@ '
' + '' + '' + - '' + + '
' + '
' + '
' + '
Octotree is enabled on every GitHub code page. Click this button or press ⌘ b (or ctrl b) to show it.
' + @@ -75,22 +75,12 @@ $treeView.hide() $optsFrm.hide().submit(saveToken) - var spinner = new Spinner({ - lines : 9, - length : 0, - width : 2, - radius : 6, - speed : 1.5, - className : 'octotree_spinner' - }) $document .on('pjax:send octotree:start', function() { - spinner.spin($toggleBtn[0]) - $toggleBtn.addClass('spinning') + $toggleBtn.addClass('loading') }) .on('pjax:end octotree:end', function() { - spinner.stop() - $toggleBtn.removeClass('spinning') + $toggleBtn.removeClass('loading') }) .on('pjax:timeout', function(event) { event.preventDefault() diff --git a/src/lib/js/spin.js b/src/lib/js/spin.js deleted file mode 100644 index bdf5853..0000000 --- a/src/lib/js/spin.js +++ /dev/null @@ -1,350 +0,0 @@ -/** - * Copyright (c) 2011-2014 Felix Gnass - * Licensed under the MIT license - */ -(function(root, factory) { - - /* CommonJS */ - if (typeof exports == 'object') 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 */ - - /** - * 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>1) + 'px' - }) - } - - for (; i < o.lines; i++) { - seg = css(createEl(), { - position: 'absolute', - top: 1+~(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: 2+'px'})) - 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.length+o.width - , s = 2*r - - function grp() { - return css( - vml('group', { - coordsize: s + ' ' + s, - coordorigin: -r + ' ' + -r - }), - { width: s, height: s } - ) - } - - var margin = -(o.width+o.length)*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.width, - left: o.radius, - top: -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 - } - } - } - - var probe = css(createEl('group'), {behavior: 'url(#default#VML)'}) - - if (!vendor(probe, 'transform') && probe.adj) initVML() - else useCssAnimations = vendor(probe, 'animation') - - return Spinner - -})); -2 \ No newline at end of file diff --git a/src/manifest.json b/src/manifest.json index d9a1f18..ccd9334 100755 --- a/src/manifest.json +++ b/src/manifest.json @@ -23,7 +23,6 @@ "inject.css" ], "js": [ - "lib/js/spin.js", "lib/js/jquery.js", "lib/js/jquery-ui.js", "lib/js/jstree.js",