Articles Tagged 'jQuery'


Camelize, CamelCase

As seen in the post Variety of coding and coding approaches that a developer may have to solve a problem are multiple and diverse for the same programming language used. Here's how some of the most popular Javascript frameworks have solved a simple function of CamelCase :

Prototype.js

Prototype.js , version 1.6.0.3, explicitly proposes a method camelize() to make the camelcase on a string. The author's approach is quite simple and the code is self-explanatory. In this case it was not made any use of Regular Expression!

1
2
3
4
5
6
7
8
9
10
11
12
13
( ) { camelize: function () {
this . split ( '-' ) , len = parts. length ; var parts = this. split ('-'), len = parts. length;
len == 1 ) return parts [ 0 ] ; if (len == 1) return parts [0];

this . charAt ( 0 ) == '-' camelized var = this. charAt (0) == '-'
0 ] . charAt ( 0 ) . toUpperCase ( ) + parts [ 0 ] . substring ( 1 ) ? Parts [0]. CharAt (0). ToUpperCase () + parts [0]. Substring (1)
0 ] ; : Parts [0];

var i = 1 ; i < len ; i ++ ) for (var i = 1, i <len; i + +)
i ] . charAt ( 0 ) . toUpperCase ( ) + parts [ i ] . substring ( 1 ) ; camelized + = parts [i]. charAt (0). toUpperCase () + parts [i]. substring (1);

camelized return;
}

More ...

JQuery: animate backgroundColor

(che nella versione camelize è backgroundColor ). I did not understand if it's a bug or something intentional, the fact remains that whatever the method animate() to jQuery does not work with some CSS attributes, including background-color (which version camelize is backgroundColor ). For example the following code has no effect:

1
2
3
4
5
"text/css" > < style type = "text / css">
div # box {background-color: # eee; width: 100px; height: 100px}
</ style >
<! - .... ->
"box" >< / div > < div id = "box"> </ div >
1
) . animate ( { backgroundColor : "#f90" } ) ; $ ('Div # box'). Animate ({backgroundColor: "# f90"});

To resolve this problem you need to install an extension: jQuery Color Animations . This allows you to run the "Animations" attribute backgroundColor and more:

  • backgroundColor
  • borderBottomColor
  • borderLeftColor
  • borderRightColor
  • borderTopColor
  • color
  • outlineColor

More ...

WordPress: how to write a reply to comment using jQuery

Recently Cristiano Up has released a useful plugin for WordPress that can aggiugere two links to every comment on a post (maybe you have installed a similar, since in the directory WordPress.org I beamed a couple, however, being an Italian software would the event to honor the excellent work done by Christians). These links (reply & quote), meet and / or listing the author of a commentary, by performing the tedious task of inserting the at sign (@) to indicate to whom it is addressed. In this tutorial I will explain - to medium-expert users - how to add such features two "hand", without recourse to the installation of any plugins. Moreover knowingly exploit the capabilities of jQuery for JavaScript party. The technique I present is the same that I used to introduce this feature in this blog.

Note: The use of a plugin is the best solution for those who tend to frequently change your WordPress template, or at least, has plans to implement this. This tutorial is only to show how to perform targeted interventions within the code WordPress and is dedicated to the most curious.

Edit your comments.php

The first change we make is to insert the link "reply" and "shares" in every comment. To do this, edit the file comments.php located in the folder of our theme. This file contains all the instructions that display the comments at the end of a post. The section we are concerned (which may vary slightly from theme to theme) is the loop for creating different comments, identified by:

More ...

jQuery: how to build an extension Plugin

Like all the libraries of this type also jQuery allows you to extend its basic functionality using real plugin. Respecting the rules of its operation, ie restituiendo always a pointer to the selected item or the same jQuery, you can write a plugin with a few lines of code. Take for example the proposed code in jQuery against everyone: a benchmark with 5 browser , which was (after the correction reported by Luca ):

1
2
3
4
5
) . css ( 'cursor' , 'pointer' ) . click ( $ ('H2.dropdown'). Css ('cursor', 'pointer'). Click (
function () {
$ ( this ) . next ( ) . is ( ':hidden' ) ) $ ( this ) . next ( ) . slideDown ( ) ; else $ ( this ) . next ( ) . slideUp ( ) ; if ($ (this). next (). is (': hidden')) $ (this). next (). slideDown (); else $ (this). next (). slideUp ();
}
);

More ...

jQuery against everyone: a benchmark with 5 browser

image A good developer has no problem to switch from one programming language to another. The choice to focus on a particular language, framework or development environment, is dictated more by the availability of time and the type of work that goes on. However, an important factor that may influence the choice of "framework" such is the sympathy and affection that can mature over time.
Specifically, I wanted to analyze some - not all - Javascript frameworks available today, because even "advised" to take a look especially at jQuery .
The creators of mootools (one of the most popular JavaScript frameworks) have made ​​available a tool to run a speed test and validity of five well-known JavaScript frameworks: Slickspeed . This test, the outcome is not at all obvious, is important as working on the client side Javascript frameworks, that are performed by our browser. It is precisely for this reason that some find Safari faster than Internet Explorer or Google Chrome faster than Firefox . However, this often depends on the type of page you are viewing. Indeed, it may well happen that a particular site is really "faster" when viewed in Safari, but this does not mean that "all sites" will be faster with Safari! Obviously this is true for any other browser.

The benchmark

In tests I've done with Slickspeed I compared the browsers available on my machine (Windows Vista 64bit Utilmate - Intel Core 2 Quad 2.4GHz with 8Gb RAM).
Unfortunately, the tests are not able to run with Internet Explorer 7, as the car crashed, even going out of scale with the results! Once again, congratulations Microsoft.
I crercato to maintain the same status of the PC during the test run, opening the browser and not individually by sending no other processes running.

Note: If you feel like you also run one or more of these tests, you can comment on this post in case of "odd" and different results.

image

Google Chrome was really fast, with a value of 68 (average) in the test with jQuery . The slower, however, was Flock , despite coming from the same "mother" Mozilla. This poor performance of Flock is really curious as its cutting social networks, because it is precisely the Social Network Web 2.0 to take advantage of the many JavaScript frameworks available, so as to provide an experience of truly innovative navigation and interaction.
Surprisingly beats FireFox and Opera also has a nice little ', even getting a 74 in the performance of Dojo ! FireFox and Safari, after all, are similar, with Safari faster in tests with Mootools and jQuery.

Which framework to choose?

If we do not care to test the speed of execution and we do not care dimesion in Kbytes of the same framework, the answer may be "whatever you like" or, if you like, "what you know better or is more harmonious with your style of programming. "
Ultimately, these frameworks will look a bit 'all (see for example the use of $), despite some important and substantial differences that can jump in the eyes of an expert or really pushed the use of a particular library. In principle, in fact, everything that can be done with jQuery, for example, you can do fine with mootools or prototype! If jQuery has a very compact syntax, as all methods always return the jQuery object basis, thus creating endless rows of oggetto.metodo().metodo().metodo()... said that this is not at all costs a strength, especially for those who will have to debug!
Libraries like prototype.js sin, perhaps in the absence of effects, even simple, forcing the developer to implement as a spinoff scriptaculous.js , heavy and distant from the library first choice.

An example

Precisely this is why, for example, led me to replace the coupled prototype / scriptaculous with jQuery to create interactive panels / Animated undolog.com here in the sidebar. Indeed, even using Google API to import libraries, is a waste load all the library and scriptaculous for a slideDown slideUp. For information and an example, here is the Javascript code as it was coupled with the prototype / scriptaculous:

1
2
3
4
5
6
7
8
9
10
11
12
13
/ / Prototype / scriptaculous
) . each ( $ $ ('H2.dropdown'). Each (
element ) { function (element) {
= "pointer" ; element. style. cursor = "pointer";
'click' , element. observe ('click',
event ) { function (event) {
this . next ( ) . style . display == "" ) new Effect. BlindUp ( this . next ( ) , { duration : .5 } ) ; if (this. next (). style. display == "") new Effect. BlindUp (this. next (), {duration: .5});
Effect. BlindDown ( this . next ( ) , { duration : .3 } ) ; Effect else new. BlindDown (this. next (), {duration: .3});
event ) ; Event. Stop (event);
}
)
}
);

