Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.60 KB | None | 0 0
  1. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  2. <!--script type="text/javascript" src="http://momentjs.com/downloads/moment-with-langs.min.js"></script-->
  3. <script type="text/javascript" src="http://www.sd.ac.th/main/wp-content/rss_fetch/FeedEk.js"></script>
  4. <script type="text/javascript">
  5. $(document).ready(function(){
  6.  
  7. $('#divRss').FeedEk({
  8. FeedUrl: 'http://www.sd.ac.th/main/?feed=rss2&cat=121',
  9. //FeedUrl: 'http://www.sd.ac.th/main/?feed=rss2&cat=234',
  10. MaxCount: 10,
  11. ShowPubDate: true,
  12. ShowDesc: false
  13. });
  14.  
  15. setInterval(
  16. function(){
  17. var re = /([.*])$/m;
  18. $('.itemTitle a').each(function() {
  19. var text = $(this).text();
  20. $(this).text(text
  21. .replace(re, '')
  22. );
  23. });}
  24. , 1);
  25. });
  26.  
  27. function reloadFunction() {
  28. location.reload();
  29. }
  30. </script>
  31. <button onclick="reloadFunction()">R</button>
  32. <!--link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css"-->
  33. <link rel="stylesheet" type="text/css" href="http://www.sd.ac.th/main/wp-content/rss_fetch/rss_style.css">
  34. <div id="divRss"></div>
  35.  
  36. /*
  37. * FeedEk jQuery RSS/ATOM Feed Plugin v3.0 with YQL API
  38. * http://jquery-plugins.net/FeedEk/FeedEk.html https://github.com/enginkizil/FeedEk
  39. * Author : Engin KIZIL http://www.enginkizil.com
  40. */
  41.  
  42. (function ($) {
  43. $.fn.FeedEk = function (opt) {
  44. var def = $.extend({
  45. MaxCount: 5,
  46. ShowDesc: true,
  47. ShowPubDate: true,
  48. DescCharacterLimit: 0,
  49. TitleLinkTarget: "_blank",
  50. DateFormat: "",
  51. DateFormatLang:"en"
  52. }, opt);
  53.  
  54. var id = $(this).attr("id"), i, s = "", dt;
  55. $("#" + id).empty();
  56. if (def.FeedUrl == undefined) return;
  57. $("#" + id).append('<!--img src="loader.gif" /-->Fetching...');
  58.  
  59. var YQLstr = 'SELECT channel.item FROM feednormalizer WHERE output="rss_2.0" AND url ="' + def.FeedUrl + '" LIMIT ' + def.MaxCount;
  60.  
  61. $.ajax({
  62. url: "https://query.yahooapis.com/v1/public/yql?q=" + encodeURIComponent(YQLstr) + "&format=json&diagnostics=false&callback=?",
  63. dataType: "json",
  64. success: function (data) {
  65. $("#" + id).empty();
  66. if (!(data.query.results.rss instanceof Array)) {
  67. data.query.results.rss = [data.query.results.rss];
  68. }
  69. $.each(data.query.results.rss, function (e, itm) {
  70. s += '<li><div class="itemTitle"><a href="' + itm.channel.item.link + '&json=1' + '" target="' + def.TitleLinkTarget + '" >' + itm.channel.item.title + '</a></div>';
  71.  
  72. if (def.ShowPubDate){
  73. dt = new Date(itm.channel.item.pubDate);
  74. s += '<div class="itemDate">';
  75. if ($.trim(def.DateFormat).length > 0) {
  76. try {
  77. moment.lang(def.DateFormatLang);
  78. s += moment(dt).format(def.DateFormat);
  79. }
  80. catch (e){s += dt.toLocaleDateString();}
  81. }
  82. else {
  83. s += dt.toLocaleDateString();
  84. }
  85. s += '</div>';
  86. }
  87. if (def.ShowDesc) {
  88. s += '<div class="itemContent">';
  89. if (def.DescCharacterLimit > 0 && itm.channel.item.description.length > def.DescCharacterLimit) {
  90. s += itm.channel.item.description.substring(0, def.DescCharacterLimit) + '...';
  91. }
  92. else {
  93. s += itm.channel.item.description;
  94. }
  95. s += '</div>';
  96. }
  97. });
  98. $("#" + id).append('<ul class="feedEkList">' + s + '</ul>');
  99. }
  100. });
  101. };
  102. })(jQuery);
  103.  
  104. <!doctype html>
  105. <html>
  106. <head>
  107.  
  108. <title>jQuery JSON Parsing</title>
  109.  
  110. <style>
  111. body{
  112. text-align: center;
  113. font-family: arial;
  114. }
  115.  
  116. .button{
  117. margin:20px;
  118. font-size:16px;
  119. font-weight: bold;
  120. padding:5px 10px;
  121. }
  122. </style>
  123.  
  124.  
  125. </head>
  126. <body>
  127. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
  128. <textarea id="txtr" rows="1" cols="35" value="http://www.sd.ac.th/main/?p= {{name}} &json=1">Enter Post ID here</textarea>
  129. <input type="button" value="Get and parse JSON" class="button" />
  130. <br />
  131. <span id="results"></span>
  132.  
  133. <script>
  134. /*function getUrlVars()
  135. {
  136. var vars = [], hash;
  137. var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
  138. for(var i = 0; i < hashes.length; i++)
  139. {
  140. hash = hashes[i].split('=');
  141. vars.push(hash[0]);
  142. vars[hash[0]] = hash[1];
  143. }
  144. return vars;
  145. }*/
  146. $(document).ready(function() {
  147.  
  148. //after button is clicked we download the data
  149. $('.button').click(function(){
  150. var txtbval = "http://www.sd.ac.th/main/?p="+$("#txtr").val()+"&json=1";
  151. //var linkq = getUrlVars()["me"];
  152. //var txtbval = "http://www.sd.ac.th/main/?p="+linkq.val()+"&json=1";
  153. //var txtbval = $("#txtr").val();
  154. console.log("url:"+txtbval);
  155. //start ajax request
  156. $.ajax({
  157. url: txtbval,
  158. //url: "http://www.sd.ac.th/main/?p="+$("#txtr").val()+"&json=1",
  159. //force to handle it as text
  160. dataType: "text",
  161. success: function(data) {
  162. var json = $.parseJSON(data);
  163. $('#results').html(
  164. "Title&nbsp:&nbsp" +
  165. json.post.title +
  166. "</br>" +
  167. "ID&nbsp:&nbsp" +
  168. json.post.id
  169. );
  170. }
  171. });
  172. });
  173. });
  174. </script>
  175.  
  176. </body>
  177. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement