Articles Tagged 'Development'


Tabstrip Design

To produce truly captivating Tabstrip there is a technique that allows particularly suited to mediate problems between graphics and Javascript code. Let us first of all how to build a template in Photoshop for our Tabstrip:

Built a tab strip similar to that shown in the figure above, we use the tool for the selection of the cutting area to generate the form that will have our HTML table. The use of the table, in this case, is particularly pointed out - as we shall see, as it simplifies both the design and JavaScript code. We cut our Tabstrip thus as follows:

In our Photoshop file we have to consider all combinations of the tabs (tab). We then selected the initial card (cut 3), the intermediate points (cutting and cutting 5 7) and the final card is not selected (cut 9) with - if any - edge finishing (cutting 10 - optional depending on the design). Then just 3 combinations to solve all cases visual. As shown below:

Graphically speaking, you can arrange the cards in overlapping and staggered, as shown below:

A matter of taste and needs ... returning to the image complete with the three stripes for combinations Tabstrip, the last two are used to resolve borderline cases, cut them as shown below:

The cut 17 and 23 solve the two cutting edge cases: the first tab is not selected, selected last. The cut 19 is the opposite of cutting 5 and 7 of the cut, you saw earlier. The complete picture that we get and we can save for future design changes is as follows:

In order not to confuse us when we come to the part of Javascript, the name of the cuts is as follows:

  • cut 3 = tabLeftFirstOn
  • 4 = cut tabStripeOn
  • Cut 5 = tabMiddleOnOff
  • Cut 6 = tabStripeOff
  • 7 = shear tabMiddleOffOff
  • Cut 9 = tabRightLastOff
  • 10 = Cutting topBg
  • 17 = Cutting tabLeftFirstOff
  • 19 = Cutting tabMiddleOffOn
  • 23 = Cutting tabRightLastOn

To accomplish this we need now a HTML code, CSS code and Javascript code as a manager clicks on the tab cards. HTML code is trivial but articulated. So I propose a PHP class that can generate it every time we need. In essence it is about creating an HTML table enclosed in a DIV with ID certain details that we need then for the execution of Javascript code and enclose the design using CSS. The generated HTML - just to get an idea - a Tabstrip with four cards is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"cscoTabStrip" > < div id = "cscoTabStrip">
"jscoTabStrip_info" > < div id = "jscoTabStrip_info">
"100%" cellspacing = "0" cellpadding = "0" border = "0" > < table width = "100%" cellspacing = "0" cellpadding = "0" border = "0">
< tr >
= "tabLeftFirstOn" >< / div >< / td > < td > < div class = "tabLeftFirstOn"> </ div > </ td >
"" class = "tabStripeOn" >< a id = "jscoTS_tab1" onclick = "_onTabStrip( this );" class = "tabsLink" title = "Caratteristiche" > Caratteristiche < / a >< / td > < td nowrap = "" class = "tabStripeOn"> < a id = "jscoTS_tab1" onclick = "_onTabStrip (this);" class = "tabsLink" title = "Features"> Features </ a > </ td >
= "tabMiddleOnOff" >< / div >< / td > < td > < div class = "tabMiddleOnOff"> </ div > </ td >
"" class = "tabStripeOff" >< a id = "jscoTS_tab2" onclick = "_onTabStrip( this );" class = "tabsLink" title = "Come funziona" > Come funziona < / a >< / td > < td nowrap = "" class = "tabStripeOff"> < a id = "jscoTS_tab2" onclick = "_onTabStrip (this);" class = "tabsLink" title = "How it works"> How does it work </ a > </ td >
= "tabMiddleOffOff" >< / div >< / td > < td > < div class = "tabMiddleOffOff"> </ div > </ td >
"" class = "tabStripeOff" >< a id = "jscoTS_tab3" onclick = "_onTabStrip( this );" class = "tabsLink" title = "Interfaccia" > Interfaccia < / a >< / td > < td nowrap = "" class = "tabStripeOff"> < a id = "jscoTS_tab3" onclick = "_onTabStrip (this);" class = "tabsLink" title = "Interface"> Interface </ a > </ td >
= "tabMiddleOffOff" >< / div >< / td > < td > < div class = "tabMiddleOffOff"> </ div > </ td >
"" class = "tabStripeOff" >< a id = "jscoTS_tab4" onclick = "_onTabStrip( this );" class = "tabsLink" title = "Richiesta Iscrizione" > Richiesta Iscrizione < / a >< / td > < td nowrap = "" class = "tabStripeOff"> < a id = "jscoTS_tab4" onclick = "_onTabStrip (this);" class = "tabsLink" title = "Registration Request"> Registration Request </ a > </ td >
= "tabRightLastOff" >< / div >< / td > < td > < div class = "tabRightLastOff"> </ div > </ td >
"100%" class = "topBG" >< / td > < td width = "100%" class = "topBG"> </ td >
</ tr >
</ table >
</ div >
"jscoTSC_jscoTS_tab1" class = "tabStripContent" > < div id = "jscoTSC_jscoTS_tab1" class = "tabStripContent">
p > < p > TAB SHEET 1 content </ p >
</ div >
"jscoTSC_jscoTS_tab2" class = "tabStripContentHidden" > < div id = "jscoTSC_jscoTS_tab2" class = "tabStripContentHidden">
p > < p > DATA TABLE 2 content </ p >
</ div >
"jscoTSC_jscoTS_tab3" class = "tabStripContentHidden" > < div id = "jscoTSC_jscoTS_tab3" class = "tabStripContentHidden">
p > < p > TAB SHEET 3 content </ p >
</ div >
"jscoTSC_jscoTS_tab4" class = "tabStripContentHidden" > < div id = "jscoTSC_jscoTS_tab4" class = "tabStripContentHidden">
p > < p > content TAB SHEET 4 </ p >
</ div >
</ div >

