Created
April 23, 2015 04:09
-
-
Save dstyle0210/3a10d2fc06aeb6e3f697 to your computer and use it in GitHub Desktop.
[tistory, jquery] Category to JSON (카테고리 목록을 json화)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function tistoryCategoryJson(oId){ | |
| var o = {}; | |
| // 데이터 추출 | |
| function data(tg,dom){ | |
| tg.link = $(dom).find(">li>a").attr("href"); | |
| tg.cnt = $(dom).find(">li>a>span").text(); | |
| $(dom).find(">li>a>span").remove(); | |
| tg.title = $(dom).find(">li>a").text(); | |
| } | |
| function data2(tg,dom){ | |
| tg.link = $(dom).find(">a").attr("href"); | |
| tg.cnt = $(dom).find(">a>span").text(); | |
| $(dom).find("a>span").remove(); | |
| tg.title = $(dom).find(">a").text(); | |
| } | |
| function inDep3(tg,dom){ | |
| if($(dom).find(">ul").length){ | |
| tg.dep2 = []; | |
| $(dom).find(">ul>li").each(function(i,item){ | |
| tg.dep2[i] = {}; | |
| data2(tg.dep2[i],$(dom).find(">ul>li").eq(i)); | |
| }); | |
| } | |
| } | |
| // 분류전체보기 추출 | |
| o.total = {}; | |
| data(o.total,oId+">ul"); | |
| // 카테고리 추출 | |
| o.category = []; | |
| $(oId+">ul>li>ul>li").each(function(i,item){ | |
| o.category[i] = {}; | |
| data2(o.category[i],$(oId+">ul>li>ul>li").eq(i)); | |
| inDep3(o.category[i],$(oId+">ul>li>ul>li").eq(i)); | |
| }); | |
| return o; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment