Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 92 lines (80 sloc) 2.674 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
###
Verdict.coffee 0.0.0.0.0.1
(c) 2011 Radagaisus MIT open-source license
Inspired by tangle.js - http://worrydream.com/Tangle/
requirements: jQuery http://www.jquery.com/
###
###
usage:
add adjustable_number class if you want some spiffy css
$("#cookies").numbers
max: 200
min: 0
step: 1
integer: false
###

(($) ->
  # -34234235 => -34,234,235
  # I am so gonna regret this later
  $.format ||= {}
  $.format.num = (num) -> (''+num).replace(/(\d+)(\..*)?/, ($0,$1,$2) -> $1.replace(/(\d)(?=(\d{3})+$)/g,'$1,') + ($2 || ''))
  
  $.fn.numbers = (o) ->
    defaults =
      # max: 200
      # min: 0
      step: 1
      integer: true
      growth: 2
    
    o = $.extend defaults, o
    
    # Add the event handlers
    number_drag = (elem) ->
      elem.css('cursor', 'col-resize')
      elem.mousedown (e) ->
        document.body.onselectstart = -> false
        document.body.style.MozUserSelect = "none"
        document.body.onmousedown = -> false
        document.body.style.cursor = "col-resize"
        x = e.pageX
        $(window).bind 'mousemove.numbers', (change) ->
          # pageX is cross-browser normalized by jQuery
          dir = 2 * (x < change.pageX) - 1 # if x < last_x then 1 else -1 :-)
          val = Number(elem.text().replace(/,/g,''))
          val = Math.max(Math.min(val + dir * o.step * (Math.abs(change.pageX - x) / o.growth), o.max ? Infinity), o.min ? -Infinity)
          val = Math.floor(val) if o.integer?
          elem.text($.format.num val)
          x = change.pageX
           
          elem.trigger 'verdict_change', val
      
      $(window).mouseup ->
        $(window).unbind 'mousemove.numbers'
        document.body.onselectstart = null
        document.body.style.MozUserSelect = ""
        document.body.onmousedown = null
        document.body.style.cursor = "inherit"
    
    @each ->
      number_drag $(@)
)(window.jQuery)


###
usage:
add toggle class if you want some spiffy css
$("#cookies").toggle_select
list of alternative contents
###
(($) ->
  $.fn.toggle_select = () ->
    
    # Add the event handlers
    toggle = (elem) ->
      children = elem.children()
      for i in [1...children.length]
        children[i].style.display = "none"
      elem.click (e) ->
        children = elem.children()
        n = 0
        for i in [0...children.length]
          if children[i].style.display != "none"
            n = (i + 1) % children.length
          children[i].style.display = "none"
        children[n].style.removeProperty("display")
        elem.trigger('verdict_change', elem)
    
    @each ->
      toggle $(@),
)(window.jQuery)
Something went wrong with that request. Please try again.