Posts Tagged ‘JavaScript


CasperJS is an open source navigation scripting & testing utility based on PhantomJS, the scriptable headless WebKit engine. It eases the process of defining a full navigation scenario and provides useful high-level functions, methods & syntactic sugar for doing common tasks such as:

  • Defining & ordering navigation steps
  • Filling & submitting forms
  • Clicking links
  • Capturing screenshots of a page (or an area)
  • Making assertions on remote DOM
  • Logging events
  • Downloading base64 encoded resources, even binary ones
  • Writing functional test suites, saving results as JUnit XML

In the following example, we’ll query google for two terms consecutively, “capserjs” and “phantomjs”, aggregate the result links in a standard Array and output the result to the console.

Fire up your favorite editor and save the javascript code below in a googlelinks.js file:

In the following example, we’ll query google for two terms consecutively, “capserjs” and “phantomjs”, aggregate the result links in a standard Array and output the result to the console.

Fire up your favorite editor and save the javascript code below in a googlelinks.js file :

 

var links = [];
var casper = new phantom.Casper();
 
function getLinks() {
    var links = document.querySelectorAll('h3.r a');
    return Array.prototype.map.call(links, function(e) {
        return e.getAttribute('href')
    });
}
 
casper.start('http://google.fr/', function(self) {
    // search for 'casperjs' from google form
    self.fill('form[name=f]', { q: 'casperjs' }, true);
});
 
casper.then(function(self) {
    // aggregate results for the 'casperjs' search
    links = self.evaluate(getLinks);
    // now search for 'phantomjs' by fillin the form again
    self.fill('form[name=f]', { q: 'phantomjs' }, true);
});
 
casper.then(function(self) {
    // aggregate results for the 'phantomjs' search
    links = links.concat(self.evaluate(getLinks));
});
 
casper.run(function(self) {
    // echo results in some pretty fashion
    self.echo(links.length + ' links found:');
    self.echo(' - ' + links.join('\n - ')).exit();
});

@floriancargoet (whom i meet at @ParisJS) come with a nice idea : automating some elements screenshot in a WebApps/WebPages powered with #PhantomJS  (headless WebKit with JavaScript API). He’s idea is to generate multilingual documentation for a complexe application (Ext JS / Sencha).

 

In his example, the use of Ext.js give some constrain finding the element offset in the page…

 

/*
 * page.evaluate() is sandboxed
 * so that 'component' is not defined.
 *
 * It should be possible to pass variables in phantomjs 1.5
 * but for now, workaround!
 */
eval('function workaround(){ window.componentSelector = "' + component.selector + '";}')
page.evaluate(workaround);
 
var rect = page.evaluate(function(){
	// find the component
	var comp = Ext.ComponentQuery.query(window.componentSelector)[0];
	// get its bounding box
	var box = comp.el.getBox();
	// box is {x, y, width, height}
	// we want {top, left, width, height}
	box.top  = box.y;
	box.left = box.x;
	return box;
});
page.clipRect = rect;
page.render(component.output);

But with jQuery it could be as simple as this…

 

page.clipRect = $('ul#menu').offset();
page.render(component.output);

 

See the blog post for more infos

Il y a quelque temps, J’ai vu passer un plugin très intéressant nommé “Beeline“.
Son but et d’aider à lire plus rapidement en accompagnant l’oeil, grâce a un dégradé sur le texte qui évite de se perdre en fin de ligne.

Oui c’est mal de copier ! -mais je suis contre les brevets sur les logiciels- ;)

J’ai implémenté une première version (alpha !) avec mon ami jQuery.

Voici la démo en live sur JSfiddle. J’espère faire un test rapidement pour l’intégrer dans mon lecteur de livre

 

jQuery $.textGradient() ReadR V0.2 – remix by @molokoloco 2011

Save Time. Save Your Eyes. Read With BeeLine.
Original idea from http://beelinereader.com

 

 

Use “jQuery.xColor.js” plugin for funny colors !
http://www.xarg.org/project/jquery-color-plugin-xcolor/

 

Merci à @bobylito qui vient de mettre les vidéos (du live) en ligne sur Dailymotion.

On trouve entre autre ma présentation sur readr.js . Mais aussi plein de super autres sujets (http://www.dailymotion.com/ParisJS #ParisJS)

Ça fait drôle de se voir en vidéo, et ça fait drôle de parler devant beaucoup de gens avec plein de lumière dans les yeux :)

 

ReadR.JS by Julien Guézennec (@molokoloco) – ParisJS 13

“My Book ReadR” La présentation que j’ai faite hier soir à la conférence #ParisJS 13 (parisjs.org).

 

jQuery.ReadR.JS

[UPDATE : Projet en cours de refonte ici : https://github.com/molokoloco/jQuery.boxFx]

 

J’ai voulu tester ce que pouvais donner un émetteur de particule en DOM jQuery/CSS (Sans canvas)…

C’est un plugin léger et hyper-customisable, son principe et de (re)générer, X fois par secondes, un élément HTML, de lui appliquer des propriétés CSS3 (de départ), de l’insérer dans le DOM.

Le plugin applique quasi immédiatement les propriétés CSS de fin, et, au bout d’un certain temps, recycle l’élément : L’animation n’est pas faite avec jQuery $.animate() mais grâce aux propriétés CSS3 de transition, afin de bénéficier de l’accélération matériel (GPU)

 

 

 

En arrière plan, le plugin contient quelques méthodes qui permettent aux propriétés “cssFrom” et “cssTo” de supporter automatiquement l’ajout du “browser prefix” :

 

  • Fix and apply styles on element with correct browsers prefix
  • $(e).crossCss({borderRadius:’10px’}) >>> $(e).css({WebkitBorderRadius:’10px’})
  • Use Modernizer : https://github.com/Modernizr/Modernizr/blob/master/modernizr.js
  • Modernizr.prefixed(“borderRadius”); // e.g FF3.6 ‘MozBorderRadius’, FF4 ‘borderRadius’

 

$.fn.crossCss = function(css) {
	return this.each(function() {
		var $this = $(this);
		if (typeof css != 'object') return $this;
		for (var p in css)
			if (Modernizr.prefixed(p))
				css[Modernizr.prefixed(p)] = css[p];
		return $this.css(css);
	 });
};

 

Support cross-browser : Transition, borderRadius, borderImage, maskImage, Transform, boxShadow, etc

 

Le plugin écoute (bind) plusieurs événement via des méthodes publiques : start, stop, update, …
Exemple d’utilisation :

 

// Permet de mettre à jour, depuis n'importe quelle fonction, une ou des propriétés de l'émetteur
$emitter1.trigger('update', [{emitterRadius:16, rate:0}]);

Il envois (trigger) un évènement à chaque emission de particule (Cf. source) :

 

// Ecouter si un nouveau sprite à été émis
$emitter1.bind('emit', function(e, $sprite) { 
    $sprite.html('Ok'); // On modifie en live le contenu
});

 

Si la valeur “options.rate” est mise à Zéro, le plugin utilise la fonction “requestAnimationFrame()”, à la place de “setTimeout()”, afin de maximiser les performance.

 

Pour le moment il fait des bulles dans l’espace… mais on peu tout imaginer, des tweets, une cascade verticale, des images, beaucoup beaucoup de possibilités… de la synchro audio/vidéo,… Par exemple tapez une lettre entre les deux balises “<div></div>”
C’est pour cela que le code est ouvert sur Github ! :)

 

J’ai fais ce que j’ai pu pour chasser les bugs, mais il doit bien en rester ^^, vos commentaires sont les bienvenus…

PS : Cette ancienne démo est rigolote aussi :
http://jsfiddle.net/molokoloco/wRS8A/

We often see the “Promote JS” logo on the web, but for JavaScript, all the logos are branded, like with jQuery or Mozilla. Even if this both examples are cool foundation or team, there is no equivalent to the HTML5 logo, witch is agnostic (and as an universal identity).

 

Nerver know what’s the next needs for your app… now you got that too ;)
And i throw the idea in the air, if whom want to take the project to another level…

 

JS logo “Square” version

 


16×16


32×32


64×64


128×128


256×256

 

JS logo “Badge” version

 

 

Here you can download the ZIP with all ressources, images, PSD, SVG…

 

You can also take the project online

 

This JavaScript logo is licensed under Creative Commons Attribution 3.0

 

Shared by molokoloco

Excellente présentation de PhantomJS par @mauriz

Pour le dixième meetup ParisJS, j’ai présenté le projet PhantomJS. Pour résumer rapidement, PhantomJS est un navigateur Webkit sans interface graphique, qui se pilote en Javascript  (ou Coffeescript).

Voilà les diapos de ma présentation (la captation vidéo sera peut être disponible plus tard) :

ParisJS #10 : PhantomJs

 

View more presentations from Maurice Svay

 

Dans les choses que j’ai oublié de mentionner :

  • PhantomJS fonctionne sous Windows, Mac et Linux
  • il existe une version en Python, qui permet [...]

Shared by molokoloco

 

A fond dans l’idée que j’ai en ce moment… mais d’un autre chemin…

Face.

Face à l’explosion continue des savoirs disponibles. Face à la perméabilité chaque jour plus grande des champs scientifiques, à leur reconfiguration permanente et à la place toujours plus grande de l’interdisciplinarité et de la transdisciplinarité. Face à la crise de l’édition et aux rentes de situation de quelques monopolistiques éditeurs. Face à la babélisation des expertises et à la crise de l’autorité académique qu’elle met en exergue. 

Face au mouvement [...]

Fork me on GitHub

Blog code entry 
My feed on b2bweb.fr/coding-project/

Public Repositories
My code on GitHub/molokoloco

Personnal codingsheets
My wiki on “Molokoloco Coding Project

! New source code is now hosted on Github !

What you can find on my WIKI !

JS/php Class & Fonctions

PHP/js Class and Fonctions

Mixed LAMPX TIPS

Others Services Tips

 

And also my Virtual Admin PHP4/JS Prototype Framework, for managing CMS (2005~2008)

Julien Guézennec 2011 | molokoloco@gmail.com | http://www.b2bweb.fr …. Work definitely in progress…

 

16 pages

Home made artworks

MyBookReadR | The RSS Wall | Carousel slider | Fast web start | Try it :)
My latest sources and sheets :
Github sources | Personnal wiki | jsFiddle example | WebDev bookmark

RSS Molokoloco's JS fiddles

Recent Comments