Camelize, CamelCase

Monday, October 20, 2008

As was seen in the post variety of coding and coding approaches that a developer may have to solve problems are different and many of 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() make the camelcase on a string. The approach is quite simple for the author and the code is self-explanatory. In this case there was no use of Regular Expression!

JavaScript:
  1. camelize: function () (
  2. . split ( '-' ) , len = parts. length ; var parts = this. split ( '-'), len = parts. length;
  3. len == 1 ) return parts [ 0 ] ; if (len == 1) return parts [0];
  4. . charAt ( 0 ) == '-' var = camelized this. charat (0) == '-'
  5. ? ] . charAt ( 0 ) . toUpperCase ( ) + parts [ 0 ] . substring ( 1 ) parts [0]. charat (0). toUpperCase () + parts [0]. substring (1)
  6. ] ; : Parts [0];
  7. var i = 1 ; i <len; i++ ) for (var i = 1; i <len; i + +)
  8. . charAt ( 0 ) . toUpperCase ( ) + parts [ i ] . substring ( 1 ) ; camelized = + parts [i]. charat (0). toUpperCase () + parts [i]. substring (1);
  9. camelized return;
  10. )

Continue reading ... "

Related Post

jQuery against everyone: a benchmark with 5 browser

Wednesday, September 17, 2008

image A good developer has no problem to move from a programming language to another. The choice to focus on a particular language, framework and development environment, is dictated more by availability of time and type of work that takes place. However, an important factor that may influence the choice of "framework" like, is the sympathy or the illness which can mature over time.
Specifically, I wanted to analyze some - not all - Javascript framework available today, because "advised" to look primarily at jQuery.
The creators of mootools (one of the most popular Javascript framework) has made available a tool to run a test of speed and validity of five known framework Javascript: Slickspeed. This test, the results do not discount at all, is important as the operating framework Javascript client-side, which is run 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. In fact, may very well happen that a particular site is really more "fast" when displayed in Safari, but this does not mean that "all sites will be faster with Safari! Of course, this speech is valid for any other browser.

The benchmark

In tests I conducted with Slickspeed I have compared the browser available on my machine (Utilmate Windows Vista 64bit - Intel Core 2 Quad 2.4GHz with a 8Gb RAM).
Unfortunately, the tests are not able to run it with Internet Explorer 7, because blocking the car, even going out of scale with the results! Once again, congratulations Microsoft.
I crercato identical to maintain the status of the PC during the test, opening the browser separately and not sending anyone else running process.

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

image

Google Chrome is truly fast, with a value of 68 (average) in the test with jQuery. The slower, however, it appeared Flock, despite coming from the same "mother" Mozilla. This bad result for Flock is truly curious given its cutting Social Network, because it is the Social Network Web 2.0 exploit many of Javascript framework available, so as to provide a navigation and interaction truly innovative.
A surprise beat FireFox and Opera also has a lot ', even getting a 74 in the Dojo! FireFox and Safari, after all, are alike, with Safari faster in tests with Mootools and jQuery.

What framework to choose?

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

An example

Just this last reason, for example, took me to replace the coupled prototype / scriptaculous with jQuery to make the panels interactive / animated here in the sidebar of undolog.com. Indeed, even using Google API to import libraries, is a waste load the entire library scriptaculous for a slideDown and slideUp. For information and sample, here yesterday Javascript code coupled with the prototype / scriptaculous:

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

and it is now with jQuery:

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

After all, at all, I do not think there is a lot of difference! But as I said before ... question is "well" of personal taste.

Related Post

jQuery restyling

Sunday 31 August, 2008

In these days (in the council ...) I was looking at jQuery, a library style of prototype.js, scriptaculous.js, mooTools, for instance ... and here today that the entire site has been completely redesigned:

image

Excellent start to broaden my horizons on this type of libraries! Coming soon publish some interesting article, especially about the differences between jQuery and other libraries "similar".

Related Post

Simple Accordion with the class USimpleTabStrip

Wednesday, August 20, 2008

