-
23 Jul 2009 2:40 PM #1
Ext.ux.IconLoader
Ext.ux.IconLoader
this is hardly an extension, it's just a little helper utility I've been using to load icons (namely the famfamfam icons) in my pages.
I used to just include a huge (on the order of 100Kb) CSS file with rules for every single famfamfam icon but with this helper utility I don't have to do that anymore and I still get easy access to all the icons.
Example usage:
The css rules generated will be in the format: "icon-" + filename (without extension and _ replaced with -). For example:PHP Code://no need for the following line if you just edit the attached source file
Ext.ux.IconLoader.init('http://famfamfam.googlecode.com/svn/wiki/images/'); //note the trailing slash
//"register" the icons you're going to be using on the page:
Ext.ux.IconLoader.reg('accept.png', 'cross.png'); //will create the css rules necessary to use accept.png and cross.png as background images.
//use them!
new Ext.Button({iconCls: 'icon-accept', renderTo: Ext.getBody(), text: 'hello, world'});
new Ext.Button({iconCls: 'icon-cross', renderTo: Ext.getBody(), text: 'hello, world again'});
would create a css rule like so:PHP Code:Ext.ux.IconLoader.reg('application_add.png', 'application_edit.png', 'application_double.png')
Tested in firefox (3.5, 3.0), Internet Explorer (8), Chrome.PHP Code:.icon-application-add {
background-image: url(path_to_icons/application_add.png) !important;
}
.icon-application-edit {
background-image: url(path_to_icons/application_edit.png) !important;
}
.icon-application-double {
background-image: url(path_to_icons/application_double.png) !important;
}
Last edited by mitch_feaster; 27 Jul 2009 at 7:40 AM. Reason: stray period
-
23 Jul 2009 6:32 PM #2
the code's short and neat. i like

Sencha Docs / Ext 3.x - ( Docs | Examples )
Learning Center / Saki's Examples (for 2.x) / HOWTO - ( Report Bugs | Post Proper Code )
-
23 Jul 2009 11:33 PM #3
I like this too - I'll probably use it.
Well done!
-
24 Jul 2009 2:09 AM #4
Great! I start using it for TYPO3 using our skin icons

Many thanks!vg Steffen
--------------------------------------
Release Manager of TYPO3 4.5
energlobe.de - german online magazine
-
24 Jul 2009 7:48 AM #5
-
24 Jul 2009 8:57 AM #6
Sencha Docs / Ext 3.x - ( Docs | Examples )
Learning Center / Saki's Examples (for 2.x) / HOWTO - ( Report Bugs | Post Proper Code )
-
24 Jul 2009 9:14 AM #7
-
25 Jul 2009 5:04 PM #8
Thanks, i changed a bit and post it here to share...
Two icon paths, one hosted by google and one at your own host after download...
For IE6 use gif... So load without extension...
Look at TDGi version for a function way of loading...
Code:// http://www.famfamfam.com // http://code.google.com/p/famfamfam/ // http://code.google.com/p/famfamfam/wiki/all_icons_png // http://www.yui-ext.com/forum/showthread.php?p=363120 // http://tdg-i.com/js/examples/ext/tdgiux/TDGi.iconMgr/ Ext.ns('Ext.ux.icons'); Ext.ux.icons.load = function(){ //iconsPath = 'http://famfamfam.googlecode.com/svn/wiki/images/'; iconsPath = 'assets/ext/icons/'; iconExt = (Ext.isIE6) ? '.gif' : '.png'; newStyle = ''; Ext.each(arguments, function(iconName){ className = 'icon-' + iconName.replace(/_/g, '-'); iconPath = String.format('{0}{1}', iconsPath, iconName + iconExt) newStyle += String.format('.{0} { background-image: url(' + iconPath + ') !important; background-repeat: no-repeat; }', className) }); Ext.util.CSS.createStyleSheet(newStyle, 'dynamic-icons'); }; Ext.ux.icons.load('text_list_bullets', 'group', 'user', 'calendar', 'calendar', 'basket', 'overlays', 'television', 'camera', 'page_white', 'newspaper', 'wrench');
-
26 Jul 2009 2:47 AM #9Sencha - Community Support Team
- Join Date
- Mar 2007
- Location
- Frederick MD, NYC, DC
- Posts
- 16,167
- Vote Rating
- 28
Cool utility


Jay Garcia @ModusJesus || Modus Create co-founder
Ext JS in Action author
Sencha Touch in Action author
Get in touch for Ext JS & Sencha Touch Touch Training
We are also working on Video-based Sencha Touch training: Check it out here.
-
26 Jul 2009 5:02 AM #10
Thanks... It's not really mine... I combined two (source see links) and gave it my own twist... I'd like to extend it more to also add a function way of loading non pre-loaded icons. Like TDGi does. But for now this will do. The only thing you have to think of is adding a new icon to the pre-loader else the requested icon doesn't work. (It does not add a css class if you don't load it first)


Reply With Quote


