Skip to content

Instantly share code, notes, and snippets.

var s2 = {
Version: '2.0.0a1'
};
s2.fx = new (function(){
var queues = [], globalQueue, heartbeat, activeEffectCount = 0;
this.beatOnDemand = function(dir){
heartbeat[(activeEffectCount += dir) > 0 ? 'start' : 'stop']();
};
Coming soon from yours truly and Amy Hoy!
As a special thank you for my regular readers (you!), <a href="http://javascriptrocks.com/">sign up for the announcement email and get $5 off the regular price</a> when the beta book is out!
<a href="http://javascriptrocks.com/"><img src="http://javascriptrocks.com/coming-soon-opt.png"/></a>
The book will cover all sorts of topics around JavaScript performance, from perceptive loading performance all the way down to selecting between if and case statements.
It's library/framework agnostic, so whether you use Prototype, jQuery, Mootools or any other libs, you'll find that you'll be able to provide faster-loading, better performing JavaScript to your users.
def pack_file(source, target)
puts `java -jar lib/yuicompressor-2.4.1.jar -v #{source} -o #{target}`
`gzip -9 #{target} -c > #{target}.gzip`
puts "#{source}: #{'%.1f' % (File.size(source)/1024.0)}k"
puts "Packed: #{'%.1f' % (File.size(target)/1024.0)}k"
puts "Packed+GZIP: #{'%.1f' % (File.size(target+'.gzip')/1024.0)}k"
puts
end
s2.css = {
PROPERTY_MAP: {
backgroundColor: 'color',
borderBottomColor: 'color',
borderBottomWidth: 'length',
borderLeftColor: 'color',
borderLeftWidth: 'length',
borderRightColor: 'color',
borderRightWidth: 'length',
borderSpacing: 'length',
s2.fx.Opacity = Class.create(s2.fx.Element, {
setup: function() {
var from = this.options.from || 0, to = this.options.to || 1;
this.element.setStyle('opacity:'+from);
this.animate('style', this.element, { style: 'opacity:'+to });
}
});
var ObjectRange = Class.create(Enumerable, (function() {
function initialize(start, end, exclusive) {
// ...
}
function _each(iterator) {
// ...
}
function include(value) {
(function() {
/** section: DOM
* Event
*
* The namespace for Prototype's event system.
*
* <h4>Events: a fine mess</h4>
*
* Event management is one of the really sore spots of cross-browser
var CreditCard = {
CARDS: {
Visa: /^4[0-9]{12}(?:[0-9]{3})?$/,
MasterCard: /^5[1-5][0-9]{14}$/,
DinersClub: /^3(?:0[0-5]|[68][0-9])[0-9]{11}$/,
Amex: /^3[47][0-9]{13}$/,
Discover: /^6(?:011|5[0-9]{2})[0-9]{12}$/
},
TEST_NUMBERS: $w('378282246310005 371449635398431 378734493671000 '+
'30569309025904 38520000023237 6011111111111117 '+
TransitionExample: function(element){
var type = element.up().down('.ebnf').innerHTML.gsub(/s2\.fx\.Transitions\./,'').split('(').first(),
transition = s2.fx.Transitions[type], active = false;
var values = $R(0,200).map(function(v){ return transition(v/200)*200; }),
min = Math.min(0, values.min()), max = Math.max(200, values.max());
if (min==max) {
min = 0; max = 200;
}
attwenger = [
{ :year => 1991, :tracks => 18, :title => "Most" },
{ :year => 1992, :tracks => 10, :title => "Pflug" },
{ :year => 1993, :tracks => 17, :title => "Luft" },
{ :year => 1997, :tracks => 5, :title => "Song" },
{ :year => 2002, :tracks => 15, :title => "Sun" },
{ :year => 2005, :tracks => 14, :title => "dog" },
{ :year => 2006, :tracks => 17, :title => "dog2 remixes" },
{ :year => 2007, :tracks => 8, :title => "die Kia" }
]