Sha256: 35289044aabb08a2b08ef98aa01251f782da10de766958920867a45713cabbcd

Contents?: true

Size: 1.69 KB

Versions: 20

Compression:

Stored size: 1.69 KB

Contents

# Vendored from https://raw.github.com/kneath/kss/master/lib/kss.coffee
#
# ---
#
# This class scans your stylesheets for pseudo classes, then inserts a new CSS
# rule with the same properties, but named 'psuedo-class-{{name}}'.
#
# Supported pseudo classes: hover, disabled, active, visited, focus, target.
#
# Example:
#
#   a:hover{ color:blue; }
#   => a.pseudo-class-hover{ color:blue; }
class KssStateGenerator
  psuedo_selectors = [
    'hover',
    'enabled',
    'disabled',
    'active',
    'visited',
    'focus',
    'target',
    'checked',
    'empty',
    'first-of-type',
    'last-of-type',
    'first-child',
    'last-child']

  constructor: ->
    pseudos = new RegExp "(\\:#{psuedo_selectors.join('|\\:')})", "g"

    try
      for stylesheet in document.styleSheets
        if stylesheet.href && stylesheet.href.indexOf(document.domain) >= 0
          idxs = []
          for rule, idx in stylesheet.cssRules
            if (rule.type == CSSRule.STYLE_RULE) and pseudos.test(rule.selectorText)
              replaceRule = (matched, stuff) ->
                return matched.replace(/\:/g, '.pseudo-class-')
              @insertRule(rule.cssText.replace(pseudos, replaceRule))
            pseudos.lastIndex = 0

  # Takes a given style and attaches it to the current page.
  #
  # rule - A CSS rule String (ex: ".test{ display:none; }").
  #
  # Returns nothing.
  insertRule: (rule) ->
    headEl = document.getElementsByTagName('head')[0]
    styleEl = document.createElement('style')
    styleEl.type = 'text/css'
    if styleEl.styleSheet
      styleEl.styleSheet.cssText = rule
    else
      styleEl.appendChild(document.createTextNode(rule))

    headEl.appendChild(styleEl)

new KssStateGenerator

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
kayessess-0.4.0 app/assets/javascripts/kayessess/kss.coffee
kayessess-0.3.0 app/assets/javascripts/kayessess/kss.coffee
kayessess-0.2.11 app/assets/javascripts/kayessess/kss.coffee
kayessess-0.2.10 app/assets/javascripts/kayessess/kss.coffee
kayessess-0.2.9 app/assets/javascripts/kayessess/kss.coffee
kayessess-0.2.8 app/assets/javascripts/kayessess/kss.coffee
kayessess-0.2.7 app/assets/javascripts/kayessess/kss.coffee
kayessess-0.2.5 app/assets/javascripts/kayessess/kss.coffee
kayessess-0.2.4 app/assets/javascripts/kayessess/kss.coffee
kayessess-0.2.3 app/assets/javascripts/kayessess/kss.coffee
kayessess-0.2.2 app/assets/javascripts/kayessess/kss.coffee
kayessess-0.2.1 app/assets/javascripts/kayessess/kss.coffee
kayessess-0.2.0 app/assets/javascripts/kss.coffee
kayessess-0.1.6 app/assets/javascripts/kss.coffee
kayessess-0.1.5 app/assets/javascripts/kss.coffee
kayessess-0.1.4 app/assets/javascripts/kss.coffee
kayessess-0.1.3 app/assets/javascripts/kss.coffee
kayessess-0.1.2 app/assets/javascripts/kss.coffee
kayessess-0.1.1 app/assets/javascripts/kss.coffee
kayessess-0.1.0 app/assets/javascripts/kss.coffee