Category Archives: javascript

load css with javascript

Following javascript function loads css file if it’s not already loaded

javascript : scroll window or container to view element

prototypsjs framework is used for that.

– scroll container to view element inside : scrollTo(myElement, divContainer);
– scroll window to view element inside : scrollTo(myElement, null);

list html page elements not having id

Icefaces ajax render performances issues could be sequence of dom elements without id. The present post helps to list all elements not having id to be fixed.

Open your page in your browser.
In developer console create following function

then call chkid with any dom element. To get all, call chkid with body element

Nota : Here we use prototypejs framework

ajax displaying jboss server state

We aim to have web page which displays continually three jboss7 servers states.
For this we need the shell script (status.sh) to be found here.

environment requirement

    servers in same machine :
  • apache server
  • three jboss7 servers: jboss1, jboss2, jboss3

get result of status.sh in our php file

Following php code displays one jboss server state

For our example we need three php files containing the previous one line php code corresponding to each one of the three jboss server : state-jboss1.php, state-jboss2.php, and state-jboss3.php

ajax state display

We need here the load() method of jquery javascript framework.

continuous update of servers state

We’ll resort to javascript timer

deloyment

    root folder :
  • create folder jboss-state in apache server root www
    files :
  • www/jboss-state/status.sh
  • www/jboss-state/index.html
  • www/jboss-state/state-jboss1.php
  • www/jboss-state/state-jboss2.php
  • www/jboss-state/state-jboss3.php

full code

status.sh (myArtifactName string in code must be replaced by the right artifact name)

state-jboss1.php

state-jboss2.php

state-jboss3.php

index.html

Use colsure (javascript code analyser)

First of all you must have easy_install python module : cf. get-easyinstall-python-module

Install closure linter :

Downloading http://closure-linter.googlecode.com/files/closure_linter-latest.tar.gz
Processing closure_linter-latest.tar.gz
Writing /tmp/easy_install-Xt6LOk/closure_linter-2.3.11/setup.cfg
Running closure_linter-2.3.11/setup.py -q bdist_egg –dist-dir /tmp/easy_install-Xt6LOk/closure_linter-2.3.11/egg-dist-tmp-w7sS6l
zip_safe flag not set; analyzing archive contents…
Adding closure-linter 2.3.11 to easy-install.pth file
Installing fixjsstyle script to /usr/local/bin
Installing gjslint script to /usr/local/bin

Installed /usr/local/lib/python2.7/dist-packages/closure_linter-2.3.11-py2.7.egg
Processing dependencies for closure-linter==2.3.11
Searching for python-gflags
Reading https://pypi.python.org/simple/python-gflags/
Reading http://code.google.com/p/python-gflags
Best match: python-gflags 2.0
Downloading https://pypi.python.org/packages/source/p/python-gflags/python-gflags-2.0.tar.gz#md5=23c9a793959a54971b1f094b0c6d03b1
Processing python-gflags-2.0.tar.gz
Writing /tmp/easy_install-SlgYwJ/python-gflags-2.0/setup.cfg
Running python-gflags-2.0/setup.py -q bdist_egg –dist-dir /tmp/easy_install-SlgYwJ/python-gflags-2.0/egg-dist-tmp-kTyloa
zip_safe flag not set; analyzing archive contents…
Adding python-gflags 2.0 to easy-install.pth file

Installed /usr/local/lib/python2.7/dist-packages/python_gflags-2.0-py2.7.egg
Finished processing dependencies for closure-linter==2.3.11

Once finished you can use closure linter as following :

Analyse one js script file :

Analyse entire directory :

more details here : https://developers.google.com/closure/utilities/docs/linter_howto

JSFIDDLE

Utile pour les développeurs javascript. http://jsfiddle.net/ est une application Saas permettant :- d’éditer une application javascript et voir le résultat instantanément
– de choisir son framework js : Prototype, mootools, jquery … etc
– de lier des scripts externes
et plus d’autres fonctionnalités à découvrir

simple nodejs http server


================================================= 14/06/2013
simple nodejs http server:
– install nodejs
– create file server.js with following content:
var url = require(“url”);

function handleHttpRequest(request, response){
response.writeHead(200, {“Content-Type”: “text/html”});
response.write(“pathname:”+url.parse(request.url).pathname);
response.write(“
“);
response.write(“query:”+url.parse(request.url).query);
response.end();
}

var http = require(“http”);
http.createServer(handleHttpRequest).listen(8888);
– in command line: node /path/to/server.js
– go to http://localhost:8888
– go to http://localhost:8888/sevice?user=nour&age=42