Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Keep logic and DOM manipulation separately
JavaScript CoffeeScript Ruby
tag: v0.1.0

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec/javascripts
src
.gitignore
Gemfile
Gemfile.lock
Guardfile
README.md
Rakefile

README.md

$tylist

$stylist created to help keep logic and DOM manipulation separately. Your JS looks creepy because of lot's of .css, .anim etc? $tylist is your choose, man!

This project uses Semantic Versioning for release numbering.

API

$.fn.seem

$.fn.seem accepts class as first argument.

Examples

Basic usage

To attach stylist functions to DOM element, use $.fn.seem:

TrafficLightStylist = class
  makeRed:    -> @css(color: 'red')
  makeYellow: -> @css(color: 'yellow')
  makeGreen:  -> @css(color: 'red')

$('#traffic_light').seem(TrafficLightStylist)

$('#traffic_light').makeRed()    # Set color to red
$('#traffic_light').makeYellow() # Set color to yellow
$('#traffic_light').makeGreen()  # you know

Selectors

You can attach stylists to any selectors. If element.is('selector') returns true, stylist function will be called:

TrafficLightStylist = class
  makeRed:    -> @css(color: 'red')
  makeYellow: -> @css(color: 'yellow')
  makeGreen:  -> @css(color: 'red')

$('.traffic_light').seem(TrafficLightStylist)

trafficLight = $('<div />')
  .appendTo('body')
  .addClass('traffic_light')

trafficLight.makeRed() # Set color to red

Usage with Backbone.js

View class (views/login_popup_view.coffee):

class LoginPopupView = class extends Backbone.View

  el: $('#login-popup')

  initialize: ->
    @el.seem(LoginPopupStylist)
    @el.showAnimated()

  events:
    'click .close': 'close'
    'submit form':  'submitForm'

  close: ->
    @el.hideAnimated()

  submitForm: ->
    if @validate()
      # Send data to server
    else
      @el
        .makeFieldsRed()
        .shakeAnimation()

  validate: ->
    # Validation login here

Stylist class (stylists/login_popup_stylist.coffee):

class LoginPopupStylist

  showAnimated: ->
    @
      .css(
        position: absolute
        top: '50%'
        # ...
      )
      .fadeIn(300)

  hideAnimated: ->
    # Lot's of dirty jQuery code

  makeFieldsRed: ->
    @
      .find('input, textarea')
      .css(boderColor: 'red')

  shakeAnimation: ->
    # Tons of animation logic

Roadmap

v0.2.0

Allow to pass options to stylist.

v0.3.0

Who know?

Changelog

v0.1.0 (18 September 2011)

Initial version.

License

The MIT License

Copyright (c) 2011 Sasha Koss

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.