- Jump To … +
  analyze.coffee autoload.coffee blender.coffee calculate.coffee caman.coffee convert.coffee event.coffee filter.coffee io.coffee layer.coffee logger.coffee module.coffee pixel.coffee plugin.coffee renderer.coffee store.coffee util.coffee blenders.coffee filters.coffee size.coffee blur.coffee camera.coffee compoundBlur.coffee edges.coffee posterize.coffee presets.coffee rotate.coffee stackBlur.coffee threshold.coffee

- # util.coffee

- ¶

  Look what you make me do Javascript

      slice = Array::slice

- ¶

  DOM simplifier (no jQuery dependency) NodeJS compatible

      $ = (sel, root = document) ->
        return sel if typeof sel is "object" or exports?
        root.querySelector sel

      class Util

- ¶

  Unique value utility

        @uniqid = do ->
          id = 0
          get: -> id++

- ¶

  Helper function that extends one object with all the properies of other objects

        @extend = (obj, src...) ->
          dest = obj

          for copy in src
            for own prop of copy
              dest[prop] = copy[prop]

          return dest

- ¶

  In order to stay true to the latest spec, RGB values must be clamped between 0 and 255. If we don't do this, weird things happen.

        @clampRGB = (val) ->
          return 0 if val < 0
          return 255 if val > 255
          return val

        @copyAttributes: (from, to, opts={}) ->
          for attr in from.attributes
            continue if opts.except? and attr.nodeName in opts.except
            to.setAttribute(attr.nodeName, attr.nodeValue)

- ¶

  Support for browsers that don't know Uint8Array (such as IE9)

        @dataArray: (length = 0) ->
          return new Uint8Array(length) if Caman.NodeJS or window.Uint8Array?
          return new Array(length)