The PHP code that generates the HTML is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/ / ************************************************ ***********
/ /
/ / File: tabstrip.php
/ / Author: Giovambattista Fazioli (www.undolog.com)
/ / Web: http://www.undolog.com
/ / E-mail: info (at) undolog (dot) (com)
/ / Created: 03/10/2005 10:07
/ / Modified: 06/11/2005 07:17
/ /
/ / PROPERTIES
/ / Name - (string) - Name (ID) Window
/ / Style - (STRING) - Add Style Online
/ / Tabs - (ARRAY) - List of tabs (tab)
/ /
/ / METHODS
/ / AddTab () - Adds a tab to the TabStrip
/ / ToString () - Returns the HTML output for the Window
/ / Show () - Displays the HTML output for the Window
/ /
/ / NOTES
/ /
/ / EXAMPLES
/ /
/ / ************************************************ ***********

{class CSCO_UI_TABSTRIP

/ / # Public properties
; var $ name;
; var $ style;
; var $ tabs;
; var $ jsListener;

/ / # Private properties
; var $ strHeader;
; var $ strBody;

/ / ================================================ =====
/ / Constructor:
/ / ================================================ =====
$name , $jsListener = "" ) { CSCO_UI_TABSTRIP function ($ name, $ jsListener = "") {
name = $name ; $ This -> name = $ name;
jsListener = $jsListener ; $ This -> = $ jsListener jsListener;
tabs = array ( ) ; $ This -> tabs = array ();
}

/ / ================================================ =====
/ / METHOD: addTab ()
/ /
/ / DESCRIPTION
/ / Adds a tab to the TabStrip.
/ /
/ / EXAMPLES
/ /
/ / ================================================ =====
$name , $label , $tooltip , $content , $selected = false ) { addTab function ($ name, $ label, $ tooltip, $ content, $ selected = false) {
array ( "name" => $name , $ Tab = array ("name" => $ name,
$label , "Label" => $ label,
$tooltip , "Tooltips" => $ tooltips,
$content , "Content" => $ content,
$selected ) ; "Selected" => $ selected);
tabs [ ] = $tab ; $ This -> tabs [] = $ tab;
}

/ / ================================================ =====
/ / METHOD: toString ()
/ /
/ / DESCRIPTION
/ / Return the HTML output for the TabStrip.
/ /
/ / EXAMPLES
/ /
/ / ================================================ =====
function toString () {
/ /
strHeader = '<div id="cscoTabStrip" ' . $ This -> strHeader = '<div id = "cscoTabStrip"'.
-> style != "" ) ? 'style="' . $this -> style . '"' : '' ) . '>' . (($ This -> style! = "")? 'Style =' ". $ This -> style. '"':''). '>'.
'<Div'.
$this -> name . '">' . 'Id = "jscoTabStrip_'. $ This -> name. '">'.
'<table Border="0" width="100%" style="border-collapse: collapse;" cellspacing="0" cellpadding="0">'.
'<tr>';
"" ; $ StrBody = "";
/ / FirstLeft
( $this -> tabs [ 0 ] [ "selected" ] ) ? "tabLeftFirstOn" : "tabLeftFirstOff" ; ClassLeft $ = ($ this -> tabs [0] ['selected'])? "TabLeftFirstOn": "tabLeftFirstOff";
strHeader .= '<td><div class="' . $classLeft . '"></div></td>' ; $ This -> strHeader .= '<div <td> class="'. $classLeft.'"> </ Div> </ td>';
$i = 0 ; $i < sizeof ( $this -> tabs ) ; $i ++ ) { for ($ i = 0; $ i < sizeof ($ this -> tabs); $ i + +) {
/ /
( $this -> tabs [ $i ] [ "selected" ] ) ? "tabStripeOn" : "tabStripeOff" ; ClassBck $ = ($ this -> tabs [$ i] ['selected'])? "TabStripeOn": "tabStripeOff";
/ /
$i == ( sizeof ( $this -> tabs ) - 1 ) ) { if ($ i == ( sizeof ($ this -> tabs) - 1)) {
( $this -> tabs [ $i ] [ "selected" ] ) ? "tabRightLastOn" : "tabRightLastOff" ; ClassMiddle $ = ($ this -> tabs [$ i] ['selected'])? "TabRightLastOn": "tabRightLastOff";
{ Else {}
$this -> tabs [ $i ] [ "selected" ] ) { if ($ this -> tabs [$ i] ['selected']) {
"tabMiddleOnOff" ; $ ClassMiddle = "tabMiddleOnOff";
{ Else {}
( $this -> tabs [ $i + 1 ] [ "selected" ] ) ? "tabMiddleOffOn" : "tabMiddleOffOff" ; ClassMiddle $ = ($ this -> tabs [$ i + 1] ['selected'])? "TabMiddleOffOn": "tabMiddleOffOff";
}
}
/ /
/ /
strHeader .= '<td nowrap="nowrap" class="' . $classBck . '">' . $ This -> strHeader .= '<td nowrap="nowrap" class="'. $classBck.'">'.
$this -> tabs [ $i ] [ "tooltip" ] . '" class="tabsLink" onclick="_onTabStrip( this ' . ( ( $this -> jsListener != "" ) ? ( ",'" . $this -> jsListener . "'" ) : "" ) . ' );" id="jscoTS_' . $this -> tabs [ $i ] [ "name" ] . '">' . $this -> tabs [ $i ] [ "label" ] . '</a>' . '<a Title="'. $this -> Tabs [$ i] ["tooltip"].' "Class =" tabsLink "onclick =" _onTabStrip (this'. (($ This -> jsListener! = "") ? ('.' "$ this -> jsListener." '"):" ").')" id = "jscoTS_ '. $ this -> tabs [$ i] [' name '].'"> '. $ this -> tabs [$ i] [' label '].' </ a> '.
'</ Td>'.
$classMiddle . '"></div></td>' ; '<td> <div Class="'. $classMiddle.'"> </ Div> </ td>';
/ /
( $this -> tabs [ $i ] [ "selected" ] ) ? "tabStripContent" : "tabStripContentHidden" ; $ Class = ($ this -> tabs [$ i] ['selected'])? "TabStripContent": "tabStripContentHidden";
'<div class="' . $class . '" id="jscoTSC_jscoTS_' . $this -> tabs [ $i ] [ "name" ] . '">' . $this -> tabs [ $i ] [ "content" ] . '</div>' ; $ StrBody .= '<div class="'. $class.'" Id="jscoTSC_jscoTS_'. $this -> Tabs [$ i] [' name '].' "> '. $ This -> tabs [$ i] ["content"]. '</ div>';
/ /
}
/ / Align foo
strHeader .= '<td class="topBG" width="100%"></td>' . $ This -> strHeader .= '<td class="topBG" width="100%"> </ td>'.
'</ Tr> </ table>';

strBody = '<div>' . $strBody . '</div>' ; $ This -> strBody = '<div'. $ StrBody. '</ Div>';
/ /
$this -> strHeader . $this -> strBody . '</div></div>' ) ; return ($ this -> strHeader. $ this -> strBody. '</ div> </ div>');
}

/ / ================================================ =====
/ / METHOD: show ()
/ /
/ / DESCRIPTION
/ / Display the HTML output for the TabStrip.
/ /
/ / EXAMPLES
/ /
/ / ================================================ =====
function show () {
$this -> toString ( ) ) ; echo ($ this -> toString ());
}

} / / END OF FILE SCO_UI_TABSTRIP.PHP

To use the class just this snippet:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/ / File with the definition of the class
; require "tabstrip.php";

/ / Create object Tabstrip
new CSCO_UI_TABSTRIP ( "info" ) ; $ T = new CSCO_UI_TABSTRIP ("info");

/ / Create / read from file - the contents of the tabs
"Contenuto 1" ; $ S1 = "Content 1";
"Contenuto 2" ; $ S2 = "Content 2";
"Contenuto 3" ; $ S3 = "Content 3";
"Contenuto 4" ; $ S4 = "Content 4";

/ / Add cards
addTab ( "tab1" , "Caratteristiche" , "Caratteristiche" , $s1 , true ) ; $ T -> addTab ("tab1", "Features", "Features", $ s1, true);
addTab ( "tab2" , "Come funziona" , "Come funziona" , $s2 ) ; $ T -> addTab ("tab2", "How does it work", "How does it work", $ s2);
addTab ( "tab3" , "Interfaccia" , "Interfaccia" , $s3 ) ; $ T -> addTab ("TAB3", "Interface", "Interface", $ s3);
addTab ( "tab4" , "Richiesta Iscrizione" , "Richiesta Iscrizione" , $s4 ) ; $ T -> addTab ("tab4", "Registration Request", "Registration Request", $ s4);

/ / Show all - alternatively use toString () method
show ( ) ; $ T -> show ();

Let us define the styles:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
font-size : 13px } div # cscoTabStrip {font-size: 13px}

a.tabsLink , div # cscoTabStrip. tabStripeOff a.tabsLink,
a .tabsLink :link , div # cscoTabStrip. tabStripeOff to. tabsLink: link

