1 Event.observe(window, 'load', function() {
2 var fields = $$("input");
3 for (var i = 0; i fields[i].onfocus = function() {this.className += ' focused';}
4 fields[i].onblur = function() {this.className = this.className.replace('focused', '');}
5 }
6 });
7
8
9
10
11
Event.observe(window, 'load', function() {
var fields = $$("input");
for (var i = 0; i fields[i].onfocus = function() {this.className += ' focused';}
fields[i].onblur = function() {this.className = this.className.replace('focused', '');}
}
});
a very simple function.
1 extensions = new Array(".jpg", ".png");
2 function limitImage(file, extensions) {
3 allowed = false;
4 if (!file) return;
5
6 while (file.indexOf("\\") != -1)
7 file = file.slice(file.indexOf("\\") + 1);
8 ext = file.slice(file.indexOf(".")).toLowerCase();
9 for (var i = 0; i < extensions.length; i++) {
10 if (extensions[i] == ext) { allowed = true; break; }
11 }
12 return allowed;
13 }
extensions = new Array(".jpg", ".png");
function limitImage(file, extensions) {
allowed = false;
if (!file) return;
while (file.indexOf("\\") != -1)
file = file.slice(file.indexOf("\\") + 1);
ext = file.slice(file.indexOf(".")).toLowerCase();
for (var i = 0; i < extensions.length; i++) {
if (extensions[i] == ext) { allowed = true; break; }
}
return allowed;
}
source: http://snipplr.com/view/9321/vertically-align-within-browser-window/
1 <div id="verticalContainer">
2 This text will always be vertically centered inside the browser window
3 </div>
4
5 <script type="text/javascript">
6 function getWindowHeight() {
7 var windowHeight = 0;
8 if (typeof(window.innerHeight) == 'number') {
9 windowHeight = window.innerHeight;
10 }
11 else {
12 if (document.documentElement && document.documentElement.clientHeight) {
13 windowHeight = document.documentElement.clientHeight;
14 }
15 else {
16 if (document.body && document.body.clientHeight) {
17 windowHeight = document.body.clientHeight;
18 }
19 }
20 }
21 return windowHeight;
22 }
23
24 function setContent() {
25 if (document.getElementById) {
26 var windowHeight = getWindowHeight();
27 if (windowHeight > 0) {
28 var contentElement = document.getElementById('verticalContainer');
29 var contentHeight = contentElement.offsetHeight;
30 if (windowHeight - contentHeight > 0) {
31 contentElement.style.position = 'relative';
32 contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
33 }
34 else {
35 contentElement.style.position = 'static';
36 }
37 }
38 }
39 }
40
41 window.onresize = function() {
42 setContent();
43 }
44
45 window.onload = function() {
46 setContent();
47 }
48 </script>
<div id="verticalContainer">
This text will always be vertically centered inside the browser window
</div>
<script type="text/javascript">
function getWindowHeight() {
var windowHeight = 0;
if (typeof(window.innerHeight) == 'number') {
windowHeight = window.innerHeight;
}
else {
if (document.documentElement && document.documentElement.clientHeight) {
windowHeight = document.documentElement.clientHeight;
}
else {
if (document.body && document.body.clientHeight) {
windowHeight = document.body.clientHeight;
}
}
}
return windowHeight;
}
function setContent() {
if (document.getElementById) {
var windowHeight = getWindowHeight();
if (windowHeight > 0) {
var contentElement = document.getElementById('verticalContainer');
var contentHeight = contentElement.offsetHeight;
if (windowHeight - contentHeight > 0) {
contentElement.style.position = 'relative';
contentElement.style.top = ((windowHeight / 2) - (contentHeight / 2)) + 'px';
}
else {
contentElement.style.position = 'static';
}
}
}
}
window.onresize = function() {
setContent();
}
window.onload = function() {
setContent();
}
</script>
this’s used here!
1 <script type="text/javascript">
2 function clickclear(thisfield, defaulttext) {
3 if (thisfield.value == defaulttext) {
4 thisfield.value = "";
5 }
6 }
7
8 function clickrecall(thisfield, defaulttext) {
9 if (thisfield.value == "") {
10 thisfield.value = defaulttext;
11 }
12 }
13 </script>
14
15 <input id="search" type="text" name="q" value="search" onclick="clickclear(this, 'search')" onblur="clickrecall(this,'search')"/>
<script type="text/javascript">
function clickclear(thisfield, defaulttext) {
if (thisfield.value == defaulttext) {
thisfield.value = "";
}
}
function clickrecall(thisfield, defaulttext) {
if (thisfield.value == "") {
thisfield.value = defaulttext;
}
}
</script>
<input id="search" type="text" name="q" value="search" onclick="clickclear(this, 'search')" onblur="clickrecall(this,'search')"/>
1 <script type="text/javascript">
2 function jsonFlickrFeed(o){
3 var i = 0;
4 while(o.items[i]){
5 document.write('<img src="' + o.items[i].media.m + '" alt="' + o.items[i].title +'">');
6 i++;
7 }
8 }
9 </script>
10 <script src="http://api.flickr.com/services/feeds/photos_public.gne?id=28203925@N08&lang=en-us&format=json" type="text/javascript"></script>
<script type="text/javascript">
function jsonFlickrFeed(o){
var i = 0;
while(o.items[i]){
document.write('<img src="' + o.items[i].media.m + '" alt="' + o.items[i].title +'">');
i++;
}
}
</script>
<script src="http://api.flickr.com/services/feeds/photos_public.gne?id=28203925@N08&lang=en-us&format=json" type="text/javascript"></script>
a simple listener: $(’myForm’).observe(‘submit’, validateMyForm) dont support extra params in the function (in the case, validateMyForm. the solution:
1 $('myForm').observe('submit', function(event) {
2 validateMyForm(event, param1, param2);
3 });
$('myForm').observe('submit', function(event) {
validateMyForm(event, param1, param2);
});
create a link with this:
1 javascript: resizeTo(800,600);
2
3 javascript: resizeTo(1024,768);
javascript: resizeTo(800,600);
javascript: resizeTo(1024,768);