Execute js in html loaded page with sencha.

Update : scroll for part 2 !

Part 1 : evil eval trick

Ok. So I load html in a sencha panel like this :

Ext.Ajax.request({
  url:'mypage.html',
  success:function(response, options) {
    Ext.getCmp('myPanel').update(response.responseText, true);
  },
  failure:function(response, options) {
    // Redirect to success for status == 0 for local files
    if (response.responseText && response.status == 0) this.success(response, options);
  }
});

Oh dear. I don’t know another way to load a local file except redirecting to success if the response status is 0. Sorry about that.

Next trick is : how to execute some JS inside this loaded html page. Because it doesn’t work. At all.

You’ll hate me about this, but in my local html file :

function logize() {
  console.log('pouet');
}

This function is defined in a <script type=”text/javascript” id=”executeMe”>…</script> tag.

Then, in the success function, I added :

eval($('#executeMe').text());
logize();

Tricky trick is tricky ! I know eval is evil…

Any idea on how to do it nicely ?

Part 2 : nice way

Yep. The end of the eval reign has come.

I change a little bit of my html file :

(function() {
  function logize() {
    console.log('pouet');
  }
  logize();
})();

In my sencha success function :

var code = $('#executeMe').text();
var codefunc = new Function(code);
codefunc();

So :

  • No eval function
  • No need to rely on a global function called in sencha’s success function
  • Nice closure in the html ;)

That’s done !

imgzr.js : jQuery image selector based on screen width

Update: january 17, 2012 : now with REAL screen orientation detection and browser resize.
Update:
 january 13, 2012 : now with screen orientation detection.

how to use

Include :

$(function () {
 $('body').imgzr();
});

It will look into the given element (here “body”) for image and change the src if needed.

Check the demo : http://dev.federalbureauofinhumanity.org/imgzr/ (last version is v0.2)

It has been tested under :

  • Chrome 16
  • Firefox 9
  • IE9
  • Ipad
  • Iphone

configuration

Prepare your images ! Your image should have the small image in src to prevent bandwith overcharging. Add data- with the well sized image. Example :

img src="./img/small.jpg" alt=""
 data-small="./img/small.jpg"
 data-medium="./img/medium.jpg"
 data-large="./img/large.jpg"

(Sorry, I dropped the “<” & “/>” because of the pre tag)

The default configuration is the following :

resolutions:{
 small:{min:0, max:480},
 medium:{min:480, max:768},
 large:{min:768, max:10000}
}

You can change this passing a new configuration to the function call :

$(function () {
 var config = {
 resolutions:{
 small:{min:0, max:1000},
 medium:{min:1000, max:10000},
 large:{min:10000, max:100000}
 }
 };
 $('body').imgzr(config);
});

license

This script is licensed under the terms of the WTF Public License (see here and here) :

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                    Version 2, December 2004 

 Copyright (C) 2004 Sam Hocevar  

 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as long
 as the name is changed. 

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 

  0. You just DO WHAT THE FUCK YOU WANT TO.

Contact

You can contact me at siegfried.ehretATgmail.com (replace AT with @) Please write “imgzr” or something in your subject.

img2base64, a ruby image to base64 converter

Intro

An image to base64 conversion script in ruby.

Changelog

Last version is v0.1

  • v0.1 : initial version

Demo here.

How to use

You can run the script (with ruby / gems / sinatra installed) and point your browser to http://localhost:4567/<image_url>. Thou shalt see the result. You can curl the script.

Source

The github repository is here.

License

This script is licensed under the terms of the WTF Public License (see here and here) :

           DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                    Version 2, December 2004 

 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net> 

 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as
 long as the name is changed. 

 DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
 0. You just DO WHAT THE FUCK YOU WANT TO.

Duck Duck Go Zero Info search box

Update : january 17, 2012 : this plugin has been slightly modified. I had problems with reserved words… My mistake !

I always wanted to do a jQuery plugin. Now, it’s done !

It is available on GitHub.

Last version is v0.3 : try it here.

This is a jQuery plugin for Duck Duck Go Zero-click Info API.
For those who are not familiar with Duck Duck Go, it’s my new favorite search engine. Go try it !

It provides a box with some basic info (like… From wolfram alpha, wikipedia etc.).

I will make some tests to make it better (but I don’t like tests… Sorry) and add more parameters soon.
Stay tuned !

And don’t forget to use Duck Duck Go !