and it is now with jQuery:

1
2
3
4
5
6
7
8
9
10
/ / JQuery
) . each ( $ ('H2.dropdown'). Each (
i ) { function (s) {
) . css ( 'cursor' , 'pointer' ) . click ( $ (This). Css ('cursor', 'pointer'). Click (
function () {
$ ( this ) . next ( ) . is ( ':hidden' ) ) $ ( this ) . next ( ) . slideDown ( ) ; else $ ( this ) . next ( ) . slideUp ( ) ; if ($ (this). next (). is (': hidden')) $ (this). next (). slideDown (); else $ (this). next (). slideUp ();
}
);
}
);

All in all, a closer look, I do not think there is a lot of difference! But as I said before ... the question is "well" of personal taste.

More ...

jQuery makeover

Just this week (under guidance ...) I was browsing on jQuery , a great library in the style of prototype.js , scriptaculous.js , MooTools , so to speak ... and that is that today the whole site has been completely redesigned:

image

Great start to broaden my horizons on this type of libraries! Shortly be publishing some articles interesting, especially about the differences between jQuery and other libraries "similar".

More ...

Google AJAX Library API: a breakthrough for developers

AJAX Libraries API Google , in the latter period, has released a multitude of tools for developers, constantly updating their releases. Now holds an agreement with popular AJAX framework, and not only to centralize the distribution of library jQuery , Prototype , script.aculo.us , MooTools and dojo !

In practice it is possible to access these libraries leveraging the infrastructure and the Google network, with significant advantages in terms of speed and safety.

The speed, in the load, is guaranteed by the same network as Google that, in addition to providing a structure per se of distributed server, allows (by default) loading compressed (gzip / minify) of the libraries. The hosting Google closest to the request will be used to send the code and, if not met or down temporarily, Google will provide the network, however, sending the Javascript code!

More ...

All clones of Lightbox in a dynamic array

Planetozh has created a beautiful scenery of the dynamic tool that can list all of the Javascript libraries like Lightbox.

image

image Using a panel (see image at left) with a number of "ticks" (checkbox), which indicate the various features of the libraries, you can run a filter thus obtaining a list of one or more libraries that do the job. We hope that the author maintains updated this great page, very useful in extricating one of the numerous and powerful libraries of this type.

More ...

Light gallery: Lightview 2.0.0_rc1

Lightview Here is yet another newly released Unobtrusive JavaScript library for image galleries and more. Lightview in 2.0.0_rc1 release , also adds features for "open" Window with the content that goes beyond the simple picture: Flash movies, QuickTime , Form and IFRAME! Compared to the previous version (1.1.0 - which handles only images), then, this release candidate is enhanced features are also present in other libraries . . The tools required by Lighview to work are very well known Prototype 1.6.0.2 and Scriptaculous 1.8.1 . Gliattributi used to manage the library are class and rel .

Interesting one aspect of this library is the extreme care with which the graphic appears.

Rating: 9 - Home Lightview

More ...

Light Library: Slimbox by a Shadowbox, galleries in Javascript

Some might say - and rightly so - enough! Javascript libraries (Unobtrusive - not intrusive, or partially) to manage images and galleries there are so many. Anyway here's the list, with pros and cons, the best I've tried.

Slimbox 1:41

Extremely minimal, 7K (version 1.41), requires mootools to work. As indicated on the home page is a real clone graph Lightbox , we will see below. Honestly, aside from the extreme compactness of the library does not own peculiar characteristics. On the same site, however, you can also find a script to generate run-time reflections ... you may want to limit this ;)

Rating: -6 - Slimbox Home Page, Home Page Reflection.js for MooTools

Lightbox2

Lightbox2 One of the most known and simple. Manages images in this release are (so it does not work with QuickTime, Flash, etc.). For its operation, requires Prototype and Scriptaculous . Use the attribute rel to identify the links of your images to be processed:

1
"images/image-1.jpg" rel = "lightbox" title = "my caption" > image #1 < / a > < a href = "images/image-1.jpg" rel = "lightbox" title = "my caption"> image # 1 </ a >

