Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
- <!--script type="text/javascript" src="http://momentjs.com/downloads/moment-with-langs.min.js"></script-->
- <script type="text/javascript" src="http://www.sd.ac.th/main/wp-content/rss_fetch/FeedEk.js"></script>
- <script type="text/javascript">
- $(document).ready(function(){
- $('#divRss').FeedEk({
- FeedUrl: 'http://www.sd.ac.th/main/?feed=rss2&cat=121',
- //FeedUrl: 'http://www.sd.ac.th/main/?feed=rss2&cat=234',
- MaxCount: 10,
- ShowPubDate: true,
- ShowDesc: false
- });
- setInterval(
- function(){
- var re = /([.*])$/m;
- $('.itemTitle a').each(function() {
- var text = $(this).text();
- $(this).text(text
- .replace(re, '')
- );
- });}
- , 1);
- });
- function reloadFunction() {
- location.reload();
- }
- </script>
- <button onclick="reloadFunction()">R</button>
- <!--link rel="stylesheet" href="path/to/font-awesome/css/font-awesome.min.css"-->
- <link rel="stylesheet" type="text/css" href="http://www.sd.ac.th/main/wp-content/rss_fetch/rss_style.css">
- <div id="divRss"></div>
- /*
- * FeedEk jQuery RSS/ATOM Feed Plugin v3.0 with YQL API
- * http://jquery-plugins.net/FeedEk/FeedEk.html https://github.com/enginkizil/FeedEk
- * Author : Engin KIZIL http://www.enginkizil.com
- */
- (function ($) {
- $.fn.FeedEk = function (opt) {
- var def = $.extend({
- MaxCount: 5,
- ShowDesc: true,
- ShowPubDate: true,
- DescCharacterLimit: 0,
- TitleLinkTarget: "_blank",
- DateFormat: "",
- DateFormatLang:"en"
- }, opt);
- var id = $(this).attr("id"), i, s = "", dt;
- $("#" + id).empty();
- if (def.FeedUrl == undefined) return;
- $("#" + id).append('<!--img src="loader.gif" /-->Fetching...');
- var YQLstr = 'SELECT channel.item FROM feednormalizer WHERE output="rss_2.0" AND url ="' + def.FeedUrl + '" LIMIT ' + def.MaxCount;
- $.ajax({
- url: "https://query.yahooapis.com/v1/public/yql?q=" + encodeURIComponent(YQLstr) + "&format=json&diagnostics=false&callback=?",
- dataType: "json",
- success: function (data) {
- $("#" + id).empty();
- if (!(data.query.results.rss instanceof Array)) {
- data.query.results.rss = [data.query.results.rss];
- }
- $.each(data.query.results.rss, function (e, itm) {
- s += '<li><div class="itemTitle"><a href="' + itm.channel.item.link + '&json=1' + '" target="' + def.TitleLinkTarget + '" >' + itm.channel.item.title + '</a></div>';
- if (def.ShowPubDate){
- dt = new Date(itm.channel.item.pubDate);
- s += '<div class="itemDate">';
- if ($.trim(def.DateFormat).length > 0) {
- try {
- moment.lang(def.DateFormatLang);
- s += moment(dt).format(def.DateFormat);
- }
- catch (e){s += dt.toLocaleDateString();}
- }
- else {
- s += dt.toLocaleDateString();
- }
- s += '</div>';
- }
- if (def.ShowDesc) {
- s += '<div class="itemContent">';
- if (def.DescCharacterLimit > 0 && itm.channel.item.description.length > def.DescCharacterLimit) {
- s += itm.channel.item.description.substring(0, def.DescCharacterLimit) + '...';
- }
- else {
- s += itm.channel.item.description;
- }
- s += '</div>';
- }
- });
- $("#" + id).append('<ul class="feedEkList">' + s + '</ul>');
- }
- });
- };
- })(jQuery);
- <!doctype html>
- <html>
- <head>
- <title>jQuery JSON Parsing</title>
- <style>
- body{
- text-align: center;
- font-family: arial;
- }
- .button{
- margin:20px;
- font-size:16px;
- font-weight: bold;
- padding:5px 10px;
- }
- </style>
- </head>
- <body>
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
- <textarea id="txtr" rows="1" cols="35" value="http://www.sd.ac.th/main/?p= {{name}} &json=1">Enter Post ID here</textarea>
- <input type="button" value="Get and parse JSON" class="button" />
- <br />
- <span id="results"></span>
- <script>
- /*function getUrlVars()
- {
- var vars = [], hash;
- var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
- for(var i = 0; i < hashes.length; i++)
- {
- hash = hashes[i].split('=');
- vars.push(hash[0]);
- vars[hash[0]] = hash[1];
- }
- return vars;
- }*/
- $(document).ready(function() {
- //after button is clicked we download the data
- $('.button').click(function(){
- var txtbval = "http://www.sd.ac.th/main/?p="+$("#txtr").val()+"&json=1";
- //var linkq = getUrlVars()["me"];
- //var txtbval = "http://www.sd.ac.th/main/?p="+linkq.val()+"&json=1";
- //var txtbval = $("#txtr").val();
- console.log("url:"+txtbval);
- //start ajax request
- $.ajax({
- url: txtbval,
- //url: "http://www.sd.ac.th/main/?p="+$("#txtr").val()+"&json=1",
- //force to handle it as text
- dataType: "text",
- success: function(data) {
- var json = $.parseJSON(data);
- $('#results').html(
- "Title : " +
- json.post.title +
- "</br>" +
- "ID : " +
- json.post.id
- );
- }
- });
- });
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement