Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum. Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

SIMPLEJS : LIBRAIRIE AJAX COMBINÉE À DES EFFETS VISUELS.


Information sur la source

Catégorie :Effets Classé sous : ajax, simple, effets, opacité, prototype Niveau : Initié Date de création : 16/01/2007 Date de mise à jour : 21/01/2007 16:06:33 Vu : 9 520

Note :
7,4 / 10 - par 5 personnes
7,40 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (16)
Ajouter un commentaire et/ou une note

Description

Pour 10ko, vous avez une librairie de fonctions faciles pour afficher des pages via Ajax avec des effets visuels du genre de Script.aculo.us. Bien qu'en beta , aucuns bugs signalés, pourtant je suis certains qu'il y a moyen d'améliorer le code, car le javascript n'est pas ma spécialité. Le formatage (pres d'un tier du poids!) a été volontairement supprimmé, en fait elle est compressée. J'assayerai de retrouver mon code formaté si nécessaire.

J'ai créer cette librairie afin de pouvoir utiliser rapidement mes fonctions préférées de Scipt.aculo.us, sans devoir charger les plus de 100 ko nécéssaires.

Néamoins, c'est pas du tout basé sur prototype. Par contre, elle reprend le code de Sack qui me semble parfait.

N'hésitez pas à faire des commentaires constructifs car j'ai l'intention de continuer ce projet d'ici 2-3 mois. J'attendais que l'on me signale des bugs, mais au lieu de ça, on me demande sans cesse de l'aide pour des raisons ridicules (marche pas en HTML 4.0, Ajax sans serveur,...).

vous pouvez vous rendre sur cette page: http://simplejs.bleebot.com/ pour la voir en action, optenir les infos sur l'utilisation et télécharger le script avec ces plug-ins

  


 

Source

  • /*
  • SimpleJS ver 0.02 beta
  • ----------------------
  • SimpleJS is developed by Christophe "Dyo" Lefevre (http://bleebot.com/)
  • $ajax function is based on Simple AJAX Code-Kit (SACK)
  • Gregory Wild-Smith (http://www.twilightuniverse.com/)
  • */
  • var enableCache = true;
  • var jsCache = new Array();
  • var DynObj = new Array();
  • function $ajax(file) {
  • this.xmlhttp = null;
  • this.resetData = function() {
  • this.method = "POST";
  • this.queryStringSeparator = "?";
  • this.argumentSeparator = "&";
  • this.URLString = "";
  • this.encodeURIString = true;
  • this.execute = false;
  • this.element = null;
  • this.elementObj = null;
  • this.requestFile = file;
  • this.vars = new Object();
  • this.responseStatus = new Array(2);
  • }
  • ;
  • this.resetFunctions = function() {
  • this.onLoading = function() {
  • }
  • ;
  • this.onLoaded = function() {
  • }
  • ;
  • this.onInteractive = function() {
  • }
  • ;
  • this.onCompletion = function() {
  • }
  • ;
  • this.onError = function() {
  • }
  • ;
  • this.onFail = function() {
  • }
  • ;
  • }
  • ;
  • this.reset = function() {
  • this.resetFunctions();
  • this.resetData();
  • }
  • ;
  • this.crAjx = function() {
  • try {
  • this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
  • }
  • catch (e1) {
  • try {
  • this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  • }
  • catch (e2) {
  • this.xmlhttp = null;
  • }
  • }
  • if (! this.xmlhttp) {
  • if (typeof XMLHttpRequest != "undefined") {
  • this.xmlhttp = new XMLHttpRequest();
  • }
  • else {
  • this.failed = true;
  • }
  • }
  • }
  • ;
  • this.setVar = function(name, value) {
  • this.vars[name] = Array(value, false);
  • }
  • ;
  • this.encVar = function(name, value, returnvars) {
  • if (true == returnvars) {
  • return Array(encodeURIComponent(name), encodeURIComponent(value));
  • }
  • else {
  • this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
  • }
  • }
  • this.processURLString = function(string, encode) {
  • encoded = encodeURIComponent(this.argumentSeparator);
  • regexp = new RegExp(this.argumentSeparator + "|" + encoded);
  • varArray = string.split(regexp);
  • for (i = 0; i < varArray.length; i++) {
  • urlVars = varArray[i].split("=");
  • if (true == encode) {
  • this.encVar(urlVars[0], urlVars[1]);
  • }
  • else {
  • this.setVar(urlVars[0], urlVars[1]);
  • }
  • }
  • }
  • this.createURLString = function(urlstring) {
  • if (this.encodeURIString && this.URLString.length) {
  • this.processURLString(this.URLString, true);
  • }
  • if (urlstring) {
  • if (this.URLString.length) {
  • this.URLString += this.argumentSeparator + urlstring;
  • }
  • else {
  • this.URLString = urlstring;
  • }
  • }
  • // prevents caching of URLString
  • this.setVar("rndval", new Date().getTime());
  • urlstringtemp = new Array();
  • for (key in this.vars) {
  • if (false == this.vars[key][1] && true == this.encodeURIString) {
  • encoded = this.encVar(key, this.vars[key][0], true);
  • delete this.vars[key];
  • this.vars[encoded[0]] = Array(encoded[1], true);
  • key = encoded[0];
  • }
  • urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
  • }
  • if (urlstring) {
  • this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
  • }
  • else {
  • this.URLString += urlstringtemp.join(this.argumentSeparator);
  • }
  • }
  • this.runResponse = function() {
  • eval(this.response);
  • }
  • this.runAJAX = function(urlstring) {
  • if (this.failed) {
  • this.onFail();
  • }
  • else {
  • this.createURLString(urlstring);
  • if (this.element) {
  • this.elementObj = $(this.element);
  • }
  • if (this.xmlhttp) {
  • var self = this;
  • if (this.method == "GET") {
  • totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
  • this.xmlhttp.open(this.method, totalurlstring, true);
  • }
  • else {
  • this.xmlhttp.open(this.method, this.requestFile, true);
  • try {
  • this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") }
  • catch (e) {
  • }
  • }
  • this.xmlhttp.onreadystatechange = function() {
  • switch (self.xmlhttp.readyState) {
  • case 1 : self.onLoading();
  • break;
  • case 2 : self.onLoaded();
  • break;
  • case 3 : self.onInteractive();
  • break;
  • case 4 : self.response = self.xmlhttp.responseText;
  • self.responseXML = self.xmlhttp.responseXML;
  • self.responseStatus[0] = self.xmlhttp.status;
  • self.responseStatus[1] = self.xmlhttp.statusText;
  • if (self.execute) {
  • self.runResponse();
  • }
  • if (self.elementObj) {
  • elemNodeName = self.elementObj.nodeName;
  • elemNodeName.toLowerCase();
  • if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea") {
  • self.elementObj.value = self.response;
  • }
  • else {
  • self.elementObj.innerHTML = self.response;
  • }
  • }
  • if (self.responseStatus[0] == "200") {
  • self.onCompletion();
  • }
  • else {
  • self.onError();
  • }
  • self.URLString = "";
  • break;
  • }
  • }
  • ;
  • this.xmlhttp.send(this.URLString);
  • }
  • }
  • }
  • ;
  • this.reset();
  • this.crAjx();
  • }
  • function ajax_installScript(script) {
  • if (!script) return;
  • if (window.execScript) {
  • window.execScript(script);
  • }
  • else if(window.jQuery && jQuery.browser.safari) {
  • STO(script, 0);
  • }
  • else {
  • STO( script, 0 );
  • }
  • }
  • function $ajax_show(divId, Aorj, url, loader, effect) {
  • if (effect == 'appear') $opacity(divId, 0, 101, 600);
  • if (effect == 'highlight') $highlight(divId);
  • var targetObj = $(divId);
  • targetObj.innerHTML = DynObj[Aorj].response;
  • if (effect == 'blind') {
  • $(divId).style.position = '';
  • $blinddown(divId);
  • }
  • if(enableCache) {
  • jsCache[url] = DynObj[Aorj].response;
  • }
  • DynObj[Aorj] = false;
  • ajax_parseJs(targetObj) }
  • function $ajaxreplace(divId, url) {
  • $opacity(divId, 100, 0, 400);
  • $(divId).style.height = '';
  • scr = "$ajaxload('" + divId + "','" + url + "',false,'appear',false)";
  • STO(scr, 400);
  • }
  • function $ajaxload(divId, url, loader, effect, ecache) {
  • if (effect == 'appear') changeOpac(0, divId);
  • if (effect == 'blind') {
  • var ids = $(divId).style;
  • ids.overflow = 'hidden';
  • ids.display = 'block';
  • ids.height = '0px';
  • }
  • if (ecache) {
  • if(enableCache && jsCache[url]) {
  • if (effect == 'appear') $opacity(divId, 0, 101, 600);
  • if (effect == 'highlight') $highlight(divId);
  • $(divId).innerHTML = jsCache[url];
  • if (effect == 'blind') {
  • $(divId).style.position = '';
  • $blinddown(divId);
  • }
  • return;
  • }
  • }
  • var Aorj = DynObj.length;
  • if (loader != false) $(divId).innerHTML = loader;
  • DynObj[Aorj] = new $ajax();
  • DynObj[Aorj].requestFile = url;
  • DynObj[Aorj].onCompletion = function() {
  • $ajax_show(divId, Aorj, url, loader, effect);
  • }
  • ;
  • DynObj[Aorj].runAJAX();
  • }
  • function ajax_parseJs(obj) {
  • var scriptTags = obj.getElementsByTagName('SCRIPT');
  • var string = '';
  • var jsCode = '';
  • for(var no = 0; no < scriptTags.length; no++) {
  • if(scriptTags[no].src) {
  • var head = document.getElementsByTagName("head")[0];
  • var scriptObj = document.createElement("script");
  • scriptObj.setAttribute("type", "text/javascript");
  • scriptObj.setAttribute("src", scriptTags[no].src);
  • }
  • else {
  • if(DHTMLSuite.clientInfoObj.isOpera) {
  • jsCode = jsCode + scriptTags[no].text + '\n';
  • }
  • else jsCode = jsCode + scriptTags[no].innerHTML;
  • }
  • }
  • if(jsCode)ajax_installScript(jsCode);
  • }
  • //generic fonctions
  • function $(id) {
  • return document.getElementById(id);
  • }
  • function STO(func,time) {
  • return window.setTimeout(func,time);
  • }
  • function DecToHexa(DecNb) {
  • var digits = parseInt(DecNb).toString(16);
  • if (DecNb < 16) digits = '0' + digits;
  • return digits;
  • }
  • function addslashes(str) {
  • str = str.replace(/\"/g,"\\\"");
  • str = str.replace(/\'/g,"\\\'");
  • return str;
  • }
  • //blinds effects
  • function $toggle(id) {
  • if (act_height(id) == 0) $blinddown(id);
  • else $blindup(id);
  • }
  • function act_height(id) {
  • height = $(id).clientHeight;
  • if(height == 0) height = $(id).offsetHeight;
  • return height;
  • }
  • function act_width(id) {
  • width = $(id).clientWidth;
  • if(width == 0) width = $(id).offsetWidth;
  • return width;
  • }
  • function max_height(id) {
  • var ids = $(id).style;
  • ids.overflow = 'hidden';
  • if (act_height(id)!=0) return act_height(id);
  • else
  • {
  • origdisp = ids.display;
  • origheight = ids.height;
  • origpos = ids.position;
  • origvis = ids.visibility;
  • ids.visibility = 'hidden';
  • ids.height = '';
  • ids.display = 'block';
  • ids.position = 'absolute';
  • height = act_height(id);
  • ids.display = origdisp;
  • ids.height = origheight;
  • ids.position = origpos;
  • ids.visibility = origvis;
  • return height;
  • }
  • }
  • function $blindup(id, time) {
  • if (!time)time = 200;
  • acth = act_height(id);
  • maxh = max_height(id);
  • if (acth == maxh) {
  • $(id).style.display = 'block';
  • var steps;
  • steps = Math.ceil(time / acth);
  • for(i = 0; i <= acth; i++) {
  • newh = acth - i;
  • STO("$('" + id + "').style.height='" + newh + "px'", steps * i);
  • }
  • }
  • }
  • function $blinddown(id, time) {
  • if (!time)time = 200;
  • acth = act_height(id);
  • if (acth == 0) {
  • maxh = max_height(id);
  • $(id).style.display = 'block';
  • $(id).style.height = '0px';
  • var steps;
  • steps = Math.ceil(time / maxh);
  • for(i = 1; i <= maxh; i++) {
  • STO("$('" + id + "').style.height='" + i + "px'", steps * i);
  • }
  • }
  • }
  • //$opacity effects
  • function $opacity(id, opacStart, opacEnd, time) {
  • if($(id).style.width==0) $(id).style.width=act_width(id);
  • var speed = Math.round(time / 100);
  • var timer = 0;
  • if(opacStart > opacEnd) {
  • for(i = opacStart; i >= opacEnd; i--) {
  • STO("changeOpac(" + i + ",'" + id + "')", (timer * speed));
  • timer++;
  • }
  • }
  • else if(opacStart < opacEnd) {
  • for(i = opacStart; i <= opacEnd; i++) {
  • STO("changeOpac(" + i + ",'" + id + "')", (timer * speed));
  • timer++;
  • }
  • }
  • }
  • function changeOpac(opacity, id) {
  • var ids = $(id).style;
  • ids.opacity = (opacity / 100);
  • ids.MozOpacity = (opacity / 100);
  • ids.KhtmlOpacity = (opacity / 100);
  • ids.filter = "alpha(opacity=" + opacity + ")";
  • }
  • function $shiftOpacity(id, time) {
  • if($(id).style.opacity < 0.50) {
  • $opacity(id, 0, 100, time);
  • }
  • else {
  • $opacity(id, 100, 0, time);
  • }
  • }
  • function currentOpac(id, opacEnd, time) {
  • var currentOpac = 100;
  • if($(id).style.opacity < 100) {
  • currentOpac = $(id).style.opacity * 100;
  • }
  • $opacity(id, currentOpac, opacEnd, time)}
  • //$colorize effects
  • function $highlight(id, time, ncol, hcol) {
  • if(time) milli = time;
  • else milli = 900;
  • if(ncol) endcol = ncol;
  • else endcol = '#FFFFFF';
  • if(hcol) origcol = hcol;
  • else origcol = '#FFFFA6';
  • $colorize(origcol, endcol, id, milli, 'high');
  • }
  • function $textColor(id, startcol, endcol, time) {
  • if(time) milli = time;
  • else milli = 900;
  • $colorize(startcol, endcol, id, milli, 'text');
  • }
  • function $morphColor(id, starttextcol, endtextcol, startbackcol, endbackcol, startbordercol, endbordercol, time) {
  • if(time) milli = time;
  • else milli = 900;
  • $colorize(starttextcol, endtextcol, id, milli, 'text');
  • $colorize(startbackcol, endbackcol, id, milli, 'back');
  • if (startbordercol != false) $colorize(startbordercol, endbordercol, id, milli, 'border');
  • }
  • function $colorize(start, end, id, time, elem) {
  • dr = parseInt(start.substring(1, 3), 16);
  • dg = parseInt(start.substring(3, 5), 16);
  • db = parseInt(start.substring(5, 7), 16);
  • fr = parseInt(end.substring(1, 3), 16);
  • fg = parseInt(end.substring(3, 5), 16);
  • fb = parseInt(end.substring(5, 7), 16);
  • steps = time / 10;
  • cr = dr;
  • cg = dg;
  • cb = db;
  • sr = (fr - dr) / steps;
  • sg = (fg - dg) / steps;
  • sb = (fb - db) / steps;
  • var zzi = 10;
  • for (var x = 0; x < steps; x++) {
  • color = '#' + DecToHexa(cr) + DecToHexa(cg) + DecToHexa(cb);
  • if (x==(steps-1)) {
  • if (elem == "high") color='';
  • else color=end;
  • }
  • mytime = (x);
  • if (elem == "back" || elem == "high")
  • newfonc = '$("' + id + '").style.backgroundColor="' + color + '";';
  • else if (elem == "text")
  • newfonc = '$("' + id + '").style.color="' + color + '";';
  • else if (elem == "border")
  • newfonc = '$("' + id + '").style.borderColor="' + color + '";';
  • STO(newfonc, zzi);
  • cr += sr;
  • cg += sg;
  • cb += sb;
  • zzi += 10;
  • }
  • }
/*
SimpleJS ver 0.02 beta
----------------------
SimpleJS is developed by Christophe "Dyo" Lefevre (http://bleebot.com/)

$ajax function is based on Simple AJAX Code-Kit (SACK)
Gregory Wild-Smith (http://www.twilightuniverse.com/)
*/
var enableCache = true;
var jsCache = new Array();
var DynObj = new Array();
function $ajax(file) {
   this.xmlhttp = null;
   this.resetData = function() {
      this.method = "POST";
      this.queryStringSeparator = "?";
      this.argumentSeparator = "&";
      this.URLString = "";
      this.encodeURIString = true;
      this.execute = false;
      this.element = null;
      this.elementObj = null;
      this.requestFile = file;
      this.vars = new Object();
      this.responseStatus = new Array(2);
      }
   ;
   this.resetFunctions = function() {
      this.onLoading = function() {
         }
      ;
      this.onLoaded = function() {
         }
      ;
      this.onInteractive = function() {
         }
      ;
      this.onCompletion = function() {
         }
      ;
      this.onError = function() {
         }
      ;
      this.onFail = function() {
         }
      ;
      }
   ;
   this.reset = function() {
      this.resetFunctions();
      this.resetData();
      }
   ;
   this.crAjx = function() {
      try {
         this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
         }
      catch (e1) {
         try {
            this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
         catch (e2) {
            this.xmlhttp = null;
            }
         }
      if (! this.xmlhttp) {
         if (typeof XMLHttpRequest != "undefined") {
            this.xmlhttp = new XMLHttpRequest();
            }
         else {
            this.failed = true;
            }
         }
      }
   ;
   this.setVar = function(name, value) {
      this.vars[name] = Array(value, false);
      }
   ;
   this.encVar = function(name, value, returnvars) {
      if (true == returnvars) {
         return Array(encodeURIComponent(name), encodeURIComponent(value));
         }
      else {
         this.vars[encodeURIComponent(name)] = Array(encodeURIComponent(value), true);
         }
      }
   this.processURLString = function(string, encode) {
      encoded = encodeURIComponent(this.argumentSeparator);
      regexp = new RegExp(this.argumentSeparator + "|" + encoded);
      varArray = string.split(regexp);
      for (i = 0; i < varArray.length; i++) {
         urlVars = varArray[i].split("=");
         if (true == encode) {
            this.encVar(urlVars[0], urlVars[1]);
            }
         else {
            this.setVar(urlVars[0], urlVars[1]);
            }
         }
      }
   this.createURLString = function(urlstring) {
      if (this.encodeURIString && this.URLString.length) {
         this.processURLString(this.URLString, true);
         }
      if (urlstring) {
         if (this.URLString.length) {
            this.URLString += this.argumentSeparator + urlstring;
            }
         else {
            this.URLString = urlstring;
            }
         }
      // prevents caching of URLString
      this.setVar("rndval", new Date().getTime());
      urlstringtemp = new Array();
      for (key in this.vars) {
         if (false == this.vars[key][1] && true == this.encodeURIString) {
            encoded = this.encVar(key, this.vars[key][0], true);
            delete this.vars[key];
            this.vars[encoded[0]] = Array(encoded[1], true);
            key = encoded[0];
            }
         urlstringtemp[urlstringtemp.length] = key + "=" + this.vars[key][0];
         }
      if (urlstring) {
         this.URLString += this.argumentSeparator + urlstringtemp.join(this.argumentSeparator);
         }
      else {
         this.URLString += urlstringtemp.join(this.argumentSeparator);
         }
      }
   this.runResponse = function() {
      eval(this.response);
      }
   this.runAJAX = function(urlstring) {
      if (this.failed) {
         this.onFail();
         }
      else {
         this.createURLString(urlstring);
         if (this.element) {
            this.elementObj = $(this.element);
            }
         if (this.xmlhttp) {
            var self = this;
            if (this.method == "GET") {
               totalurlstring = this.requestFile + this.queryStringSeparator + this.URLString;
               this.xmlhttp.open(this.method, totalurlstring, true);
               }
            else {
               this.xmlhttp.open(this.method, this.requestFile, true);
               try {
                  this.xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded") }
               catch (e) {
                  }
               }
            this.xmlhttp.onreadystatechange = function() {
               switch (self.xmlhttp.readyState) {
                  case 1 : self.onLoading();
                  break;
                  case 2 : self.onLoaded();
                  break;
                  case 3 : self.onInteractive();
                  break;
                  case 4 : self.response = self.xmlhttp.responseText;
                  self.responseXML = self.xmlhttp.responseXML;
                  self.responseStatus[0] = self.xmlhttp.status;
                  self.responseStatus[1] = self.xmlhttp.statusText;
                  if (self.execute) {
                     self.runResponse();
                     }
                  if (self.elementObj) {
                     elemNodeName = self.elementObj.nodeName;
                     elemNodeName.toLowerCase();
                     if (elemNodeName == "input" || elemNodeName == "select" || elemNodeName == "option" || elemNodeName == "textarea") {
                        self.elementObj.value = self.response;
                        }
                     else {
                        self.elementObj.innerHTML = self.response;
                        }
                     }
                  if (self.responseStatus[0] == "200") {
                     self.onCompletion();
                     }
                  else {
                     self.onError();
                     }
                  self.URLString = "";
                  break;
                  }
               }
            ;
            this.xmlhttp.send(this.URLString);
            }
         }
      }
   ;
   this.reset();
   this.crAjx();
   }
function ajax_installScript(script) {
   if (!script) return;
   if (window.execScript) {
      window.execScript(script);
      }
   else if(window.jQuery && jQuery.browser.safari) {
      STO(script, 0);
      }
   else {
      STO( script, 0 );
      }
   }
function $ajax_show(divId, Aorj, url, loader, effect) {
   if (effect == 'appear') $opacity(divId, 0, 101, 600);
   if (effect == 'highlight') $highlight(divId);
   var targetObj = $(divId);
   targetObj.innerHTML = DynObj[Aorj].response;
   if (effect == 'blind') {
   $(divId).style.position = '';
   $blinddown(divId);
   }
   if(enableCache) {
      jsCache[url] = DynObj[Aorj].response;
      }
   DynObj[Aorj] = false;
   ajax_parseJs(targetObj) }
function $ajaxreplace(divId, url) {
   $opacity(divId, 100, 0, 400);
   $(divId).style.height = '';
   scr = "$ajaxload('" + divId + "','" + url + "',false,'appear',false)";
   STO(scr, 400);
   }
function $ajaxload(divId, url, loader, effect, ecache) {
   if (effect == 'appear') changeOpac(0, divId);
   if (effect == 'blind') {
	  var ids = $(divId).style;
      ids.overflow = 'hidden';
      ids.display = 'block';
      ids.height = '0px';
      }
   if (ecache) {
      if(enableCache && jsCache[url]) {
		 if (effect == 'appear') $opacity(divId, 0, 101, 600);
   		 if (effect == 'highlight') $highlight(divId);
         $(divId).innerHTML = jsCache[url];
		 if (effect == 'blind') {
   		 $(divId).style.position = '';
   		 $blinddown(divId);
   		 }
	     return;
         }
      }
   var Aorj = DynObj.length;
   if (loader != false) $(divId).innerHTML = loader;
   DynObj[Aorj] = new $ajax();
   DynObj[Aorj].requestFile = url;
   DynObj[Aorj].onCompletion = function() {
      $ajax_show(divId, Aorj, url, loader, effect);
      }
   ;
   DynObj[Aorj].runAJAX();
   }
function ajax_parseJs(obj) {
   var scriptTags = obj.getElementsByTagName('SCRIPT');
   var string = '';
   var jsCode = '';
   for(var no = 0; no < scriptTags.length; no++) {
      if(scriptTags[no].src) {
         var head = document.getElementsByTagName("head")[0];
         var scriptObj = document.createElement("script");
         scriptObj.setAttribute("type", "text/javascript");
         scriptObj.setAttribute("src", scriptTags[no].src);
         }
      else {
         if(DHTMLSuite.clientInfoObj.isOpera) {
            jsCode = jsCode + scriptTags[no].text + '\n';
            }
         else jsCode = jsCode + scriptTags[no].innerHTML;
         }
      }
   if(jsCode)ajax_installScript(jsCode);
   }
//generic fonctions
function $(id) {
        return document.getElementById(id);
        }
function STO(func,time) {
	return window.setTimeout(func,time);
	} 
function DecToHexa(DecNb) {
   var digits = parseInt(DecNb).toString(16);
    if (DecNb < 16) digits = '0' + digits;
   return digits; 
   } 
function addslashes(str) {
   str = str.replace(/\"/g,"\\\"");
   str = str.replace(/\'/g,"\\\'");
   return str;
   }
//blinds effects
function $toggle(id) {
   if (act_height(id) == 0) $blinddown(id);
   else $blindup(id);
   }
function act_height(id) {
   height = $(id).clientHeight;
   if(height == 0) height = $(id).offsetHeight;
   return height;
   }
function act_width(id) {
   width = $(id).clientWidth;
   if(width == 0) width = $(id).offsetWidth;
   return width;
   }
function max_height(id) {
   var ids = $(id).style;
   ids.overflow = 'hidden';
   if (act_height(id)!=0) return act_height(id);
   else
   {
   origdisp = ids.display;
   origheight = ids.height;
   origpos = ids.position;
   origvis = ids.visibility;
   ids.visibility = 'hidden';
   ids.height = '';
   ids.display = 'block';
   ids.position = 'absolute';
   height = act_height(id);
   ids.display = origdisp;
   ids.height = origheight;
   ids.position = origpos;
   ids.visibility = origvis;
   return height;
   }
   }
function $blindup(id, time) {
   if (!time)time = 200;
   acth = act_height(id);
   maxh = max_height(id);
   if (acth == maxh) {
      $(id).style.display = 'block';
      var steps;
      steps = Math.ceil(time / acth);
      for(i = 0; i <= acth; i++) {
         newh = acth - i;
         STO("$('" + id + "').style.height='" + newh + "px'", steps * i);
         }
      }
   }
function $blinddown(id, time) {
   if (!time)time = 200;
   acth = act_height(id);
   if (acth == 0) {
      maxh = max_height(id);
      $(id).style.display = 'block';
      $(id).style.height = '0px';
      var steps;
      steps = Math.ceil(time / maxh);
      for(i = 1; i <= maxh; i++) {
         STO("$('" + id + "').style.height='" + i + "px'", steps * i);
         }
      }
   }
//$opacity effects
function $opacity(id, opacStart, opacEnd, time) {
   if($(id).style.width==0) $(id).style.width=act_width(id);
   var speed = Math.round(time / 100);
   var timer = 0;
   if(opacStart > opacEnd) {
      for(i = opacStart; i >= opacEnd; i--) {
         STO("changeOpac(" + i + ",'" + id + "')", (timer * speed));
         timer++;
         }
      }
   else if(opacStart < opacEnd) {
      for(i = opacStart; i <= opacEnd; i++) {
         STO("changeOpac(" + i + ",'" + id + "')", (timer * speed));
         timer++;
         }
      }
   }
function changeOpac(opacity, id) {
   var ids = $(id).style;
   ids.opacity = (opacity / 100);
   ids.MozOpacity = (opacity / 100);
   ids.KhtmlOpacity = (opacity / 100);
   ids.filter = "alpha(opacity=" + opacity + ")";
   }
function $shiftOpacity(id, time) {
   if($(id).style.opacity < 0.50) {
      $opacity(id, 0, 100, time);
      }
   else {
      $opacity(id, 100, 0, time);
      }
   }
function currentOpac(id, opacEnd, time) {
   var currentOpac = 100;
   if($(id).style.opacity < 100) {
      currentOpac = $(id).style.opacity * 100;
      }
   $opacity(id, currentOpac, opacEnd, time)}
//$colorize effects
function $highlight(id, time, ncol, hcol) {
   if(time) milli = time;
   else milli = 900;
   if(ncol) endcol = ncol;
   else endcol = '#FFFFFF';
   if(hcol) origcol = hcol;
   else origcol = '#FFFFA6';
   $colorize(origcol, endcol, id, milli, 'high');
   }
function $textColor(id, startcol, endcol, time) {
   if(time) milli = time;
   else milli = 900;
   $colorize(startcol, endcol, id, milli, 'text');
   }
function $morphColor(id, starttextcol, endtextcol, startbackcol, endbackcol, startbordercol, endbordercol, time) {
   if(time) milli = time;
   else milli = 900;
   $colorize(starttextcol, endtextcol, id, milli, 'text');
   $colorize(startbackcol, endbackcol, id, milli, 'back');
   if (startbordercol != false) $colorize(startbordercol, endbordercol, id, milli, 'border');
   }
function $colorize(start, end, id, time, elem) {
   dr = parseInt(start.substring(1, 3), 16);
   dg = parseInt(start.substring(3, 5), 16);
   db = parseInt(start.substring(5, 7), 16);
   fr = parseInt(end.substring(1, 3), 16);
   fg = parseInt(end.substring(3, 5), 16);
   fb = parseInt(end.substring(5, 7), 16);
   steps = time / 10;
   cr = dr;
   cg = dg;
   cb = db;
   sr = (fr - dr) / steps;
   sg = (fg - dg) / steps;
   sb = (fb - db) / steps;
   var zzi = 10;
   for (var x = 0; x < steps; x++) {
      color = '#' + DecToHexa(cr) + DecToHexa(cg) + DecToHexa(cb);
	  if (x==(steps-1)) {
	  if (elem == "high") color='';
	  else color=end;
	  }
      mytime = (x);
      if (elem == "back" || elem == "high") 
	  newfonc = '$("' + id + '").style.backgroundColor="' + color + '";';
      else if (elem == "text") 
	  newfonc = '$("' + id + '").style.color="' + color + '";';
      else if (elem == "border") 
	  newfonc = '$("' + id + '").style.borderColor="' + color + '";';
      STO(newfonc, zzi);
      cr += sr;
      cg += sg;
      cb += sb;
      zzi += 10;
      }
   }

Conclusion

Ne me dite pas "elle n'est pas commentée", je sais, j'avais pas prévu de la placer ici. C'est d'ailleurs ma première source
 

Historique

16 janvier 2007 00:34:17 :
amusez vous
19 janvier 2007 20:26:23 :
j'ai remplacé par ma version non compressée (ou décryptée si vous voulez)
21 janvier 2007 16:06:34 :
remise en état de la function $(id)

Commentaires et avis

signaler à un administrateur
Commentaire de bultez le 17/01/2007 09:09:43

probablement utile ? mais déjà, comment s'en sert-on ?

signaler à un administrateur
Commentaire de info2c le 17/01/2007 16:08:58

Merci beaucoup, c'est vraiment génial skon peux faire avec 10 pauvres Ko !!!

BULTEZ : ne le dérange pas si tu n'a pas regardé avant sur le site indiqué :
"vous pouvez vous rendre sur cette page: http://simplejs.bleebot.com/ pour la voir en action, optenir les infos sur l'utilisation et télécharger le script avec ces plug-ins",
il est super bien fait et explique comment mettre en oeuvre ce type de script !

Encor merci

signaler à un administrateur
Commentaire de DyoChris le 17/01/2007 23:40:56

Au passage, je vous signal qu'il y a un formulaire de contact en cas de soucis, c'est vrai que j'ai pas hyper documenté.

Pour celui que ça intéresse, j'ai isolé ici les effets visuels:
http://simplejs.bleebot.com/simpleJSlight.zip

c'est donc SimpleJS sans ajax (5,3ko), le script n'est pas compressé.

signaler à un administrateur
Commentaire de ralecul le 18/01/2007 11:44:46

Moi je trouve ça vraiment super ! (10/10)

Je pense que je vais m'inspirer de $toggle(), $blindup() et $blinddown() pour ajouter
un système d'aide masquable à mon système de visite virtuelle (voir sur mon site perso)

Par contre je pense que le code devrait être remplacé par celui du fichier http://simplejs.bleebot.com/simpleJSlight.zip.
Je pense (j'espère) qu'au niveau de code source les sources brouillées sont interdites (car d'aucun intéret pédagogique).

En effet la version actuelle est très explicite n'est ce pas ? Exemple :
function STO(_24,_25){
return window.setTimeout(_24,_25);
}

Je pense donc qu'un fichier zip avec une version compressée (et pas brouillée avec un truc du style Javascript Obfuscator)
+ une version non compressée serait beaucoup mieux....

Sinon bravo pour le site : http://simplejs.bleebot.com !

Henri

signaler à un administrateur
Commentaire de DyoChris le 19/01/2007 20:29:55

Non c'est une méthode de compression simple.

function STO(_24,_25){
return window.setTimeout(_24,_25);
}

et

function STO(func,time) {
return window.setTimeout(func,time);
}

ne fait pas grande différence.

signaler à un administrateur
Commentaire de ralecul le 20/01/2007 12:35:03

Merci en tout cas d'avoir mis la version non compressée sur code source !

Sinon je ne suis pas du tout d'accord :

Il y a une grande différence entre :

function STO(_24,_25){
return window.setTimeout(_24,_25);
}

et

function STO(func,time) {
return window.setTimeout(func,time);
}

car si l'on ne connait pas les paramètres nécessaires à setTimeout il est bien plus compréhensible de voir setTimeout(func,time) que setTimeout(_24,_25) ! Je reconnais que le code produit est compressé, mais afin de gagner de la place il existe des méthodes plus performantes (suppression des espaces inutiles par ex). Cette méthode n'empèche pas de faire du reverse engineering. Alors que l'utilisation de variable nommé _24 sert clairement à empecher les autres de comprendre le fonctionnement du code ...

Henri

signaler à un administrateur
Commentaire de DyoChris le 21/01/2007 16:04:31

ok ok ;)

au sujet de cette ligne, il faut enlever les //
# //function $(id) {
# // return document.getElementById(id);
# //}

je viens juste de le voir.

(ps la suppression de la fonction $() rend simpleJS compatible avec d'autre librairie comme prototype)

signaler à un administrateur
Commentaire de malalam le 10/02/2007 12:27:02 administrateur CS

Hello,

je suis moyennement convaincu par ton code. Sans hostilité hein ;-) C'est juste que, finalement, tu as pris 2-3 éléments de prototype, 2-3 de scriptaculous, et une api ajax, pour faire ton bin's. Bref, ce code, c'est ce que TU utilises dans ces frameworks. Utiliser ces frameworks à la place a l'avantage de permettre plus de choses (prototype est particulièrement bien foutu et extrèmement utile!) que ton code, et ne limite pas les possibilités à ce dont TU as généralement besoin.
D'accord, ça fait que 10k, soit au bas mot 20 fois moins que prototype et scriptaculous réunis. Mais c'est aussi 20 fois moins puissant et permet largement moins de 20 fois moins de choses.
Et petit gros regret, l'aspect DOM a totalement disparu. Prototype permet justement de conserver cette norme, de l'appliquer, et par là d'être parfaitement portable (et accessible si on ne fait pas de bêtise avec).

Ceci dit...cette critique n'est pas virulente, parce que tu as le mérite d'avoir exploré, trié, et récupéré de ces excellents frameworks ce dont tu avais besoin uniquement, afin d'avoir ta propre version light. Pourquoi pas, donc.

Mais j'invite quand même les gens intéressés à jeter un oeil à prototype (et à scriptaculous, forcément plus spectaculaire et ludique, mais néanmoins très bien foutu). A voir aussi, windows js, basé sur ces 2 frameworks.

signaler à un administrateur
Commentaire de fidjay le 10/02/2007 14:36:13

Salut, je comprend pas j'ai un soucis sur la fonction toggle, sur Fire Fox marche super bien mais par contre sur Ie ma Div et apparente et pas moyen de la faire remonté, alors que sur le site de l'auteur sa marche niquel avec le meme code. Je pense que ca vien du css mais quoi

<a href="#"  onclick="$toggle('commentaire'); return false">Ajouter</a>
<div id="commentaire" style="overflow: hidden; display: block; width: 430px; height: 0px;>

Si quelqu'un a une idée ou a renconté le probleme.

signaler à un administrateur
Commentaire de malalam le 10/02/2007 19:19:24 administrateur CS

Il serait bien que celui qui a mis 1/10 commente sa note.
Ca m'étonne d'autant plus que généralement, il le fait, et ne note pas au hasard.
Merci par avance pour l'auteur :-)
Sans quoi, je supprimerai la note car je la trouve exagérée.

signaler à un administrateur
Commentaire de DyoChris le 27/02/2007 09:25:33

fidjay : tu trouveras des exemples maintenant en téléchargement.

voici ce que tu aurais du mettre en fait

<div id="commentaire" style="display:none; width:430px" ></div>

malalam: d'habitude je bosse avec prototype, mais je trouve ça exagéré quand il suffit de bêtement faire un formulaire de contact, par exemple.

Si tes clients te demande "un petit truc qu'ils ont trouvé sur un site, tu dois pouvoir les contenter sans alourdir leur page"  

cette librairie ne convient pas dans la plus parts des cas, bien sûr. Mais crois moi, elle a son utilité.

Sa simplicité, pour les débutants plais beaucoup par contre:

par exemple, un bouton pour charger une page php dans un Div

<input type="button" onclick="$ajaxload('mondiv','mapage.php','chargement','blind',false);return false" name="Button" value="test1" />  

c'est quand même plus simple que ce que propose prototype  

je reçois des remerciement presque tous les jours dans toutes les langues. Si tu fais une recherche sur "SimpleJS" dans google, tu verras que je ne mens pas.

Si j'ai déposé ce script ici, c'est principalement pour voir si certaines personnes voient des choses à modifier.

signaler à un administrateur
Commentaire de canniballette le 16/04/2007 15:48:04

Même erreur que  fidjay : le div remonte mais arrivé en haut il redescent tout de suite ... :/

<div  onclick="$toggle('commentaire'); return false">Ajouter</div>
<div id="commentaire" style="display:none;" ></div>

Quelqu'un aurait-il trouvé le problème ?

signaler à un administrateur
Commentaire de byld le 14/11/2007 18:19:25 10/10

Je trouve cela très bien fait!
Bien entendu je mets le max!
Par contre pourriez vous, m'expliquer comment je dois procéder pour le cas suivant. J'ai un formulaire avec deux boutons submit.
Il faut cliquer dans l'ordre pour valider le formulaire.
Dans le cas présent, les internautes sur mon site, valident le premier bouton et le formulaire se relève. Ils en oublient de vredplier pour valider le second bouton et du coup le formulaire n'est pas validé.
Pour résumé: Comment obligé le formulaire a rester en position basse tant que les deux boutons ne sont pas validés?

signaler à un administrateur
Commentaire de DonDiegoAA le 13/12/2007 12:34:51 7/10

Bonjour,

je fais mes premiers tests avec cette librairie, et avec Ajax tout court en fait, et pour un débutant en la matière, c'est vraiment simple d'utilisation, merci.
Petite question peut-être idiote mais bon:
J'ai fais quelques expériences avec AjaxLoad et AjaxReplace, et ça fonctionne bien tant que le nouveau contenu est dans le même espace que la page qui appelle. Y a t'il moyen de faire la même chose avec des pages sur un autre domaine? En gros, j'ai un bouton sur mon site qui mènera à un autre site, et je voudrais faire un effet de transition entre les 2 pages. Possible ?

Merci d'avance

signaler à un administrateur
Commentaire de DonDiegoAA le 13/12/2007 12:37:20

Pour être plus précis, quand je fais
<input onclick="$ajaxreplace('content','mapage2.htm',true);return false" name="Button" value="test1" type="button">, c'est nickel
mais si je fais
<input onclick="$ajaxreplace('content','http://www.google.com',true);return false" name="Button" value="test1" type="button">
ça marche pas.

Voilà :D

signaler à un administrateur
Commentaire de fidjay le 22/12/2007 16:44:11 9/10

Vraiment sympa cette librairie je l'utilise sur différente application et sa marche nikel.

J'aurais une colle si quelque a une idée, je chercher a utilisé l'effet toogle, mais qui remonterais automatiquement au bout de X secondes je pense que c'est largement possible avec simple-JS mais je trouve pas comment faire, si vous avez une idée ;-)

Bonnes fêtes a tous...

Ajouter un commentaire

Discussions en rapport avec ce code source dans le forum

javascript dans formulaire acrobat [ par domi ] "Envoie par mèl du contenu du formulaire"j'ai écrit deux lignes simple en javascript dans un formulaire acrobat, il fonctionne bien avec Acrobat "prog recherche aide [ par g2m ] nouveau dans la création de site, je bute sur une chose simple, créer un menu déroulant horizontale avec survol.Un truc simple quoi!Dans cette barre 8 différents effets sur les liens d'une meme page [ par geoffroy ] Salut, J'aimerais savoir comment fait on pour qu'un lien devienne plus gros au survolage de la souris . Mais j'aimerais que cet effet ne marche que su c'est simple comme bonjour mais je ne me raplle plus... [ par escaflone1 ] Bonjour,comme je le di je ne sais plus comment on fait pour actualiser une page mais juste une seul fois:la page charger puis 1 voir 2 sec apres hop i tout simple [ par pierre81 ] je débute et je voudrez savoir comment on fait pour dire que quand on clique sur la frame de gauche , je veux afficher un truc a droite merci de me do Formulaire tout simple [ par Angel42480 ] Bonjour, je travail en html,Je désirerais créer un formulaire, qui définisse une image.Exemple : on tape dans la case du formulaire : "arbre" . Je veu Supprimer menubar [ par meka ] Bonjour,Voilà, je m'enlise sur un truc simple depuis 4 jours !j' explique : j'aimerais faire disparaitre le menubar ( Menus : fichier-edition-affichag truc surement tres simple mais bon... [ par bipross ] Bonjour,Voici mon souci :....var nbJ = nb_jour(l,laDate); //retourne 24 par exempleif (nbJ &gt; 31){toto = 1;}else{toto = 2;}et j'obtiens l'erreur "ob Afficher une popup [ par BsEtZeOpLhD ] Bonjour.Je cherche un code pour afficher une simple popup à l'affichage d'une fenetre. Une popup affichant une page web (http://perso.wanadoo.fr/bsetz contenu d'un textarea dans des 'input text' [ par SauCisS ] Bonjour a tousMon problème est simple, peut-t-on me dire comment faire pour mettre le contenu d'une zone de texte (texarea) dans des zones de texte si


Nos sponsors

Sondage...

CalendriCode

Juillet 2009
LMMJVSD
  12345
6789101112
13141516171819
20212223242526
2728293031  

Consulter la suite du CalendriCode

Téléchargements

Logiciels à télécharger sur le même thème :

Comparez les prix Nouvelle version

Photothèque Nouveau !



Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés
Temps d'éxécution de la page : 0,983 sec

Google Coop CodeS-SourceS Google Coop CodeS-SourceS


Certaines images présentes sur le site (notament certains avatars) sont issues des collections IconShock, donc si vous souhaitez utiliser ces icons vous devez les acheter, ne les copiez pas et ne utilisez pas dans vos sites et applications sans les avoir commandé.