123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235 |
- UE.parse.register("list", function(utils) {
- var customCss = [],
- customStyle = {
- cn: "cn-1-",
- cn1: "cn-2-",
- cn2: "cn-3-",
- num: "num-1-",
- num1: "num-2-",
- num2: "num-3-",
- dash: "dash",
- dot: "dot"
- };
- utils.extend(this, {
- liiconpath: "http://bs.baidu.com/listicon/",
- listDefaultPaddingLeft: "20"
- });
- var root = this.root,
- ols = root.getElementsByTagName("ol"),
- uls = root.getElementsByTagName("ul"),
- selector = this.selector;
- if (ols.length) {
- applyStyle.call(this, ols);
- }
- if (uls.length) {
- applyStyle.call(this, uls);
- }
- if (ols.length || uls.length) {
- customCss.push(selector + " .list-paddingleft-1{padding-left:0}");
- customCss.push(
- selector +
- " .list-paddingleft-2{padding-left:" +
- this.listDefaultPaddingLeft +
- "px}"
- );
- customCss.push(
- selector +
- " .list-paddingleft-3{padding-left:" +
- this.listDefaultPaddingLeft * 2 +
- "px}"
- );
- utils.cssRule(
- "list",
- selector +
- " ol," +
- selector +
- " ul{margin:0;padding:0;}\n" +
- selector +
- " li{clear:both;}\n" +
- customCss.join("\n"),
- document
- );
- }
- function applyStyle(nodes) {
- var T = this;
- utils.each(nodes, function(list) {
- if (list.className && /custom_/i.test(list.className)) {
- var listStyle = list.className.match(/custom_(\w+)/)[1];
- if (listStyle == "dash" || listStyle == "dot") {
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- customStyle[listStyle] +
- "{background-image:url(" +
- T.liiconpath +
- customStyle[listStyle] +
- ".gif)}"
- );
- utils.pushItem(
- customCss,
- selector +
- " ul.custom_" +
- listStyle +
- "{list-style:none;} " +
- selector +
- " ul.custom_" +
- listStyle +
- " li{background-position:0 3px;background-repeat:no-repeat}"
- );
- } else {
- var index = 1;
- utils.each(list.childNodes, function(li) {
- if (li.tagName == "LI") {
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- customStyle[listStyle] +
- index +
- "{background-image:url(" +
- T.liiconpath +
- "list-" +
- customStyle[listStyle] +
- index +
- ".gif)}"
- );
- index++;
- }
- });
- utils.pushItem(
- customCss,
- selector +
- " ol.custom_" +
- listStyle +
- "{list-style:none;}" +
- selector +
- " ol.custom_" +
- listStyle +
- " li{background-position:0 3px;background-repeat:no-repeat}"
- );
- }
- switch (listStyle) {
- case "cn":
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft-1{padding-left:25px}"
- );
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft-2{padding-left:40px}"
- );
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft-3{padding-left:55px}"
- );
- break;
- case "cn1":
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft-1{padding-left:30px}"
- );
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft-2{padding-left:40px}"
- );
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft-3{padding-left:55px}"
- );
- break;
- case "cn2":
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft-1{padding-left:40px}"
- );
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft-2{padding-left:55px}"
- );
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft-3{padding-left:68px}"
- );
- break;
- case "num":
- case "num1":
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft-1{padding-left:25px}"
- );
- break;
- case "num2":
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft-1{padding-left:35px}"
- );
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft-2{padding-left:40px}"
- );
- break;
- case "dash":
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft{padding-left:35px}"
- );
- break;
- case "dot":
- utils.pushItem(
- customCss,
- selector +
- " li.list-" +
- listStyle +
- "-paddingleft{padding-left:20px}"
- );
- }
- }
- });
- }
- });
|