a .tabsLink :hover { color : #f70 } div # cscoTabStrip. tabStripeOff to. tabsLink: hover {color: # f70}

a.tabsLink , div # cscoTabStrip. tabStripeOn a.tabsLink,
a .tabsLink :link , div # cscoTabStrip. tabStripeOn to. tabsLink: link

a .tabsLink :hover { } div # cscoTabStrip. tabStripeOn to. tabsLink: hover {}








{ background : url ( tabstrip/tabStripeOff.png ) repeat-x ; } div # cscoTabStrip. tabStripeOff {background: url (tab strip / tabStripeOff.png) repeat-x;}
{ background : url ( tabstrip/tabStripeOn.png ) repeat-x ; } div # cscoTabStrip. tabStripeOn {background: url (tab strip / tabStripeOn.png) repeat-x;}



{ text-align : right ; background : url ( tabstrip/topBg.png ) repeat-x ; } div # cscoTabStrip. topBG {text-align: right; background: url (tab strip / topBg.png) repeat-x;}

{ width : 100% ; padding : 0 ; } div # cscoTabStrip. tabStripContent {width: 100%; padding: 0;}
{ display : none ; } div # cscoTabStrip. tabStripContentHidden {display: none;}

The JavaScript code is very bland, written at a time when far away prototype.js does not exist. Also in the example below I use a library of effects (not even exist Scriptaculous ) still valid, then the line that uses the transition you can change the Opacity to whatever you want:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
t ) { _onTabStrip function (t) {
arguments. length > 1 ) { if (arguments. length> 1) {
"onBeforeClick" ; var evt = "onBeforeClick";
t. id . substr ( 7 ) ; var t = n id. substr (7);
"var res = " + arguments [ 1 ] + "('" + n + "','" + evt + "');" ; and var = "var res =" + arguments [1] + "('" + n + "','" + evt + "');";
e ) ; eval (s);
! res ) return ( false ) ; if (res) return (false);
}
t. parentNode . parentNode ; var tr = t. parentNode. parentNode;
var i = 1 ; i < tr. childNodes . length - 2 ; i ++ ) { for (var i = 1, i <tr. childNodes. length - 2; i + +) {
tr. childNodes [ i ] ; var td = tr. childNodes [i];
td. childNodes [ 0 ] ; var el = td. childNodes [0];
/ /
el. tagName ) { switch (el tagName) {
: case "DIV"
"tabMiddleOffOff" ; and. className = "tabMiddleOffOff";
break;
: case "A":
"tabStripeOff" ; td. className = "tabStripeOff";
break;
}
}
t. parentNode ; var td = t. parentNode;
[ 0 ] . className = "tabMiddleOffOn" ; td. previousSibling. childNodes [0]. className = "tabMiddleOffOn";
[ 0 ] . className = "tabMiddleOnOff" ; td. nextSibling. childNodes [0]. className = "tabMiddleOnOff";

Number ( ( tr. childNodes . length - 2 ) ) ; var last = Number ((tr. childNodes. length - 2));

= "tabStripeOn" ; t. parentNode. className = "tabStripeOn";
$G ( "jscoTSC_" + t. id ) ; var = mc $ G ("jscoTSC_" t + id);
mc. parentNode ; var d = mc. parentNode;
var i = 0 ; i < d. childNodes . length ; i ++ ) { for (var i = 0; i <d. childNodes. length; i + +) {
i ] . className = "tabStripContentHidden" ; d. childNodes [i]. className = "tabStripContentHidden";
}
"tabStripContent" ; mc. className = "tabStripContent";
new OpacityTween ( mc , Tween. regularEaseOut , 0 , 100 , 1 ) ; var to = new OpacityTween (mc Tween. regularEaseOut, 0, 100, 1);
t ; to. args = arguments ; to. t = t; to. args = arguments;
function ( ) { to. onMotionFinished = function () {
this . args . length > 1 ) { if (this. args. length> 1) {
"onAfterClick" ; var evt = "onAfterClick";
this . t . id . substr ( 7 ) ; var n = this. t. id. substr (7);
"var res = " + this . args [ 1 ] + "('" + n + "','" + evt + "');" ; and var = "var res =" + this. args [1] + "('" + n + "','" + evt + "');";
e ) ; eval (s);
}
};
; to. start ();
}

In practice the rows from 36 to 46 may be replaced with whatever you want, even a display = "none". The code is outdated, at least compared to the new techniques of unobtrusive JavaScript (today we would write it differently). But the part that remains interesting and relevant and configuration of the HTML table that manages the strip. It allows a high level of graphics performance, unlike some other methods that - essentially - Tab deal the cards as a simple DIV next to each other.
An even better way would be to use the z-index (stacking order) present in the CSS styles, so as to manage the overlay graphics. Unfortunately, to date, is a technique very difficult to implement because of the differences between browsers that make it unstable in fact, except in rare circumstances.
Soon I will make a more modern version ... if you have doubts or questions here!

Continued ...

Restyling: animation and interactivity

After fixing the graphics Undolog and have made ​​the final touches to a few titles (see sidebar), I enjoyed the couple to use prototype.js and Scriptaculous , in a non-intrusive (Unobtrusive)! Here's a video (but you can try it for yourself right here ;) ) With the nice feature that I added to the sidebar Undolog, which not only make it more enjoyable I hope makes it even more functional!

Loading Flash ...

The code I used is very simple:

1
2
3
4
5
6
7
8
9
window , 'load' , function ( ) { Event. Observe (window, 'load', function () {
) . each ( function ( element ) { element. style . cursor = "pointer" ; $ $ ('H2.dropdown'). Each (function (element) {element. Style. Cursor = "pointer";
'click' , function ( event ) { element. observe ('click', 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);
( element ) ) }. BindAsEventListener (element))
})
})

Also note that the first time you load the home page of the panel is automatically closed Undolog Categories - identified by ID tit_category :

1
window , 'load' , function ( ) { new Effect. BlindUp ( $ ( "tit_category" ) . next ( ) , { duration : .5 } ) } ) Event. Observe (window, 'load', function () {new Effect. BlindUp ($ ("tit_category.") Next (), {duration: .5})})

The titles on the sidebar are defined, then, in this way:

1
2
3
4
"tit_category" class = "dropdown replacetitle" title = "Categorie" >< span > Categorie < / span >< / h2 > < h2 id = "tit_category" class = "dropdown replacetitle" title = "Categories"> < span > categories </ span > </ h2 >
< div >
p > < p > to get rid of Content </ p >
</ div >

da rendere dinamici, grazie alla funzione doppio-dollaro ($$) di Prototype.js – di cui abbiamo già parlato… Through the class dropdown titles are identified H2 to make dynamic, thanks to the double-dollar ($ $) of prototype.js - we already talked about ...

Continued ...

Reflecting on Joost, Apollo and Browsers

