www-thermferm/js/spin.js

Tue, 08 Jul 2014 23:53:04 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Tue, 08 Jul 2014 23:53:04 +0200
changeset 97
4a9dbee41a6c
permissions
-rw-r--r--

Added initial set for the thermferm web interface

97
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 //fgnass.github.com/spin.js#v1.3
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 /**
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Copyright (c) 2011-2013 Felix Gnass
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 * Licensed under the MIT license
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 (function(root, factory) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 /* CommonJS */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 if (typeof exports == 'object') module.exports = factory()
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 /* AMD module */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 else if (typeof define == 'function' && define.amd) define(factory)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 /* Browser global */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 else root.Spinner = factory()
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 (this, function() {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 "use strict";
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 var prefixes = ['webkit', 'Moz', 'ms', 'O'] /* Vendor prefixes */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22 , animations = {} /* Animation rules keyed by their name */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 , useCssAnimations /* Whether to use CSS animations or setTimeout */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
24
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
25 /**
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
26 * Utility function to create elements. If no tag name is given,
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 * a DIV is created. Optionally properties can be passed.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28 */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
29 function createEl(tag, prop) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30 var el = document.createElement(tag || 'div')
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
31 , n
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
32
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
33 for(n in prop) el[n] = prop[n]
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
34 return el
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
35 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
36
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37 /**
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38 * Appends children and returns the parent.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
39 */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 function ins(parent /* child1, child2, ...*/) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
41 for (var i=1, n=arguments.length; i<n; i++)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
42 parent.appendChild(arguments[i])
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
44 return parent
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
47 /**
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
48 * Insert a new stylesheet to hold the @keyframe or VML rules.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
49 */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
50 var sheet = (function() {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
51 var el = createEl('style', {type : 'text/css'})
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
52 ins(document.getElementsByTagName('head')[0], el)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
53 return el.sheet || el.styleSheet
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
54 }())
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
55
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
56 /**
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
57 * Creates an opacity keyframe animation rule and returns its name.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
58 * Since most mobile Webkits have timing issues with animation-delay,
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
59 * we create separate rules for each line/segment.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
60 */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
61 function addAnimation(alpha, trail, i, lines) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
62 var name = ['opacity', trail, ~~(alpha*100), i, lines].join('-')
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
63 , start = 0.01 + i/lines * 100
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
64 , z = Math.max(1 - (1-alpha) / trail * (100-start), alpha)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
65 , prefix = useCssAnimations.substring(0, useCssAnimations.indexOf('Animation')).toLowerCase()
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
66 , pre = prefix && '-' + prefix + '-' || ''
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
67
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
68 if (!animations[name]) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
69 sheet.insertRule(
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
70 '@' + pre + 'keyframes ' + name + '{' +
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
71 '0%{opacity:' + z + '}' +
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
72 start + '%{opacity:' + alpha + '}' +
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
73 (start+0.01) + '%{opacity:1}' +
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
74 (start+trail) % 100 + '%{opacity:' + alpha + '}' +
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
75 '100%{opacity:' + z + '}' +
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
76 '}', sheet.cssRules.length)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
77
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
78 animations[name] = 1
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
79 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
80
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
81 return name
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
82 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
83
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
84 /**
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
85 * Tries various vendor prefixes and returns the first supported property.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
86 */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
87 function vendor(el, prop) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
88 var s = el.style
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
89 , pp
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
90 , i
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 if(s[prop] !== undefined) return prop
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
93 prop = prop.charAt(0).toUpperCase() + prop.slice(1)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
94 for(i=0; i<prefixes.length; i++) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
95 pp = prefixes[i]+prop
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
96 if(s[pp] !== undefined) return pp
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
97 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
98 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100 /**
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 * Sets multiple style properties at once.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
103 function css(el, prop) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
104 for (var n in prop)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 el.style[vendor(el, n)||n] = prop[n]
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 return el
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110 /**
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 * Fills in default values.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 function merge(obj) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 for (var i=1; i < arguments.length; i++) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 var def = arguments[i]
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 for (var n in def)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 if (obj[n] === undefined) obj[n] = def[n]
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 return obj
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
120 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
121
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
122 /**
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
123 * Returns the absolute page-offset of the given element.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 function pos(el) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126 var o = { x:el.offsetLeft, y:el.offsetTop }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
127 while((el = el.offsetParent))
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 o.x+=el.offsetLeft, o.y+=el.offsetTop
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130 return o
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
131 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
132
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
133 // Built-in defaults
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
134
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
135 var defaults = {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
136 lines: 12, // The number of lines to draw
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
137 length: 7, // The length of each line
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
138 width: 5, // The line thickness
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
139 radius: 10, // The radius of the inner circle
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
140 rotate: 0, // Rotation offset
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
141 corners: 1, // Roundness (0..1)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
142 color: '#000', // #rgb or #rrggbb
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
143 direction: 1, // 1: clockwise, -1: counterclockwise
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
144 speed: 1, // Rounds per second
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
145 trail: 100, // Afterglow percentage
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
146 opacity: 1/4, // Opacity of the lines
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
147 fps: 20, // Frames per second when using setTimeout()
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
148 zIndex: 2e9, // Use a high z-index by default
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
149 className: 'spinner', // CSS class to assign to the element
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
150 top: 'auto', // center vertically
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
151 left: 'auto', // center horizontally
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
152 position: 'relative' // element position
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
153 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
154
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
155 /** The constructor */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
156 function Spinner(o) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
157 if (typeof this == 'undefined') return new Spinner(o)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
158 this.opts = merge(o || {}, Spinner.defaults, defaults)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
159 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
160
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
161 // Global defaults that override the built-ins:
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
162 Spinner.defaults = {}
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
163
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
164 merge(Spinner.prototype, {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
165
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
166 /**
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
167 * Adds the spinner to the given target element. If this instance is already
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
168 * spinning, it is automatically removed from its previous target b calling
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
169 * stop() internally.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
170 */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
171 spin: function(target) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
172 this.stop()
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
173
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
174 var self = this
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
175 , o = self.opts
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
176 , el = self.el = css(createEl(0, {className: o.className}), {position: o.position, width: 0, zIndex: o.zIndex})
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
177 , mid = o.radius+o.length+o.width
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
178 , ep // element position
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
179 , tp // target position
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
180
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
181 if (target) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
182 target.insertBefore(el, target.firstChild||null)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
183 tp = pos(target)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
184 ep = pos(el)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
185 css(el, {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
186 left: (o.left == 'auto' ? tp.x-ep.x + (target.offsetWidth >> 1) : parseInt(o.left, 10) + mid) + 'px',
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
187 top: (o.top == 'auto' ? tp.y-ep.y + (target.offsetHeight >> 1) : parseInt(o.top, 10) + mid) + 'px'
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
188 })
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
189 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
190
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
191 el.setAttribute('role', 'progressbar')
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
192 self.lines(el, self.opts)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
193
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
194 if (!useCssAnimations) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
195 // No CSS animation support, use setTimeout() instead
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
196 var i = 0
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
197 , start = (o.lines - 1) * (1 - o.direction) / 2
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
198 , alpha
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
199 , fps = o.fps
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
200 , f = fps/o.speed
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
201 , ostep = (1-o.opacity) / (f*o.trail / 100)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
202 , astep = f/o.lines
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
203
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
204 ;(function anim() {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
205 i++;
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
206 for (var j = 0; j < o.lines; j++) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
207 alpha = Math.max(1 - (i + (o.lines - j) * astep) % f * ostep, o.opacity)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
208
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
209 self.opacity(el, j * o.direction + start, alpha, o)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
210 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
211 self.timeout = self.el && setTimeout(anim, ~~(1000/fps))
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
212 })()
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
213 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
214 return self
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
215 },
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
216
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
217 /**
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
218 * Stops and removes the Spinner.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
219 */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
220 stop: function() {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
221 var el = this.el
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
222 if (el) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
223 clearTimeout(this.timeout)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
224 if (el.parentNode) el.parentNode.removeChild(el)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
225 this.el = undefined
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
226 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
227 return this
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
228 },
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
229
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
230 /**
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
231 * Internal method that draws the individual lines. Will be overwritten
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
232 * in VML fallback mode below.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
233 */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
234 lines: function(el, o) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
235 var i = 0
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
236 , start = (o.lines - 1) * (1 - o.direction) / 2
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
237 , seg
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239 function fill(color, shadow) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
240 return css(createEl(), {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
241 position: 'absolute',
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
242 width: (o.length+o.width) + 'px',
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
243 height: o.width + 'px',
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
244 background: color,
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
245 boxShadow: shadow,
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
246 transformOrigin: 'left',
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
247 transform: 'rotate(' + ~~(360/o.lines*i+o.rotate) + 'deg) translate(' + o.radius+'px' +',0)',
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
248 borderRadius: (o.corners * o.width>>1) + 'px'
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
249 })
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
250 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
251
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
252 for (; i < o.lines; i++) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
253 seg = css(createEl(), {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
254 position: 'absolute',
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
255 top: 1+~(o.width/2) + 'px',
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
256 transform: o.hwaccel ? 'translate3d(0,0,0)' : '',
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
257 opacity: o.opacity,
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
258 animation: useCssAnimations && addAnimation(o.opacity, o.trail, start + i * o.direction, o.lines) + ' ' + 1/o.speed + 's linear infinite'
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
259 })
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
260
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
261 if (o.shadow) ins(seg, css(fill('#000', '0 0 4px ' + '#000'), {top: 2+'px'}))
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
262
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
263 ins(el, ins(seg, fill(o.color, '0 0 1px rgba(0,0,0,.1)')))
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
264 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
265 return el
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
266 },
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
267
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
268 /**
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
269 * Internal method that adjusts the opacity of a single line.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
270 * Will be overwritten in VML fallback mode below.
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
271 */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
272 opacity: function(el, i, val) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
273 if (i < el.childNodes.length) el.childNodes[i].style.opacity = val
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
274 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
275
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
276 })
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
277
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
278
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
279 function initVML() {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
280
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
281 /* Utility function to create a VML tag */
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
282 function vml(tag, attr) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
283 return createEl('<' + tag + ' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">', attr)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
284 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
285
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
286 // No CSS transforms but VML support, add a CSS rule for VML elements:
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
287 sheet.addRule('.spin-vml', 'behavior:url(#default#VML)')
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
288
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
289 Spinner.prototype.lines = function(el, o) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
290 var r = o.length+o.width
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
291 , s = 2*r
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
292
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
293 function grp() {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
294 return css(
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
295 vml('group', {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
296 coordsize: s + ' ' + s,
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
297 coordorigin: -r + ' ' + -r
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
298 }),
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
299 { width: s, height: s }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
300 )
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
301 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
302
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
303 var margin = -(o.width+o.length)*2 + 'px'
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
304 , g = css(grp(), {position: 'absolute', top: margin, left: margin})
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
305 , i
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
306
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
307 function seg(i, dx, filter) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
308 ins(g,
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
309 ins(css(grp(), {rotation: 360 / o.lines * i + 'deg', left: ~~dx}),
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
310 ins(css(vml('roundrect', {arcsize: o.corners}), {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
311 width: r,
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
312 height: o.width,
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
313 left: o.radius,
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
314 top: -o.width>>1,
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
315 filter: filter
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
316 }),
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
317 vml('fill', {color: o.color, opacity: o.opacity}),
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
318 vml('stroke', {opacity: 0}) // transparent stroke to fix color bleeding upon opacity change
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
319 )
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
320 )
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
321 )
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
322 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
323
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
324 if (o.shadow)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
325 for (i = 1; i <= o.lines; i++)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
326 seg(i, -2, 'progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)')
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
327
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
328 for (i = 1; i <= o.lines; i++) seg(i)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
329 return ins(el, g)
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
330 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
331
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
332 Spinner.prototype.opacity = function(el, i, val, o) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
333 var c = el.firstChild
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
334 o = o.shadow && o.lines || 0
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
335 if (c && i+o < c.childNodes.length) {
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
336 c = c.childNodes[i+o]; c = c && c.firstChild; c = c && c.firstChild
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
337 if (c) c.opacity = val
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
338 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
339 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
340 }
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
341
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
342 var probe = css(createEl('group'), {behavior: 'url(#default#VML)'})
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
343
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
344 if (!vendor(probe, 'transform') && probe.adj) initVML()
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
345 else useCssAnimations = vendor(probe, 'animation')
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
346
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
347 return Spinner
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
348
4a9dbee41a6c Added initial set for the thermferm web interface
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
349 }));

mercurial