├── .gitignore ├── examples ├── case.png ├── dial.png ├── hour.png ├── min.png ├── sec.png ├── crown_0.png ├── date_disk.png ├── fallback.png ├── stop_hour.png ├── stop_min.png ├── stop_sec.png ├── pusher_a_0.png ├── pusher_a_1.png ├── pusher_b_0.png ├── pusher_b_1.png ├── pusher_c_0.png ├── pusher_c_1.png └── watch.html ├── .gitmodules ├── Cakefile └── src └── jquery.floatinghands.coffee /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | lib/jquery.floatinghands.js 3 | docs/ 4 | -------------------------------------------------------------------------------- /examples/case.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/case.png -------------------------------------------------------------------------------- /examples/dial.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/dial.png -------------------------------------------------------------------------------- /examples/hour.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/hour.png -------------------------------------------------------------------------------- /examples/min.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/min.png -------------------------------------------------------------------------------- /examples/sec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/sec.png -------------------------------------------------------------------------------- /examples/crown_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/crown_0.png -------------------------------------------------------------------------------- /examples/date_disk.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/date_disk.png -------------------------------------------------------------------------------- /examples/fallback.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/fallback.png -------------------------------------------------------------------------------- /examples/stop_hour.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/stop_hour.png -------------------------------------------------------------------------------- /examples/stop_min.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/stop_min.png -------------------------------------------------------------------------------- /examples/stop_sec.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/stop_sec.png -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "lib/EaselJS"] 2 | path = lib/EaselJS 3 | url = git://github.com/gskinner/EaselJS.git 4 | -------------------------------------------------------------------------------- /examples/pusher_a_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/pusher_a_0.png -------------------------------------------------------------------------------- /examples/pusher_a_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/pusher_a_1.png -------------------------------------------------------------------------------- /examples/pusher_b_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/pusher_b_0.png -------------------------------------------------------------------------------- /examples/pusher_b_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/pusher_b_1.png -------------------------------------------------------------------------------- /examples/pusher_c_0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/pusher_c_0.png -------------------------------------------------------------------------------- /examples/pusher_c_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Leonidas-from-XIV/floatinghands/master/examples/pusher_c_1.png -------------------------------------------------------------------------------- /Cakefile: -------------------------------------------------------------------------------- 1 | {spawn, exec} = require 'child_process' 2 | 3 | task 'build', 'continually build the JavaScript code', -> 4 | coffee = spawn 'coffee', ['-cwb', '-o', 'lib', 'src'] 5 | coffee.stdout.on 'data', (data) -> console.log data.toString().trim() 6 | 7 | task 'doc', 'rebuild the Docco documentation', -> 8 | exec([ 9 | 'docco src/jquery.floatinghands.coffee' 10 | ].join(' && '), (err) -> 11 | throw err if err 12 | ) 13 | -------------------------------------------------------------------------------- /examples/watch.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Example 6 | 7 | 10 | 11 | 12 | 13 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /src/jquery.floatinghands.coffee: -------------------------------------------------------------------------------- 1 | ### 2 | *jQuery Floating Hands Plugin* 3 | 4 | Written in 2011 by Marek Kubica . 5 | 6 | See https://github.com/Leonidas-from-XIV/floatinghands for details. 7 | ### 8 | 9 | # define the wrapper function for jQuery 10 | (($) -> 11 | # function that gets called to update the bitmap every n milliseconds 12 | # yes, this is a curried function returning a unary function 13 | onUpdate = (bitmap) -> -> 14 | # calculate the degree by passing the function to the degree calculator 15 | # function and set this degree 16 | bitmap.rotation = bitmap.updateFn bitmap.timeFn 17 | # return `true` so it will be called again 18 | true 19 | 20 | # comparison function that sorts elements based on their z attribute in 21 | # descending order 22 | sortByZ = (first, second) -> 23 | second.z - first.z 24 | 25 | ### 26 | a function that provides the number of milliseconds passed since 27 | midnight today (rather than 1970/01/01 midnight). For that, we subtract 28 | create a date that is today 0:00 and subtract it from the current date. 29 | ### 30 | now = -> 31 | atm = new Date() 32 | atm.getTime() - new Date(atm.getFullYear(), atm.getMonth(), atm.getDay()).getTime() 33 | 34 | layerLoaded = (stage, layer) -> (event) -> 35 | image = event.target 36 | bitmap = new Bitmap image 37 | delete layer.image 38 | 39 | if !layer.z? 40 | # Z is default to 10, so it stays in the back 41 | layer.z = 10 42 | 43 | # apply all options that were passed 44 | bitmap[key] = value for own key, value of layer 45 | 46 | if bitmap.updateFn? 47 | # if not specified differently, use `now` as time source 48 | if !bitmap.timeFn? 49 | bitmap.timeFn = now 50 | # get the specialized updater function 51 | updaterFn = onUpdate bitmap 52 | # call it once, so we start with the newest coordinates 53 | updaterFn() 54 | # add the bitmap to the Ticker so it recalculates every tick 55 | Ticker.addListener tick: updaterFn 56 | 57 | # deactivate mouse events on layers, because they are not clickable 58 | bitmap.mouseEnabled = false 59 | # put the object on the stage, thus making it visible 60 | stage.addChild bitmap 61 | # sort the list of children by the Z index, otherwise the order 62 | # will be determined by the time the image is loaded 63 | stage.sortChildren sortByZ 64 | 65 | pusherLoaded = (stage, layer, extra) -> (event) -> 66 | image = event.target 67 | bitmap = new Bitmap image 68 | delete layer.image 69 | 70 | if !layer.z? 71 | # Z is default to 10, so it stays in the back 72 | layer.z = 10 73 | 74 | bitmap[key] = value for own key, value of layer 75 | 76 | if extra.button? 77 | extra.button.data(extra.type, bitmap) 78 | 79 | stage.addChild bitmap 80 | stage.sortChildren sortByZ 81 | 82 | initialize = (stage, onLoad) -> (element) -> 83 | image = new Image 84 | image.src = element.image 85 | image.onload = onLoad stage, element 86 | 87 | initButton = (stage) -> (element) -> 88 | callback = element.pushed 89 | [x1, y1, x2, y2] = element.hotspot 90 | button = $ '