Why switch to Apollo to display HTML and dynamic content when a browser already allows it? Why use Joost Net TV to see if a browser already allows it?

Why has not the producer of two simple browser functions within them:

  • Windowless windows
  • P2P Object

Windowless windows

This simple feature would make the most of the HTTP connection and make it really useful browsers. To open windows (pop-up in practice) with only the title and no border, just in case in transparency, increase the production of widgets to be exploited with the normal browser, like what he does now Apollo . With a careful study on the safety (as I think it is now the only reason for this limit) would open up very interesting scenarios.

P2P Object

As we all know by now all browsers support the object XMLHttpRequest , which has given rise to an endless amount of so-called Ajax applications. This object can be accessed via JavaScript, is able to provide an HTTP channel - parallel - scriptable client for both IINV and receiving data.
Sooner or later, as anticipated in various other blog, Adobe will insert a P2P in Flash. Why not do the same thing in the browser? An object of this type together with Windowless features allow you to create applications like Joost-without installing anything on your machine, ensuring cross-compatibility worthy of the Internet, thereby increasing the efficiency of production (now Joost is developed for each system operational, which is quite heavy - both in money and time - in fact, the beta will follow ...).

RSS FEED short windows with text, audio and video from the place where we want on our desktops, in true W3C standards. Open TCP channels are directly from JavaScript, with endless possibilities of data exchange. Clearly, the will is little and the "crime" is high, hackers, spam and phishing are lurking and moves of this kind terrorize a bit 'all ...

Continued ...

WordPress: categories in the dropdown

I state that we are talking about WordPress 2.0.6. If you try to set the categories in "combo" - dropdown - eye on the site of the proposed indications WordPress . When you make a HTML form with a SUBMIT button must be careful not to set the name of the input tag just "submit", worth ruining everything just trying to submittare the FORM via Javascript.

On the site of WordPress is proposed the following code:

1
2
3
4
5
6
<li id="categories">
'Categories:' ) ; ?> <? Php _e ('Categories');?>
<li>
$PHP_SELF ?> " method="get"> <?php dropdown_cats ( ) ; ?> <input type="submit" name="submit" value="view" /> </form> <Form action = "<? Php echo $ PHP_SELF?>" Method = "get"> <? Php dropdown_cats ();?> <input Type="submit" name="submit" value="view" /> </ form>
</ Li> </ ul>
</ Li>

Note that the submit button has the name attribute set to "submit". If you try to run at a Javascript code like this:

1
. submit ( ) ; document. forms. nomeform. submit ();

The interpreter gets confused because it does not distinguish the method submit () element "submit", which is a button! The solution is simple: call it what you will but not the button "submit"!

The code I used to display the categories in dropdown mode I is as follows:

1
2
3
4
5
<div id="cmb_months">
<form name="xcats" id="xcats" action="/index.php" method="get">
; ?> <? Php dropdown_cats ();?>
</ Form>
</ Div>

I also had to modify the kernel of WordPress (which should not be done ...). In the file "template-functions-category.php" I modified the function dropdown_cats () when preparing the select tag I added:

1
onchange = "document.forms ['xcats']. submit ();"

Here is the piece of code to track:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
$wpdb -> get_results ( $query ) ; $ Categories = $ wpdb -> get_results ($ query);
. " \n " ; echo '<select name="cat" class="postform" onchange="document.forms[\'xcats\'].submit();">'. "\ n";
intval ( $optionall ) == 1 ) { if ( intval ($ optionall) == 1) {
apply_filters ( 'list_cats' , $all ) ; $ To = apply_filters ('list_cats', $ all);
<option value='0'>Seleziona una Categoria</option> \n " ; echo "\ t <option value='0'> Select a Category </ option> \ n";
}
intval ( $optionnone ) == 1 ) if ( intval ($ optionnone) == 1)
<option value='-1'>" . __ ( 'None' ) . "</option> \n " ; echo "\ t <option value='-1'>". __ ('Name'). "</ option> \ n";
$categories ) { if ($ categories) {
$categories as $category ) { foreach ($ categories as $ category) {
apply_filters ( 'list_cats' , $category -> cat_name , $category ) ; $ Cat_name = apply_filters ('list_cats', $ category -> cat_name, $ category);
<option value= \" " . $category -> cat_ID . " \" " ; echo "\ t <option value= \"". $category -> cat_id. "\" ";
$category -> cat_ID == $selected ) if ($ category -> cat_id == $ selected)
; echo 'selected = "selected"';
; echo '>';
; echo $ cat_name;
intval ( $optioncount ) == 1 ) if ( intval ($ optioncount) == 1)
. $category -> cat_count . ')' ; echo '('. $ category -> cat_count. ')';
intval ( $optiondates ) == 1 ) if ( intval ($ optiondates) == 1)
. $category -> lastday . '/' . $category -> lastmonth ; echo ''. $ category -> lastday. '/'. $ category -> lastmonth;
" ; echo "</ option> \ n";
}
}
" ; echo "</ select> \ n";

One thing the function does is set the combo on the chosen category reload the page when I have time ... just look at him better.

As known to all, for the sake of completeness, I note that action was needed with a non-intrusive code (Unobtrusive) instead of entering directly into the construction of the onchange of the combo. In addition, the categories displayed in the combo are not accessible for browsers with Javascript disabled. However this can be solved by using the noscript tag in the sidebar and view the categories as a list of links - default mode of WordPress - adjustments that will soon ;) .

Continued ...

Unobtrusive Flash Objects

The insertion of objects (especially Flash Objects) in web pages has recently become an often stressful. In other posts we have already addressed the topic of how to detect Flash and insert pages appropriately. As we talked about Unobtrusive techniques, we mark two well-known script can detect (and eventually install) and insert Flash objects on a page, in a very unobtrusive and afficiente: SWFObject and UFO .
Both scripts have essentially the same features and the same operation. The approach is to replace it with a particular tag using Javascript on your browser. As we know, this procedure eliminates the problem of activation of the Flash object imposed by Internet Explorer, however, implies that Javascript is enabled on the target browser.
Both scripts do not use any external libraries such as prototype.js for example. The most important difference between the two is that SWFObject is called when the TAG to be replaced is already loaded on the page, not exactly how Unobtrusive. Here is an excerpt of code that shows the call sequence:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
"flashcontent" > < div id = "flashcontent">
strong > < strong > You need to upgrade your Flash Player </ p >
This Is Replaced by the Flash content.
Place your alternate content here and users without the Flash plugin or with
Javascript turned off will see this. > noscript < / code > Content here allows you to leave out < code inline = "true"> noscript </ code >
tags. "swfobject.html?detectflash=false" > bypass the detection < / a > if you wish. Includes a link to < a href = "swfobject.html? detectflash = false"> bypass the detection </ a > if you wish.
</ div >
"text/javascript" > < script type = "text / javascript">
/ / <! [CDATA [
, "sotester" , "300" , "300" , "9" , "#FF6600" ) ; var so = new SWFObject ("so_tester.swf", "sotester", "300", "300", "9", "# FF6600");
) ; // this line is optional, but this example uses the variable and displays this text inside the flash movie so.addVariable ("flashVarText", "this is passed in via FlashVars for example only") / / this line is optional, but this example uses the variable and displays this text inside the flash movie
; so.write ("flashcontent");
/ /]]>
</ script >

UFOs , however, allows un'approccio much more in line with the classic Unobtrusive script. The replacement of the TAG is in transparent mode without loading abbligare sequences, as shown in the example below:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
< head >
title > < title > Unobtrusive Flash Objects (UFO) | Sample Page </ title >
"Content-Type" content = "text/html; charset=iso-8859-1" / > < meta http-equiv = "Content-Type" content = "text / html; charset = iso-8859-1" />
"text/javascript" src = "ufo.js" >< / script > < script type = "text / javascript" src = "ufo.js"> </ script >
"text/javascript" > < script type = "text / javascript">
var FOR = {movie: "test8.swf", width: "300", height: "120", MajorVersion: "12", build: "0", xi: "true"};
UFO.create (FOR, "ufoDemo");
</ script >
</ head >
< body >
"ufoDemo" > < div id = "ufoDemo">
p > < p > Replacement content </ p >
"border: none;" / >< / a >< / p > Macromedia Flash Player "style =" border: none; "/> </ a > </ p >
</ div >
</ body >

In the source code of the script of UFOs , in fact, you can immediately use - more appropriate - an event that careful loading the page before you complete the replace operation; approach therefore extremely well suited to most scripts are not intrusive.

Continued ...

Javascript frameworks in Apollo

Among the various libraries - or set of libraries (real framework), dedicated to Ajax, HTML and Web 2.0 interface extension that I've seen, Ext is definitely worthy of note. The website and documentation are well done and organized, also the demo is not to be missed. The graphical user interface, compatibility with Prototype and Scriptaculous , and Yahoo Utils impletazione of, at least make it an interesting system! Beware though the license! Despite presenting himself as open source and free for personal use, requires a fee to enhance the use and care. The latter, in fact, is never to be underestimated in the framework of some complexity.

For documentation and demo click here .

In particular I mention this system, I'm still analyzing in detail, as it has been used to create Fresh Feed Reader , one of the sample applications provided with the release of Adobe Apollo Alpha (see Adobe Apollo Alpha Release ). Fresh, therefore, is example of a double of Apollo, which demonstrates its ability to leverage HTML and JavaScript at the most. Fresh, in fact, is not a pure Apollo, but uses the framework Ext - and then you need JavaScript and HTML - Apollo in the engine! Great!

Continued ...

Javascript Obfuscator Compressor

Here is a new and interesting tool for the compression and the darkening of Javascript code (see also Reverse Engineering: the compressors of code ).
On the Web site of Dean Edwards , you can download the source code of this compressor JavaScript. Furthermore, the author has made ​​available the server versions for Microsoft. NET Framework version 1.1, Perl, WHS and PHP5.

Online is a working version available to try immediately , less complex - to be honest - one that I had made ​​long ago . Fact allows to compress the code with only two choices: the Base62 encoded, which obscure the code and Shrink variables, the optimizer variables.
Compared to the previous version have been fixed some bugs that, in situations of extreme hacks (and really interesting) as:

1
/*@cc_on!@*/ false ; isMSIE var = / * @ cc_on! @ * / false;

did not comply with the generated output. Now both are properly supported conditional comments from Microsoft, is the + / - in conditions such as:

1
b ; c = a + + + b;

As outlined in page Help , however:

Packed scripts successfully unpack on all browsers Should That support JavaScript. Only basic JavaScript functionality is used to decode the packed script.

Some browsers not may support the packer itself. The web interface Requires DOM supported. Legacy browsers will display disabled interface.

So attention to end-users and the type of browser support as always ... the rest!

Continued ...

Unobtrusive Javascript: pseudo real &

