JavaScript

JavaScript, JS, source code, scripts, developing, tips & hints

Change the CSS of your site with JavaScript

0

This is a useful trick.

Change the CSS of the site without loading the entire site. It’s something really easy to do.

Here you can find this small example to do it:

Imagine that you have 2 css (can be only 1), 1 with all the styles and another with the colors:

<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="blue.css" />

Then we do more CSS with different colors:

<link rel="stylesheet" type="text/css" href="green.css" />
<link rel="stylesheet" type="text/css" href="blue.css" />
<link rel="stylesheet" type="text/css" href="purple.css" />
<link rel="stylesheet" type="text/css" href="orange.css" />

Well, then first we need to put an ID to the style we want to change:

<link rel="stylesheet" type="text/css" href="style.css" />
<link rel="stylesheet" type="text/css" href="blue.css" id="css_color" />

(more…)

jsClock – JavaScript Clock with few options

0

I needed a Clock that is updating automatically and takes the time from the server (same as the office), also they want to display the time in other countries to have a reference.

For this I developed a “simple” (how much I like this word) script to update times.

Screenshot:
screenshot jsClock   JavaScript Clock with few options
Demo
Download

Installation:
Download, unzip and serve your self!

UPDATE: Faster way, just copy paste this in your site:

<script type='text/javascript' src='http://lab.neo22s.com/jsClock/jsClock.js'></script>
<link rel="stylesheet" href="http://lab.neo22s.com/jsClock/jsClock.css" type="text/css" />
<div id="rellotje" class="clock"></div>
<script type='text/javascript'>moveClock("rellotje");</script>

Usage:
(more…)

webLab – Create your own php-html lab

3

Since I opened the lab, few people asked to me how it works.

Today I’m going to answer that and also I will release the code that makes the lab possible.

The lab is a really simple script:

  1. Reads from a given path all the files and paths that are inside.
  2. The list is shorted by date of creation (in this way we have the newest script in the top).
  3. We only display the folders that have a readme.txt file inside.
  4. If inside the folder there’s a screenshot or a .zip or index.php or index.html we show this options.

Of course right now only works with HTML and PHP, but for me is enough.

For a new script to appear in the list must be have this requirements:

/folderExample/
readme.txt (mandatory, you can ad as many new fields as you wish)
screenshot.png (optional)
index.php or index.html (example for the running script, optional)
folderExample.zip (download for the script, optional)

Improvements that I have in mind:

  • Pagination
  • RSS

Version: 0.1
Author: Chema Garrido
License: GPL v3

Demo in lab.neo22s.com
Download

Check file extension in JavaScript

2

Easy script to check extensions on JavaScript.

function checkExt(e) {//use in a form event or ina input
       value=e.value;
	if( !value.match(/\.(jpg)|(gif)|(png)|(bmp)|(pdf)$/) ){//here your extensions
		alert("wrong extension");	//actions like focus, not validate...
	}
	else {//right extension
		alert("nice!");	//actions
	}
}

Usage example onchange event:

<input id="Path" name="Path" type="file" />

Just one that says if is PDF or not:

function isPdf(e) {
if( e.value.match(/\.(pdf)$/) ){
	alert("pdf");	//action
      }
	else alert("no pdf");	//actions
}

Same as the other one.

I know they are really simple but I never need it to validate this in the client side since today. Kind of weird xD

JavaScript to return dimensions

2

Three useful functions for JavaScript.

They are not the best since you need to have X and Y as global variables, but it works.

var x,y;//GLOBAL
function returnInnerDimensions(){//returns screen size X,Y
	if (self.innerHeight){ // all except Explorer
		x = self.innerWidth;
		y = self.innerHeight;
	}
	else if (document.documentElement && document.documentElement.clientHeight){// Explorer 6 Strict Mode
		x = document.documentElement.clientWidth;
		y = document.documentElement.clientHeight;
	}
	else if (document.body){ // other Explorers
		x = document.body.clientWidth;
		y = document.body.clientHeight;
	}
}
 
function returnScrollOffset(){//return how much we scrolled already
	if (self.pageYOffset){ // all except Explorer
		x = self.pageXOffset;
		y = self.pageYOffset;
	}
	else if (document.documentElement && document.documentElement.scrollTop){// Explorer 6 Strict
		x = document.documentElement.scrollLeft;
		y = document.documentElement.scrollTop;
	}
	else if (document.body){ // all other Explorers
		x = document.body.scrollLeft;
		y = document.body.scrollTop;
	}
}
 
function returnPageDimensions(){//returns the page size, max X and max Y
	var sh = document.body.scrollHeight;
	var oh= document.body.offsetHeight
	if (sh > oh){ // all but Explorer Mac
		x = document.body.scrollWidth;
		y = document.body.scrollHeight;
	}
	else {// Explorer Mac;would also work in Explorer 6 Strict, Mozilla and Safari
		x = document.body.offsetWidth;
		y = document.body.offsetHeight;
	}
}

Works in ie5,ie6,ie7,ie8, Firefox, Chrome, Safari. That I could try ;)

jsCheckBox – Advanced select unselect checbox

0

Today I will show an script that is really useful to work with Checkbox, at least to me ;)

Script Name: jsCheckBox
Version: 0.1
License: GPL v3
Screenshot:
screenshot jsCheckBox   Advanced select unselect checbox

Demo
Download

Usage: (more…)

Confirm before click in JavaScript

0

Easy tip of the day xD

You want to have a modal of confirmation before an action?

Here you have the way of doing this:

<a href="http://neo22s.com" onclick="return confirm('Are you sure you want to continue?');" >neo22s.com</a>


Try the confirm modal

Of course it works at any other HTML tag.

jsScroll – Smooth scroll for your site

6

Smooth vertical scroll for your site, really easy to use, fast and light. Doesn’t use any external library ;)

Script Name: jsScroll
Version: 0.3
License: GPL v3
Screenshot:
screenshot jsScroll   Smooth scroll for your site
Demo
Download

Installation:
(more…)

Creating following pop ups in JavaScript

0

Still in many web pages they use the annoying pop up style that you don’t know where they are going, you can’t follow that pop up either search engines…

Normal pop up:

<a onclick="window.open('http://neo22s.com','popup','width=300,height=400')" href="#">Bad link</a>

Bad link

Why is so wrong:

  • You can’t follow where the heck the link is going
  • Search engines can’t either
  • Not possible to open the link in a new Tab
  • You need to have JavaScript enabled
  • Is difficult to add it to favorites
  • Doesn’t follow the standards

Good way following pop up:

<a href="http://neo22s.com" onclick="window.open(this.href, this.target,'width=300,height=400');return false;">Like this you can follow me!</a>

Like this you can follow me!

All of this comes from a client that ask me today why he couldn’t open that link of his webpage in a new tab…

jsTabs – Simple tab switcher

3

Hi there!

First script to release!

Today I was working on a simple solution for a tab switcher, I found many ways of doing it, but many of them required jQuery or another and why the heck I want all that big script if I just want a tab switcher.

Guess what? I better do it myself :P

The thing is that this is the first script that I release here, normally I would try to follow this schema for each script.

Script Name: jsTabs
Version: 0.1
License: GPL v3
Screenshot:
screenshot jsTabs   Simple tab switcher

Live Demo

Download

Installation

Just download the .zip file , uncompress and try ;)

Support: Use the forum please ;) (more…)

Page 2 of 212
Go to Top