Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

add custom charset support #8

Open
zhikuanlin opened this issue Oct 13, 2011 · 2 comments
Open

add custom charset support #8

zhikuanlin opened this issue Oct 13, 2011 · 2 comments

Comments

@zhikuanlin
Copy link

lazyload is a very good product,
we are going to use it in chinese environment now, but it only supports utf8 charset when loading js/css files.
i know that utf8 is the best choice, but in our sites there is lots of old js/css files using non-unicode charsets such as gbk, gb2312, etc.
so i suggest to add custom charset support:

LazyLoad.js(['file1.js[charset=utf-8]', 'file2.js[charset=gbk]']);

or

LazyLoad.js([{
  src: 'file1.js'
  charset: 'utf-8'
}, {
  src: 'file2.js',
  charset: 'gbk'
}]);

Either one would be fine.

and here is the code for the first form:

// lazyload.js 2.0.3
// line 218 add:
var charset = '';
var match = url.match(/\[charset=([a-zA-Z0-9-]+)\]$/);
if (match) {
  charset = match[1];
  url = url.replace(match[0], '');
}
// line 230 change to:
if (charset != '') node.setAttribute('charset', charset);

Thanks

@zhikuanlin
Copy link
Author

code above has a bug,
"charset" must be set to the newly created node before "src", see:
http://yuilibrary.com/projects/yui3/ticket/2528363

@tylerzhu
Copy link

tylerzhu commented Jun 2, 2012

Is the problem solved?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants