Flash Games

 FAQ   Search   Members   Groups   Register  User Control Panel      Login 

Your time now:
Sat Nov 21, 2009 11:10 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 7 posts ]  Bookmark and Share
Author Message
 Post subject: Show, Hide, Call File and Write to Element script - AJAX
PostPosted: Sat Jan 10, 2009 3:26 pm 
Offline
500+ Club
User avatar

Joined: Wed Feb 27, 2008 6:14 am
Posts: 929
Location: Cebu City Philippines
Code Title: Show, Hide, Call File and Write to Element script

Author Name/notes : Raymond Angana aka rangana

Description : I was inspired by this post: post49170.html#p49170

This is a simple and very light script that show,hide (multiple) element(s), calls file and append to the element and writes text nodes to (multiple) element(s).

The script gives you the advantage to show/hide/write (multiple) element(s) at a time, by passing it as an argument to the available methods as explained below. It also gives you the flexibility to create text nodes from external file (via AJAX).

Code:
Code:
<script type="text/javascript">
/**
Title: Show, Hide, CallFile and Write to Element script
Author: Raymond Angana - [username = rangana in devppl.com/forum]
Created: 1/10/09
This notice must stay intact for legal use


Installation configuration:
hidelayer() - pass the id(s) of the layer you want to hide. Could work with multiple IDs

showlayer() - pass the id(s) of the layer you want to show. Could work with multiple IDs.

callFile() - first argument should be the URL of the file to call. The next argument is the ID of the layer you want the content of the file to show.

writetolayer() - first argument should be the text to write. The next argument(s) is the ID of the layer(s) you want the text be written. Could work with multiple IDs.
*/
var ray={
   hidelayer:function(){
      if(this.hidelayer.arguments.length>1){
         for(var i=0;i<this.hidelayer.arguments.length;i++)
            this.showHide(this.hidelayer.arguments[i],'none');
      }
      else this.showHide(this.hidelayer.arguments[0],'none');
   },
   
   showlayer:function(){
      if(this.showlayer.arguments.length>1){
         for(var i=0;i<this.showlayer.arguments.length;i++)
            this.showHide(this.showlayer.arguments[i],'');
      }
      else this.showHide(this.showlayer.arguments[0],'');
   },
   
   getID:function(el){
      return document.getElementById(el);
   },
   
   el:'',
   
   callFile:function(){
      this.el=this.el==''?this.callFile.arguments[1]:this.el;
      var xmlHttp;
      try{
         // Firefox, Opera 8.0+, Safari
         xmlHttp=new XMLHttpRequest();
      }
      catch (e){
         // Internet Explorer
         try{
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
         }
         catch (e){
            try{
               xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch (e){
               alert("Your browser does not support AJAX!");
               return false;
            }
         }
      }
            
      xmlHttp.onreadystatechange=function(){
         if(xmlHttp.readyState==4){
            ray.showlayer(ray.el);
            ray.getID(ray.el).innerHTML=xmlHttp.responseText;
         }
      }
                  
      xmlHttp.open("POST",this.callFile.arguments[0],true);
      xmlHttp.send(null);
   },
   
   writetolayer:function(){
      if(this.writetolayer.arguments.length>2){
         for(var i=1;i<this.writetolayer.arguments.length;i++){
            this.showlayer(this.writetolayer.arguments[i]);
            this.getID(this.writetolayer.arguments[i]).innerHTML=
this.writetolayer.arguments[0];
            }
      }
      else{
         this.showlayer(this.writetolayer.arguments[1]);
         this.getID(this.writetolayer.arguments[1]).innerHTML=
this.writetolayer.arguments[0];
      }
   },
   
   showHide:function(el,disp){
      this.getID(el).style.display=disp;
   }
}
</script>
<span id="newlayer" style="position:absolute;">layer-text</span>
<br><br><br>
<a href="#" onclick="ray.hidelayer('newlayer');return false;">hide layer</a> |
<a href="#" onclick="ray.showlayer('newlayer');return false;">show layer</a> |
<a href="#" onclick="ray.callFile('myfile.php','newlayer');return false;">layer-text #1</a> |
<a href="#" onclick="ray.writetolayer('layer-text #2','newlayer');return false;">layer-text #2</a>


Methods available on ray object are as follows:

hidelayer() - pass the id(s) of the layer you want to hide. Could work with multiple IDs.

showlayer() - pass the id(s) of the layer you want to show. Could work with multiple IDs.

callFile() - first argument should be the URL of the file to call. The next argument is the ID of the layer you want the content of the file to show.

writetolayer() - first argument should be the text to write. The next argument(s) is the ID of the layer(s) you want the text be written. Could work with multiple IDs.

Hope this helps.

_________________
~ Get me some work, I do freelancing ~


Top
 Profile  
 
 Post subject: Re: Show, Hide, Call File and Write to Element script - AJAX
PostPosted: Sat Jan 10, 2009 5:58 pm 
Offline
500+ Club
User avatar

Joined: Mon Jun 26, 2006 7:51 pm
Posts: 925
Any chance of a demo, I don't know what it does. :p


Top
 Profile  
 
 Post subject: Re: Show, Hide, Call File and Write to Element script - AJAX
PostPosted: Sun Jan 11, 2009 5:21 am 
Offline
500+ Club
User avatar

Joined: Wed Feb 27, 2008 6:14 am
Posts: 929
Location: Cebu City Philippines
Just copy and paste the code on your page and you'll know what it does.

If you're still having problem, please don't hesitate to let me know.

I'll show a demo.

_________________
~ Get me some work, I do freelancing ~


Top
 Profile  
 
 Post subject: Re: Show, Hide, Call File and Write to Element script - AJAX
PostPosted: Sun Jan 11, 2009 6:15 am 
Offline
500+ Club
User avatar

Joined: Mon Jun 26, 2006 7:51 pm
Posts: 925
Ooh, very nice. I guess you can use this for an entire navigation, call an entire pages content - so you have a website where the user never actually goes to a new page? Will probably use this for my portfolio. :)

Thanks


Top
 Profile  
 
 Post subject: Re: Show, Hide, Call File and Write to Element script - AJAX
PostPosted: Sun Jan 11, 2009 7:03 am 
Offline
500+ Club
User avatar

Joined: Wed Feb 27, 2008 6:14 am
Posts: 929
Location: Cebu City Philippines
No problem, just keep the notice intact.

_________________
~ Get me some work, I do freelancing ~


Top
 Profile  
 
 Post subject: Re: Show, Hide, Call File and Write to Element script - AJAX
PostPosted: Sat Feb 07, 2009 5:02 am 
Offline
500+ Club
User avatar

Joined: Mon Jun 26, 2006 7:51 pm
Posts: 925
Hey rangana, having a bit of trouble making this do what I want. What I want is that when a thumbnail image is clicked a larger image is displayed to the right along with some text below.

See what I'm trying to accomplish here: http://designprohibited.com/webdesign.php

The smaller image below the large image on the right I am using just to exemplify another layer right now so what I want is when the page loads only the large image on the right can be seen. When the user clicks the derby runners thumbnail to the left the smaller image shows instead of the large one.


Top
 Profile  
 
 Post subject: Re: Show, Hide, Call File and Write to Element script - AJAX
PostPosted: Sat Feb 07, 2009 5:25 am 
Offline
500+ Club
User avatar

Joined: Wed Feb 27, 2008 6:14 am
Posts: 929
Location: Cebu City Philippines
That's another script.

You should post a different thread highlighting your desire.

_________________
~ Get me some work, I do freelancing ~


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group - Flash Games - TNX Invitation Code - TNX Review


Webmaster - Excruciating - Johnathan - Kotik - Ash - Tomi - rangana - Phate - dflynn - Medley