The class USimpleTabStrip submitted unobtrusive Simple TabStrip, can also be used to create a simple menu Accordion.
Using the effects of BlindUp() BlindDown() offered by Scriptaculous:

JavaScript:
  1. function init () (
  2. ; UTS = new USimpleTabStrip ();
  3. ; UTS. Init ();
  4. ( e ) { UTS. onShow = function (e) (
  5. ( e ) ; new Effect. BlindDown (e);
  6. )
  7. ( e ) { UTS. onHide = function (e) (
  8. ( e ) ; new Effect. BlindUp (e);
  9. )
  10. )

And put it back on the HTML (HTML source):

HTML:
  1. > <div class = "accordion">
  2. > Accordion 1 </a> <a href = "#acc1"> Accordion 1 </ a>
  3. > </a> <a name = "acc1"> </ a>
  4. <h1> Content # 1 </ h1>
  5. <p> Bla bla bla .... </ p>
  6. </ div>
  7. > Accordion 2 </a> <a href = "#acc2"> Accordion 2 </ a>
  8. > </a> <a name = "acc2"> </ a>
  9. <h1> Content # 2 </ h1>
  10. <p> Bla bla bla .... </ p>
  11. </ div>
  12. > Accordion 3 </a> <a href = "#acc3"> Accordion 3 </ a>
  13. > </a> <a name = "acc3"> </ a>
  14. <h1> Content # 3 </ h1>
  15. <p> Bla bla bla .... </ p>
  16. </ div>
  17. </ div>

You get a simple menu Accordion that can be used in very fast.

Related Post

Simple unobtrusive TabStrip

Thursday 14 August, 2008

USimpleTabStrip is an unobtrusive Javascript to improve classici link anchor (yet) within an HTML page. This source is an improvement of the function presented in TabStrip unobtrusive. In this version also align the code to release 1.6 of prototype.js was created a real class to manage the TabStrip. The release here is very simple and straightforward. Its main work lies in adding an event click the link anchor normal. Not be submitted CSS styles, just to leave the maximum freedom of action, but you can get an effective TabStrip with a few lines of code add CSS, see Adding CSS styles below.

HTML

The class USimpleTabStrip working on a very simple HTML, the anchor sftuttando <a name></a>

HTML:
  1. <! - Simple list of links on the page ->
  2. > Link 1 </a> </li> <li> <a href = "#tbs1"> Link 1 </ a> </ li>
  3. > Link 2 </a> </li> <li> <a href = "#tbs2"> Link 2 </ a> </ li>
  4. > Link 3 </a> </li> <li> <a href = "#tbs3"> Link 3 </ a> </ li>
  5. </ ul>
  6. <! - Blocks / tabs ->
  7. > </a> <a name = "tbs1"> </ a>
  8. <h1> Card # 1 </ h1>
  9. <p> Bla bla bla .... </ p>
  10. </ div>
  11. > </a> <a name = "tbs2"> </ a>
  12. <h1> Card # 2 </ h1>
  13. <p> Bla bla bla .... </ p>
  14. </ div>
  15. > </a> <a name = "tbs3"> </ a>
  16. <h1> Card # 3 </ h1>
  17. <p> Bla bla bla .... </ p>
  18. </ div>

The tag div just below the anchor a work from the container.

Continue reading ... "

Related Post

Text Replacement Techniques in Flash

Wednesday 25 June, 2008

The technique of Text Replacement I am presenting today is in some respects, really interesting. Unlike the classic image to replace through CSS, this technique uses a flash to override the titles of our site. Despite being a bit more, because it requires the creation of a Flash movie and the use of Javascript, allows a number of advantages not indifferent:

  • Keeps' s accessibility of the site using a True-unobtrusive-Javascript so that crawlers and spiders continue to see the page as simple and correct HTML
  • Does not require the creation of images n for n titles. Just one movie to replace all the titles of our site, with considerable savings in terms of Download
  • Allows you to create simple titles but with Font not normally used on the Web
  • The text can be rendered in HTML, thanks to the characteristics of Flash
  • The text is selectable
  • Being a flash you can add interactivity and animation of any kind

You'll notice also that this procedure CSS are not practically taken into account!

Continue reading ... "

Related Post

Google AJAX API Library: a turning point for developers

Thursday, May 29, 2008

AJAX API Libraries Google, in the latter perdiodo, has released a multitude of tools dedicated to developers, continuously updating their releases. Now running out an agreement with popular AJAX framework, and not only to centralize the distribution of libraries jQuery, prototype, script.aculo.us, MooTools and dojo!

In practice, you can access these libraries using the infrastructure and the Google network, with significant benefits in terms of speed and security.

The speed, loading, is guaranteed by the same network that Google and provide per se a distributed server, allowing (by default) loading compressed (gzip / minify) library. The hosting Google closer to the request will be used to send the code and, if not reaching down or temporarily, the Google network will still send the Javascript code!

Continue reading ... "

Related Post

Google AJAX Language API and Prototype.js

Tuesday, May 13, 2008

Having seen the operation of Google AJAX API I came to mind an alternative way to translate our real Web pages. Taking advantage prototype.js is possible to mark the HTML tag that we want to translate, instead of subjecting the entire document translation. To mark the HTML tag I used to translate the attribute rel setting it to translate

HTML:
  1. > Questo testo deve essere tradotto </p> <p rel = "translate"> This text must be translated </ p>

With a simple function, then we can exploit prototype.js to process all HTML tags with rel='translate'

JavaScript:
  1. / *
  2. ** @ Name: translate ()
  3. ** @ Description: translate
  4. * /
  5. function translate () (
  6. ) . each ( $ $ ( '[Rel = "translate"]'). Each (
  7. e ) { function (e) (
  8. ( e. innerHTML , 'it' , 'en' , google. language. translate (e. innerHtml, 'it', 'en',
  9. result ) { function (result) (
  10. result. translation ) { if (result. translation) (
  11. ; e. innerHtml = result. translation;
  12. { Else ()
  13. 'Translate Error! \n \n ' + result. error . message ) ; alert ( 'Error Translate! \ n \ n' + result. error. message);
  14. )
  15. )
  16. );
  17. )
  18. );
  19. )

You can see it in action on e-lementi.com

Obviously, the script can (or must) be implemented as appropriate. Interestingly, however, that can be specialized in such a way as to replace the images (in the case of buttons in graphics that contain text) or let him develop TAG like INPUT or TEXTAREA

One of the limitations that I found, and that voorei deepen, the number of characters that can be translated. In the case of important texts is not difficult to obtain a mistake that I managed it in the script with an alert()

Related Post

Prototype with dynamic HTML: style and script

Friday 9 May, 2008

Over a year ago I wrote a post (Dynamic HTML with Javascript) that outlined some techniques to dynamically add style sheets and scripts to an HTML page already loaded. Who uses Prototype.js can greatly simplify life by using for instance:

JavaScript:
  1. "dom:loaded" , document. observe ( "Sunday: loaded"
  2. function () (
  3. Element ( "script" , { type: "text/javascript" , src: "/js/altro.js" } ) ; var script = new Element ( "script", (type: "text / javascript" src: "/ js / altro.js"));
  4. ) [ 0 ] . insert ( script ) ; $ $ ( "Head") [0]. Insert (script);
  5. )
  6. );

After the page is loaded document.observe adds a new script Javascript! For styles that is exactly the same thing!

Related Post

Unobtrusive Javascript: un po 'di clarity and eye to imposters

Sunday, April 13, 2008

Some scripts, and some Web, using some JavaScript functions impersonating non-intrusive (unobtrusive), even when they are not at all. What makes a script (usually JavaScript) not intrusive? In principle a script Javascript is non-intrusive when may be less than it! Quite simply! In developing a Web site usability of the same should not depend on any script. Only in this case we have a genuine script unobtrusive. Continue reading ... "

Related Post