In this post I would like to analyze the use of unobtrusive script from the point of view of the Web Designer. Normally, in fact, a script that is not intrusive towards the end of the navigator!
But it can also be used for the Web Designer?

Unobtrusive JavaScript from the perspective of the Web Designer

Putting ourselves in the shoes of a web designer can identify two categories of unobtrusive JavaScript: Unobtrusive Javascript true and pseudo unobtrusive JavaScript.

Both categories, however, are not completely non-intrusive (always from the point of view of the Web Designer). A real and complete unobtrusive JavaScript should not take any action on the Web page, but this is - for now - basically impossible. The minimal operation required during the installation of a script is, however, the inclusion of the inclusion of the script itself! It is, therefore, that this operation permissible - indeed - does not even require the web designer to make regular adjustments to the structure of the page. The simple placement of the inclusion of the script tag inside the head can be therefore considered non-intrusive.

The true unobtrusive JavaScript

The scripts of this type are the only ones that require inclusion of the script and not unobtrusive; claim any operation! Scripts of this type are, for example (the usual and oft-cited), Snap . Once you entered the code include the Web Designers must not engage in any further operation, as the script snap operates on standard tags.

Pseudo unobtrusive JavaScript

These are different from previous tagging as requiring further to run correctly. Examples of this type are Control.Tabs of Ryan Johnson to slide or library Lightbox JS . per identificare i link che devono essere modificati. Lightbox JS , in particolare, richiede addirittura la presenza esplicita sia di Prototype che di Scriptaculous . The latter solution, for example, requires the inclusion in the Tag A the attribute rel to identify the links that need to be modified. Lightbox JS , in particular, requires explicit and even the presence of Prototype that Scriptaculous . As indicated on the website Lightbox JS , the inclusion of the script should look like this:

1
2
3
"text/javascript" src = "js/prototype.js" >< / script > < script type = "text / javascript" src = "js / prototype.js"> </ script >
"text/javascript" src = "js/scriptaculous.js?load=effects" >< / script > < script type = "text / javascript" src = "js / scriptaculous.js? load = effects"> </ script >
"text/javascript" src = "js/lightbox.js" >< / script > < script type = "text / javascript" src = "js / lightbox.js"> </ script >

The links that point to un'immmagine you want to view the system with Lightbox JS should be written like this:

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 >

In addition to identify a group of images, to add the ability to scroll forward and backward images, tags A be set as follows:

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 >

The need for such constraints is evident, there is no easy way to distinguish a link element (Tag A ) from another. In particular it is not possible to understand which element the designer wants to display in one way or another. Web Designer must necessarily indicate somewhat Tags and their behaviors. Are therefore required - intrusive - totally understandable, not at all diminish the usefulness and potential of these scripts. Only lead to greater detail and a few lines of code in over the Web Designer.

It is interesting, however, the double aspect of 'unobtrusive JavaScript, is analyzed in terms of both end-user point of view, Web Designer.

Continued ...

Defects dell'unobtrusive JavaScript

As we talked about it well in the previous post, it's time to talk about evil (joke), or at least highlight some shortcomings of the technique of unobtrusive JavaScript.
If unobtrusive JavaScript code is executed when the page is completely loaded, it follows that the greater the amount of data (HTML) that makes up our page, and more time to wait before our code is executed.

This can result in implementation delays and resulting in an annoying flicker effect if you are working on the visual elements of the page. Take for example the code used by Ryan Johnson to create objects TabStrip. If you look at the demo you will find that for about one second, when the page loads, you can clearly see a standard layout to be replaced immediately after the TabStrip objects. Reloading the page again, thanks to the browser cache, the problem tends to decrease (try to clean all your browser's cache to see the time).

All this must make us reflect on the limits of this technique. The same snap suffers from exactly the same slowdown, especially in the pages that are often extremely high as that of undolog.com . Loading the home page of this blog is clear that Snap runs a few seconds later, ie when the page is completely loaded.

By definition of 'unobtrusive JavaScript is difficult to resolve this problem in general. However, in developing a site owner can take some steps aimed at eliminating or reducing these defects. A fairly simple way is to create a sort of preload, an element frequently used in Adobe Flash. You can then set the body tag - which contains all the elements of the page - so that it is invisible, leaving the task of Javascript code to make it visible when it has finished - if any - changes to the DOM:

1
"ibody" style = "display:none" > < body id = "ibody" style = "display: none">

The unobtrusive JavaScript code at the end of its operations:

1
2
3
"ibody" ) . style . display = "" ; document. getElementById ("ibody.") style. display = "";
/ / If you use the prototype
) . style . display = "" ; $ ("Ibody.") Style. Display = "";

Solution, however, trivial and not always applicable. Moreover, even if we somehow solved the problem of the first caricameno, navigate in such a manner in the long run could be really annoying for surfers. Do not be intrusive, therefore, has a price to pay. Even operating at the object level, for example by setting only the interesting elements in the hidden mode, the fact that the code starts at the end of loading the entire page with it inevitably leads to the exact same problems.

Continued ...

Examples of unobtrusive Javascript

As promised here are some concrete example of unobtrusive JavaScript, versatile and powerful tool if used properly. On Site / Blog Ryan Johnson you can download two really great example of unobtrusive JavaScript:

