Posts for: #Prototype

How to use Sprockets with Rails

Sam Stephenson has recently released a Javascript preprocessor called Sprockets. It’s distributed as Ruby gem, and it helps to declare scripts dependencies through special comments, and safely build them one script. It’s very useful for maintain your Javascript projects, extract reusable code and share across applications.

Installation

$ (sudo) gem install sprockets It will also install sprocketize executable.

How it works?

To declare a dependency use require directive:
//= require //= require "cookies" When you use angular brackets the script will be searched in all the Sprockets load path, if you use quotes instead, you are forcing to load the file from the current directory. Usually you should use the first way to require frameworks or libraries and the second one for your scripts.

[]

Make your elements draggable and resizeable with Resizeable.js

Hello, I’m still alive and I want to share a useful JavaScript class: Resizeable.js. It allows to make draggable and resizeable your DOM elements!

How it works?

new Resizeable('element');

Your element has now two sensible areas: the border area and the central area. If you click on the central area and move the mouse around, keeping the left button pressed, your element will be dragged. If you are on the border area, and perform the same gesture, your element will be resized.

[]

ActiveForm 0.2.0 released

ActiveForm is a JavaScript library, based on Prototype, useful to validate your forms in an automagically and pluggable way.

Automagically? Simply, You have to declare your fields, eventually your error messages, and.. nothing else!!

Pluggable? ActiveForm contains most common validations (regular expressions, presence, conditional presence..), and it performs them in a certain order. If you don’t like this, you can simply redeclare a method, or exclude it from validation process.

Features:

[]