$tylist is a library for keeping app logic and DOM manipulations separately. Your JS looks creepy because of numerous
.anim etc? $tylist is your choose, man!
This project uses Semantic Versioning.
$.fn.mixins accepts class as a first argument.
$.fn.mixins to attach stylist functions to a DOM element:
TrafficLightStylist = class makeRed: -> @css(color: 'red') makeYellow: -> @css(color: 'yellow') makeGreen: -> @css(color: 'red') $('#traffic_light').mixins(TrafficLightStylist) $('#traffic_light').makeRed() # Set color to red $('#traffic_light').makeYellow() # Set color to yellow $('#traffic_light').makeGreen() # you know
Stylist can be attached to any selector. 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').mixins(TrafficLightStylist) trafficLight = $('<div />') .appendTo('body') .addClass('traffic_light') trafficLight.makeRed() # Set color to red
Take a look at (
class LoginPopupView = class extends Backbone.View el: $('#login-popup') initialize: -> @el.mixins(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 (
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
Allow passing options to stylist.
$.fn.seem was renamed to
$.fn.mixins, thanks to @anayden for advice.
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.