利用Jquery实现的RSS阅读器源码高亮模式在线查看
当前路径:js/rss.js /* author:caedmon web: Email:huimingcai@163.com */ $(document).ready(function() { init(); }); $(function() { $("#btncannal").click(function() { $("#InsertBox").slideUp(); }) $("#aClose").click(function() { $("#InsertBox").slideUp(); }) $("#InsertShow").click(function(event) { var rss = $.cookie('myrss'); if (rss != null) { var json = eval("(" + rss + ")"); if (json.length > 7) { alert("这回有差了,深圳新闻资讯 ,只能8个!:)"); return; } } actionType = 0; var leftvalue = event.clientX - 180; var topvalue = event.clientY + 20; $("#InsertBox").css({ left: leftvalue, top: topvalue }); $("#InsertBox").animate({ height: 'show' }, "normal"); }) $("#btnedit").click(function() { var title = $.trim($("#txtTitle").val()); var url = $.trim($("#txtRss").val()); if (title.length == 0 || url.length == 0) { alert("想空没门"); return; } if (actionType == 0) { //add New Insert(title, url); init(); } else if (actionType == 1) { //edit node update(oldTitle, oldUrl, title, url); init(); } $("#InsertBox").slideUp(); }) }) var defaultRss = "[{\"title\":\"CnBeta\",\"url\":\"\"},{\"title\":\"体育\",\"url\":\"\"},{\"title\":\"163新闻\",\"url\":\"\"}]"; function Insert(title, url) { var oldrss = $.cookie('myrss'); var myrss = changeJson(title, url); if (oldrss != null) { oldrss = oldrss.replace("[", "").replace("]", ""); $.cookie('myrss', "[" + oldrss + "," + myrss+"]", { expires: 100000 }); } else { defaultRss = defaultRss.replace("[", "").replace("]", ""); $.cookie('myrss', "["+defaultRss+","+myrss+"]", { expires: 100000 }); } } function del(title, url) { var oldrss = $.cookie('myrss'); if (oldrss == null) oldrss = defaultRss; var json = eval("(" + oldrss + ")"); if (actionType != 0) { if (json.length == 1) { alert("这个你可以有!不差这个!:)"); return; } } var NewRss = ""; if (oldrss == null) return; var oneRss = changeJson(title, url); var moreRss = "," + oneRss; if (oldrss.indexOf(moreRss) > 0) { NewRss = oldrss.replace(moreRss, ""); $.cookie('myrss', NewRss, { expires: 100000 }); return; } else if (oldrss.indexOf(oneRss + ",") > 0) { NewRss = oldrss.replace(oneRss + ",", ""); $.cookie('myrss', NewRss, { expires: 100000 }); return; } else if (oldrss.indexOf(oneRss) > 0) { NewRss = oldrss.replace(oneRss, ""); $.cookie('myrss', NewRss, { expires: 100000 }); return; } } function update(oldtitle, oldurl, newtitle, newurl) { del(oldtitle, oldurl); Insert(newtitle, newurl); } function changeJson(title, url) { var result = "{\"title\":"; result = result + "\"" + title + "\","; result = result + "\"url\":"; result = result + "\"" + url + "\"}"; return result; } function loadData(url) { $.ajax({ url: "Rss.axd?url=" + encodeURIComponent(url), success: function(json) { var DomainUrl = ""; var Domain = url.replace("", ""); if (Domain.indexOf("/") > 0) { DomainUrl=Domain = Domain.substring(0, Domain.indexOf("/")); if (Domain.split(".").length > 2) { Domain = Domain.split(".")[1] + "." + Domain.split(".")[2]; } } $("#InfoContent").html(""); json = eval("(" + json + ")"); $.each(json, function(i) { var des = json[i].Description; if (des.length == 0) des = "该网站未提供描述"; if (des.length > 320) des = des.substring(0, 320) + "......"; var myurl = json[i].url; if (myurl.indexOf(Domain) < 0) myurl = "" + DomainUrl + myurl; $("#InfoContent").append("<li class='list'><a href=\"javascript:void(0)\" url=\"" + myurl + "\" description=\"" + des + "\">" + json[i].title + "</a></li>"); }) $("#InfoContent").find("li").each(function() { $(this).mouseover(function() { $(this).addClass("mouseoverli"); }) .mouseout(function() { $(this).removeClass("mouseoverli"); }) .click(function() { $(".currentli").removeClass("currentli"); $("#InfoDescription").html($(this).find("a").attr("description") + "<a href=\"" + $(this).find("a").attr("url") + "\" target=\"_blank\">[更多内容]</a>"); $(this).addClass("currentli"); }); }) }, beforeSend: function() { $("#load").show(); }, complete: function() { $("#load").hide(); }, error: function() { alert("或许你提供的网址有误,或许是该死的字符!"); } }) } var actionType = -1; var oldTitle = ""; var oldUrl = ""; function init() { var defaulturl = ""; var rss = $.cookie('myrss'); var isExist = true; if (rss == null) { isExist = false; rss = defaultRss; } $("#InfoHeadMain").html(""); var json = eval("(" + rss + ")"); $.each(json, function(i) { if (i == 0) { defaulturl = json[i].url; $("#InfoHeadMain").append("<div class=\"currentMenu\" title=\""+json[i].title+"\"><div url=\"" + json[i].url + "\" class=\"MenuTitle\">" + json[i].title + "</div><div class=\"MenuSet\"><div title=\"编辑\" url=\"" + json[i].url + "\" note=\"" + json[i].title + "\" class=\"MenuEditactive\"></div><div title=\"删除\" url=\"" + json[i].url + "\" note=\"" + json[i].title + "\" class=\"MenuDelactive\"></div></div></div>"); } else { $("#InfoHeadMain").append("<div class=\"Menu\" title=\"" + json[i].title + "\"><div url=\"" + json[i].url + "\" class=\"MenuTitle\">" + json[i].title + "</div><div class=\"MenuSet\"><div title=\"编辑\" url=\"" + json[i].url + "\" note=\"" + json[i].title + "\" class=\"MenuEdit\"></div><div title=\"删除\" url=\"" + json[i].url + "\" note=\"" + json[i].title + "\" class=\"MenuDel\"></div></div></div>"); } }) $("#InfoHeadMain").find(".Menu").each(function() { $(this).mouseover(function() { $(this).addClass("mouseoverMenu"); $(this).find(".MenuEdit").addClass("MenuEditmouveover"); $(this).find(".MenuDel").addClass("MenuDelmouveover"); }).mouseout(function() { $(this).removeClass("mouseoverMenu").addClass("Menu"); $(this).find(".MenuEdit").removeClass("MenuEditmouveover").addClass("MenuEdit"); $(this).find(".MenuDel").removeClass("MenuDelmouveover").addClass("MenuDel"); }).click(function() { $(".currentMenu").removeClass("currentMenu").addClass("Menu"); $(".MenuEditactive").removeClass("MenuEditactive").addClass("MenuEdit"); $(".MenuDelactive").removeClass("MenuDelactive").addClass("MenuDel"); $(this).addClass("currentMenu"); $(this).find(".MenuEdit").addClass("MenuEditactive"); $(this).find(".MenuDel").addClass("MenuDelactive"); }) }) $("#InfoHeadMain").find(".currentMenu").click(function() { $(".currentMenu").removeClass("currentMenu").addClass("Menu"); $(".MenuEditactive").removeClass("MenuEditactive").addClass("MenuEdit"); $(".MenuDelactive").removeClass("MenuDelactive").addClass("MenuDel"); $(this).addClass("currentMenu"); $(this).find(".MenuEdit").addClass("MenuEditactive"); $(this).find(".MenuDel").addClass("MenuDelactive"); }).mouseover(function() { $(this).addClass("mouseoverMenu"); $(this).find(".MenuEdit").addClass("MenuEditmouveover"); $(this).find(".MenuDel").addClass("MenuDelmouveover"); }).mouseout(function() { $(this).removeClass("mouseoverMenu").addClass("Menu"); $(this).find(".MenuEdit").removeClass("MenuEditmouveover").addClass("MenuEdit"); $(this).find(".MenuDel").removeClass("MenuDelmouveover").addClass("MenuDel"); }) $("#InfoHeadMain").find(".MenuTitle").each(function() { $(this).click(function() { loadData($(this).attr("url")); }) }) $("#InfoHeadMain").find(".MenuEdit").each(function(i) { $(this).click(function(event) { var leftvalue = event.clientX - 180; var topvalue = event.clientY + 20; $("#InsertBox").css({ left: leftvalue, top: topvalue }); $("#InsertBox").animate({ height: 'show' }, "normal"); oldTitle = ""; oldUrl = ""; oldTitle = $(this).attr("note"); oldUrl = $(this).attr("url"); $("#txtTitle").val(oldTitle); $("#txtRss").val(oldUrl); actionType = 1; }) }) $("#InfoHeadMain").find(".MenuDel").each(function(i) { $(this).click(function() { if (confirm("确定要删除该标签吗?")) { var rss = $.cookie('myrss'); if (isExist) { del($(this).attr("note"), $(this).attr("url")); } else { var delRss = changeJson($(this).attr("note"), $(this).attr("url")); var rsscookie = ""; if (defaultRss.indexOf("," + delRss) > 0) rsscookie = defaultRss.replace("," + delRss, ""); else if (defaultRss.indexOf(delRss+",") > 0) rsscookie = defaultRss.replace(delRss + ",", ""); else rsscookie = defaultRss.replace(delRss, ""); $.cookie('myrss', rsscookie, { expires: 100000 }); } init(); } }) }) $("#InfoHeadMain").find(".MenuEditactive").each(function(i) { $(this).click(function(event) { var leftvalue = event.clientX - 180; var topvalue = event.clientY + 20; $("#InsertBox").css({ left: leftvalue, top: topvalue }); $("#InsertBox").animate({ height: 'show' }, "normal"); oldTitle = ""; oldUrl = ""; oldTitle = $(this).attr("note"); oldUrl = $(this).attr("url"); $("#txtTitle").val(oldTitle); $("#txtRss").val(oldUrl); actionType = 1; }) }) $("#InfoHeadMain").find(".MenuDelactive").each(function(i) { $(this).click(function() { if (confirm("确定要删除该标签吗?")) { var rss = $.cookie('myrss'); if (isExist) { del($(this).attr("note"), $(this).attr("url")); } else { var delRss = changeJson($(this).attr("note"), $(this).attr("url")); var rsscookie = ""; if (defaultRss.indexOf("," + delRss) > 0) rsscookie = defaultRss.replace("," + delRss, ""); else if (defaultRss.indexOf(delRss + ",") > 0) rsscookie = defaultRss.replace(delRss + ",", ""); else rsscookie = defaultRss.replace(delRss, ""); $.cookie('myrss', rsscookie, { expires: 100000 }); } init(); } }) }) loadData(defaulturl); }
- 中国足彩网:皮克不必
中国足彩网:近日,中国足彩网一名前西班牙裁判针对皮克85%的裁判都是皇马粉丝的言论... - 美欧指责巴将AIP系统
元级潜艇 团长老丁 自元级潜艇露面以来,其新颖的外形和优异的性能就引起了全世界军事... - 深度:我侦察船抵近夏
新浪军事编者:为了更好的为读者呈现多样军事内容,满足读者不同阅读需求,共同探讨国... - 中土导弹交易目前协议
红旗-9防空导弹系统(资料图) 人民网11月15日讯土耳其国防官员14日表示,针对是否同...