Ryan Johnson, in his script, the library uses Prototype , like many of the rest. He has also written some extensions to the relatively Prototype , then introduced - in a different form - in the latest version of the library.
Using Prototype to illustrate the operation of unobtrusive JavaScript code is usually more comfortable - as we shall see later, but here's a crude example that requires no external libraries. We begin by recalling that the concept behind the Unobtrusive JavaScript is to start from any HTML page (standard and not necessarily written by us - more important strong point) and use Javascript to make some changes.

Schematimamente the concept is to perform a function that parses the HTML, then traverses the DOM and in particular points to add or change functionality. Normally two methods are exploited to execute Javascript code to load a page: the first is what you do not enclose the code in any function, and then let the browser execute code immediately uploaded to the point where the call appears:

1
script > < script > alert ("Hello"); </ script >

The same result is obtained by including the code:

1
"http://miosito.com/miocodice.js" >< / script > < script src = "http://miosito.com/miocodice.js"> </ script >

However, when it must operate on the DOM of a page that it assumes a fully loaded, that all the TAG of the page is present and available to be tracked. So the best solution becomes the one to be sure that the page is complete. This is possible by engaging the body tag onload event for example, which is released when the page load is complete.

1
2
3
miafunzione ; window. onload = myfunction;
/ / Or, which is the same
function ( ) { alert ( "Hello" ) ; } window. onload = function () {alert ("Hello");}

Be avoided, of course, the canonical solution that would be an understatement to call it intrusive:

1
"miafunzione()" > < body onload = "myfunction ()">

Another technique, more coarsely and equally intrusive (as would force the end user to place the code in a particular spot), is to put our script at the end of the document before the closing body tag, now obsolete technique and used in rare cases (see Google Analytics!).

Even better is to use the method below:

1
2
3
4
5
6
7
window. addEventListener ) { if (window. addEventListener) {
"load" , miafunzione , false ) ; window. addEventListener ("load", myfunction, false) ¾ Í
( window. attachEvent ) { } Else if (window. attachEvent) {
"onload" , miafunzione ) ; window. attachEvent ("onload", myfunction) ¾ Í
{ Else {}
createSubMenus; window. createSubMenusÍ onload = ¾
}

Even this piece of code is enclosed in a function. It will add an event listener for the load event of the window, calling our function miafunzione() . . Modern browsers, like FireFox for example, will use the function addEventListener() defined in DOM Level 2 specification, while Internet Explorer will use its proprietary function attachEvent() . However we are not at perfection in this way, in fact, replace all - any - onload events created by other scripts, which is not really "non-intrusive."

To quickly resolve the issue, that because of the different behavior of the browser would be least complicated to explain here, it is convenient to use as libreirie Prototype providing un'elengantissimo method to overcome the problem:

1
window , 'load' , function ( ) { alert ( "Hello" ) ; } ) ; Event. Observe (window, 'load', function () {alert ("Hello");});

The syntax is very obvious and spectacular! The advantage for those who had not understood, is that you can write:

1
2
window , 'load' , function ( ) { alert ( "Hello 1" ) ; } ) ; Event. Observe (window, 'load', function () {alert ("Hello 1");});
window , 'load' , function ( ) { alert ( "Hello 2" ) ; } ) ; Event. Observe (window, 'load', function () {alert ("Hello 2");});

On loading the page will be shown before the alert "Hello 2" and then alert "Hello 1". Basically you load in a FILO (First Last Input Output) a stack, while ensuring the execution of all events attached to the load of the document, exactly what you wanted to get. In this way a page can load - virtually - endless unobtrusive JavaScript that hook to load the document.

But what can be done with this technique? Many interesting things. An example that we can comment (see also Prototype: The use of the double dollar sign ($ $) ) comes from Tobie Langel . With a few lines of code and downloading libraries Prototype and Scriptaculous you can give a nice effect to the classic anchor of our pages. First create an HTML page with the following code:

1
2
3
4
5
6
7
8
= "#capitolo1" > Vai al capitolo 1 < / a >< / p > < p > < a href = "# Chapter 1"> Go to Chapter 1 </ a > </ p >

< / p > < p > </ p >
< / p > < p > </ p >

.... < / p > .... a lot 'of < p > </ p > .... just as an example

"capitolo1" > Capitolo 1 < / h1 > < h1 id = "Chapter 1"> Chapter 1 </ h1 >

Include the page:

1
2
3
4
5
6
7
8
9
10
11
12
"prototype.js" type = "text/javascript" charset = "utf-8" >< / script > < script src = "prototype.js" type = "text / javascript" charset = "utf-8"> </ script >
"scriptaculous-js-1.7.0/src/effects.js" type = "text/javascript" charset = "utf-8" >< / script > < script src = "scriptaculous-js-1.7.0/src/effects.js" type = "text / javascript" charset = "utf-8"> </ script >

"text/javascript" language = "javascript1.2" > < script type = "text / javascript" language = "JavaScript1.2">
Event.observe (window, 'load', function () {
$ $ ('A [href ^=#]: not ([href =#])'). each (function (element) {
element.observe ('click', function (event) {new Effect.ScrollTo (this.hash.substr (1));
Event.stop (event);
bindAsEventListener (element))
})
})
</ script >

Thanks to "use Event.observe() function and two-dollar ($ $) you can easily modify the behavior of the classic anchor. In this case a new function is hooked to upload the HTML page. When taking the load event is traced all the links in the DOM (Tag <A>) with href that begins with the pound sign (#, excluding the one with only a pound!). To these elements is a function attached to the click event, similar to what was done with the load of the document. At this point comes into play Scriptaculous effect that produces a scroll to the item from our punat links - changed!

Continued ...