Skip to content
This repository has been archived by the owner on Jun 21, 2019. It is now read-only.

Commit

Permalink
Fix request var declaration; build
Browse files Browse the repository at this point in the history
  • Loading branch information
pyrsmk committed Mar 31, 2012
1 parent ac3dbc7 commit b56b542
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 44 deletions.
2 changes: 1 addition & 1 deletion README.markdown
@@ -1,4 +1,4 @@
molt 2.4.2
molt 2.4.3
==========

The idea to develop molt comes from a few observations:
Expand Down
1 change: 0 additions & 1 deletion molt-2.4.0.W.min.js

This file was deleted.

1 change: 0 additions & 1 deletion molt-2.4.0.min.js

This file was deleted.

1 change: 1 addition & 0 deletions molt-2.4.3.W.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions molt-2.4.3.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions src/molt.js
@@ -1,7 +1,7 @@
/*
molt, image updater for responsive designs
Version : 2.4.2
Version : 2.4.3
Author : Aurélien Delogu (dev@dreamysource.fr)
Homepage : https://github.com/pyrsmk/molt
License : MIT
Expand All @@ -24,7 +24,7 @@
triggers=[],
listeners=[],
nodes=[],
i;
i,

/*
Refresh image nodes
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
@@ -1,7 +1,7 @@
{
"name" : "molt",
"description" : "Image updater for responsive designs",
"version" : "2.4.0",
"version" : "2.4.3",
"author" : "Aurélien Delogu <pyrsmk@dreamysource.fr> (http://dreamysource.fr)",
"repository" : {
"type" : "git",
Expand Down
73 changes: 35 additions & 38 deletions unit/ender.js
Expand Up @@ -119,10 +119,10 @@
/*
molt, image updater for responsive designs
Version: 2.4.0
Author: Aurélien Delogu (dev@dreamysource.fr)
Homepage: https://github.com/pyrsmk/molt
License: MIT
Version : 2.4.3
Author : Aurélien Delogu (dev@dreamysource.fr)
Homepage : https://github.com/pyrsmk/molt
License : MIT
*/

(function(def){
Expand All @@ -133,83 +133,77 @@
this.molt=def;
}
}(function(){

/*
Array nodes: molt images
*/
var getAttribute='getAttribute',
data='data-',
triggers=[],
listeners=[],
nodes=[],
i,

/*
Refresh image nodes
*/
refresh=function(){
var j,
k,
l,
url,
display,
node,
mode,
modes,
mapping,
width=W(),
stack;
width=W();
// Browse molt images
i=-1;
while(node=nodes[++i]){
// Guess the current mode for that image
modes=(url=node.getAttribute('data-url')).match(/\{\s*(.*?)\s*\}/)[1].split(/\s*,\s*/);
for(l=0;l<modes.length;l++){
mapping = modes[l].split(":");
if(mapping.length===1){
modes[l] = [mapping[0], mapping[0]];
}else{
modes[l] = [mapping[0], mapping[1]];
}
}
modes=(url=node.getAttribute(data+'url')).match(/\{\s*(.*?)\s*\}/)[1].split(/\s*,\s*/);
j=modes.length;
while(j){
if(width>modes[--j][0].match(/^!?(.+)/)[1]){
while(j--){
mode=modes[j].split(':');
if(mode.length==1){
mode[1]=mode[0];
}
if(width>mode[0].match(/^!?(.+)/)[1]){
break;
}
}
// Negative mode
if(modes[j][0].charAt(0)=='!'){
if(mode[0].charAt(0)=='!'){
// Hide image
node.style.display='none';
}
// Normal mode
else{
// Show image
if(node.style.display=='none'){
if(display=node.getAttribute('data-display')){
node.style.display=display;
if(k=node.getAttribute(data+'display')){
node.style.display=k;
}
else{
node.style.display='inline';
}
}
// Refresh src
node.src=url.replace(/\{.+\}/g,modes[j][1]);
node.src=url.replace(/\{.+\}/g,mode[1]);
// Call node listeners
k=triggers.length;
while(k){
if(triggers[--k]==node){
listeners[k].apply(node,[modes[j][1]]);
while(k--){
if(triggers[k]==node){
listeners[k].apply(node,[mode[1]]);
}
}
}
}
};

return {

/*
Add a listener to the stack
Object node : node to listen
Function callback : function to call when the node has been refreshed
*/
Expand All @@ -223,20 +217,23 @@
*/
discover:function(){
// Discover images
var imgs=document.getElementsByTagName('img'),
i=imgs.length;
while(i){
var img,
imgs=document.getElementsByTagName('img'),
discovered='discovered';
i=-1;
while(img=imgs[++i]){
// Only accept images with data-url attribute set
if(imgs[--i][getAttribute]('data-url')){
nodes.push(imgs[i]);
if(img[getAttribute](data+'url') && !img[getAttribute](data+discovered)){
img.setAttribute(data+discovered,discovered);
nodes.push(img);
}
}
// Update images
refresh();
// Catch events
W(refresh);
return nodes;
}

};

}()));
Expand Down

0 comments on commit b56b542

Please sign in to comment.