Like the other libraries that we will see, it supports the slideshow mode, by inserting brackets any identifier in a series of link / image:

1
2
3
"images/image-1.jpg" rel = "lightbox[roadtrip]" > image #1 < / a > < a href = "images/image-1.jpg" rel = "lightbox [roadtrip]"> image # 1 </ a >
"images/image-2.jpg" rel = "lightbox[roadtrip]" > image #2 < / a > < a href = "images/image-2.jpg" rel = "lightbox [roadtrip]"> image # 2 </ a >
"images/image-3.jpg" rel = "lightbox[roadtrip]" > image #3 < / a > < a href = "images/image-3.jpg" rel = "lightbox [roadtrip]"> image # 3 </ a >

Rating: 6 - Home Page Lightbox2

LIGHTWINDOW 2.0

LightWindow 2.0 Even this is quite common! After all, how to understand what is the most used? ;) . However it is extremely comprehensive and versatile. On the site stands the request for donations for the purchase of a Mac ... a little invasive and urgent ... Anyway, like the previous one, for its operation, requires the presence of Prototype and Scriptaculous . Unlike its predecessor, however, this allows you to view moltisiimi types of files: from the images, QuickTime movies, Flash movies, external HTML pages and PDF. ) altri obbligatori ( class e params - per impostare il comportamento della libreria). By contrast, uses various attributes, some optional ( author, caption and title ) other mandatory ( class and params - to set the behavior of the library). For example, to view a gallery or slide show using the attribute rel :

1
2
3
"gallery/0-sushi.jpg" class = "lightwindow" rel = "[Sushi]" title = "Left Behind" caption = "Look's super tasty!" author = "Unknown" > image #1 < / a > < a href = "gallery/0-sushi.jpg" class = "lightwindow" rel = "[Sushi]" title = "Left Behind" caption = "Look's super tasty!" author = "Unknown"> image # 1 </ to >
"gallery/1-sushi.jpg" class = "lightwindow" rel = "[Sushi]" title = "Beware of warewolves..." caption = "I shouldn't be doing this when I am hungry" author = "Unknown" > image #2 < / a > < a href = "gallery/1-sushi.jpg" class = "lightwindow" rel = "[Sushi]" title = "Beware of warewolves ..." caption = "I Should not be doing this when i am hungry" author = "Unknown"> image # 2 </ a >
"gallery/2-sushi.jpg" class = "lightwindow" rel = "[Sushi]" title = "That was good!" caption = "Take that sushi!" author = "Unknown" > image #3 < / a > < a href = "gallery/2-sushi.jpg" class = "lightwindow" rel = "[Sushi]" title = "That was good!" caption = "Take that sushi!" author = "Unknown"> image # 3 </ a >

Score: 8 - Home Page LightWindow 2.0

ShadowBox 1.0B

Shadowbox Although the beta version 1.0, this is perhaps the most complete library, both from the functional point of view for both libraries supported. For its operation, in fact, you can choose from a variety of frameworks, with the file "adapters" specially manufactured and supplied by the author:

The visual effect (configurable via skin / css), then, unlike the others, is definitely more appealing. The attributes are used only rel where, at its interior, find space all other configuration parameters. For example, to realize a gallery, just use:

1
2
"beach.jpg" rel = "shadowbox[Vacation]" > The Beach < / a > < a href = "beach.jpg" rel = "shadowbox [Vacation]"> The Beach </ a >
"pier.jpg" rel = "shadowbox[Vacation]" > The Pier < / a > < a href = "pier.jpg" rel = "shadowbox [Vacation]"> The Pier </ a >

If you want to set some options ( see website for complete list ) simply use the following syntax:

1
"myimage.jpg" rel = "shadowbox;options={overlayOpacity: 0.5, resize: false}" > My Image < / a > < a href = "myimage.jpg" rel = "shadowbox; options = {overlayOpacity: 0.5, resize: false}"> My Image </ a >

On the Internet they can find other, like Highslide JS . Indeed, if some other library you want to report me ... Anyway, personally, I prefer Shadowbox for simplicity, scalability and cross-framework.

Rating: 9 - Top Shadowbox 1.0B

More ...



Stop SOPA