forked from jaked/ocamljs
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add jQuery "Live Examples" based on tutorial at jquery.com
- Loading branch information
Showing
6 changed files
with
269 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
DIRS=live_examples | ||
|
||
all: | ||
for dir in $(DIRS); do \ | ||
$(MAKE) -C $$dir all || exit; \ | ||
done | ||
|
||
clean: | ||
for dir in $(DIRS); do \ | ||
$(MAKE) -C $$dir clean || exit; \ | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
all: myocamlbuild.ml | ||
ocamlbuild live_examples.js | ||
|
||
clean: | ||
ocamlbuild -clean | ||
rm -f myocamlbuild.ml | ||
|
||
myocamlbuild.ml: | ||
ln -s ../../../tools/myocamlbuild.ml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<live_examples.ml> : pkg_ocamljs,pkg_dom,pkg_jquery | ||
<live_examples.js> : pkg_ocamljs,pkg_dom,pkg_jquery |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" | ||
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> | ||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"> | ||
<head> | ||
<meta http-equiv="content-type" content="text/html; charset=utf-8" /> | ||
|
||
<title>Live Examples of jQuery</title> | ||
|
||
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script> | ||
<script type="text/javascript" src="_build/live_examples.js"></script> | ||
|
||
<style type="text/css"> | ||
.changeP{ | ||
color: #FFFFFF; | ||
border: 2px solid #CC6633; | ||
width: 150px; | ||
background-color: #CC6633; | ||
padding:10px; | ||
line-height:1.4em; | ||
} | ||
|
||
.alert { | ||
font-weight: bold; | ||
color: #FFFFFF; | ||
background-color: #FF0000; | ||
padding: 10px; | ||
text-transform:uppercase; | ||
} | ||
|
||
.addedtext{ | ||
color:#FF0000; | ||
} | ||
|
||
pre { | ||
display: none; | ||
} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div style="padding:10px;margin:10px;background:#F5F5F5;border:1px solid #DDD;"> | ||
<p><big>An interactive demonstration of the basics behind jQuery.</big> | ||
</p><p><b>Original:</b> <a href="http://codylindley.com/Javascript/241/jquery-to-the-rescue" class="external free" title="http://codylindley.com/Javascript/241/jquery-to-the-rescue">http://codylindley.com/Javascript/241/jquery-to-the-rescue</a><br /> | ||
<b>Author:</b> <a href="http://codylindley.com/" class="external text" title="http://codylindley.com/">Cody Lindley</a> | ||
</p> | ||
</div> | ||
<p>Use the buttons to the left, in the examples, to run jQuery code on the structural markup below. Showing the code for each example will display the jQuery code required to make the changes to the structural markup happen. | ||
</p> | ||
|
||
<div style="float:left;width:48%;margin-right:2%;"> | ||
<h2>Examples:</h2> | ||
|
||
<p><strong>Example A</strong></p> | ||
<p>Get number of paragraphs in column 2 and display that number in an alert box. Including the one in the red box.</p> | ||
<input type="button" value="# of Paragraphs" class="buttonAsize" /> | ||
<a href="#" class="codeButtonA">Show / Hide jquery code</a> | ||
<pre class="codeA">(j "input.buttonAsize")#click | ||
(fun _ -> | ||
let size = ((j "div.contentToChange")#find "p")#size in | ||
window#alert (string_of_int size); | ||
false);</pre> | ||
|
||
<br/> | ||
|
||
<p><strong>Example B</strong></p> | ||
<p>Animate a paragraph in Column 2 by using a slide animation.</p> | ||
|
||
<input type="button" value="Slide Out" class="buttonBslideup" /> | ||
<input type="button" value="Slide In" class="buttonBslidedown" /> | ||
<a href="#" class="codeButtonB">Show / Hide jquery code</a> | ||
<pre class="codeB">(j "input.buttonBslidedown")#click | ||
(fun _ -> | ||
((j "div.contentToChange")#find "p.firstparagraph:hidden") | ||
#slideDown_speed_ "slow" ignore; | ||
false); | ||
(j "input.buttonBslideup")#click | ||
(fun _ -> | ||
((j "div.contentToChange")#find "p.firstparagraph:visible") | ||
#slideUp_speed_ "slow" ignore; | ||
false);</pre> | ||
|
||
<br/> | ||
|
||
<p><strong>Example C</strong></p> | ||
<p>Add/Remove text from the end of all <p> elements in column 2 except the paragraph in the red box.</p> | ||
|
||
<input type="button" value="Add" class="buttonCAdd" /> | ||
<input type="button" value="Remove" class="buttonCRemove" /> | ||
<a href="#" class="codeButtonC">Show / Hide jquery code</a> | ||
<pre class="codeC">(j "input.buttonCAdd")#click | ||
(fun _ -> | ||
(((j "div.contentToChange")#find "p")#not ".alert") | ||
#append "<strong class=\"addedtext\">&nbsp;This text was just appended to this paragraph</strong>"; | ||
false); | ||
(j "input.buttonCRemove")#click | ||
(fun _ -> | ||
(j "strong.addedtext")#remove; | ||
false);</pre> | ||
|
||
<br/> | ||
|
||
<p><strong>Example D</strong></p> | ||
|
||
<p>Remove paragraph with fade and animation.</p> | ||
<input type="button" value="Remove" class="buttonDhide" /> | ||
<a href="#" class="codeButtonD">Show / Hide jquery code</a> | ||
<pre class="codeD">(j "input.buttonDhide")#click | ||
(fun _ -> | ||
((j "div.contentToChange")#find "p.thirdparagraph") | ||
#hide_speed_ "slow" ignore; | ||
false);</pre> | ||
|
||
<br/> | ||
|
||
<p><strong>Example E</strong></p> | ||
<p>Change the font weight and color of all Italic text in column 2 by adding CSS properties and values to all <em> elements.</p> | ||
|
||
<input type="button" value="Change Italics" class="buttonEitalics" /> | ||
<a href="#" class="codeButtonE">Show / Hide jquery code</a> | ||
<pre class="codeE">(j "input.buttonEitalics")#click | ||
(fun _ -> | ||
((j "div.contentToChange")#find "em")#css_obj_ | ||
(object | ||
method color = "#993300" | ||
method fontWeight = "bold" | ||
end); | ||
false);</pre> | ||
|
||
<br/> | ||
|
||
<p><strong>Example F</strong></p> | ||
<p>Change the CSS on the fifth paragraph in Column 2 by adding a class value to the <p> element.</p> | ||
|
||
<input type="button" value="Add Class" class="buttonFaddclass" /> | ||
<input type="button" value="Remove Class" class="buttonFremoveclass" /> | ||
<a href="#" class="codeButtonF">Show / Hide jquery code</a> | ||
<pre class="codeF">(j "input.buttonFaddclass")#click | ||
(fun _ -> (j "p.fifthparagraph")#addClass "changeP"; false); | ||
(j "input.buttonFremoveclass")#click | ||
(fun _ -> (j "p.fifthparagraph")#removeClass "changeP"; false);</pre> | ||
</div> | ||
|
||
<div style="float:right;width:50%;background:#F5F5F5;" class="contentToChange"> | ||
<h2 style="margin-left:30px;">Column 2:</h2> | ||
|
||
<p class="alert">Use the buttons to the left to run jQuery code on the HTML below.</p> | ||
|
||
<p class="firstparagraph">Lorem ipsum <em>dolor</em> sit amet, consectetuer <em>adipiscing</em> elit, sed diam nonummy nibh euismod <em>tincidunt</em> ut laoreet dolore magna aliquam erat <strong>volutpat</strong>. Ut wisi enim ad minim <em>veniam</em>, quis nostrud exerci <strong>tation</strong> ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p> | ||
|
||
<p class="secondparagraph">Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse <strong>molestie</strong> consequat, vel illum <strong>dolore</strong> eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer <strong>adipiscing</strong> elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> | ||
|
||
<p class="thirdparagraph">Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea <em>commodo</em> consequat. Duis autem vel eum iriure dolor in hendrerit in <em>vulputate</em> velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te <strong>feugait</strong> nulla facilisi.</p> | ||
|
||
<p class="fourthparagraph">Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, <strong>quis</strong> nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. | ||
Duis autem vel eum iriure dolor in <em>hendrerit</em> in vulputate velit <em>esse</em> molestie consequat, vel illum dolore eu feugiat nulla <strong>facilisis</strong> at vero eros et accumsan et <em>iusto</em> odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te <strong>feugait</strong> nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh <strong>euismod</strong> tincidunt ut laoreet <em>dolore</em> magna aliquam erat volutpat.</p> | ||
|
||
<p class="fifthparagraph">Lorem ipsum <em>dolor</em> sit amet, consectetuer <em>adipiscing</em> elit, sed diam nonummy nibh euismod <em>tincidunt</em> ut laoreet dolore magna aliquam erat <strong>volutpat</strong>. Ut wisi enim ad minim <em>veniam</em>, quis nostrud exerci <strong>tation</strong> ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</p> | ||
|
||
<p class="sixthparagraph">Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse <strong>molestie</strong> consequat, vel illum <strong>dolore</strong> eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer <strong>adipiscing</strong> elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.</p> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
open JQuery | ||
open Dom | ||
|
||
let () = jQuery_ready | ||
begin fun j -> | ||
|
||
(* Code for example A *) | ||
(j "input.buttonAsize")#click | ||
(fun _ -> | ||
let size = ((j "div.contentToChange")#find "p")#size in | ||
window#alert (string_of_int size); | ||
false); | ||
(* Show code example A *) | ||
(j "a.codeButtonA")#click (fun _ -> (j "pre.codeA")#toggle; false); | ||
|
||
(* Code for example B *) | ||
(j "input.buttonBslidedown")#click | ||
(fun _ -> | ||
((j "div.contentToChange")#find "p.firstparagraph:hidden") | ||
#slideDown_speed_ "slow" ignore; | ||
false); | ||
(j "input.buttonBslideup")#click | ||
(fun _ -> | ||
((j "div.contentToChange")#find "p.firstparagraph:visible") | ||
#slideUp_speed_ "slow" ignore; | ||
false); | ||
(* Show code example B *) | ||
(j "a.codeButtonB")#click (fun _ -> (j "pre.codeB")#toggle; false); | ||
|
||
(* Code for example C *) | ||
(j "input.buttonCAdd")#click | ||
(fun _ -> | ||
(((j "div.contentToChange")#find "p")#not ".alert") | ||
#append "<strong class=\"addedtext\"> This text was just appended to this paragraph</strong>"; | ||
false); | ||
(j "input.buttonCRemove")#click | ||
(fun _ -> | ||
(j "strong.addedtext")#remove; | ||
false); | ||
(* Show code example C *) | ||
(j "a.codeButtonC")#click (fun _ -> (j "pre.codeC")#toggle; false); | ||
|
||
(* Code for example D *) | ||
(j "input.buttonDhide")#click | ||
(fun _ -> | ||
((j "div.contentToChange")#find "p.thirdparagraph") | ||
#hide_speed_ "slow" ignore; | ||
false); | ||
(* Show code example D *) | ||
(j "a.codeButtonD")#click (fun _ -> (j "pre.codeD")#toggle; false); | ||
|
||
(* Code for example E *) | ||
(j "input.buttonEitalics")#click | ||
(fun _ -> | ||
((j "div.contentToChange")#find "em")#css_obj_ | ||
(object | ||
method color = "#993300" | ||
method fontWeight = "bold" | ||
end); | ||
false); | ||
(* Show code example E *) | ||
(j "a.codeButtonE")#click (fun _ -> (j "pre.codeE")#toggle; false); | ||
|
||
(* Code for example F *) | ||
(j "input.buttonFaddclass")#click | ||
(fun _ -> (j "p.fifthparagraph")#addClass "changeP"; false); | ||
(j "input.buttonFremoveclass")#click | ||
(fun _ -> (j "p.fifthparagraph")#removeClass "changeP"; false); | ||
(* Show code example F *) | ||
(j "a.codeButtonF")#click (fun _ -> (j "pre.codeF")#toggle; false); | ||
|
||
end |