| | |
| Line 1: | Line 1: |
| | | | |
| | if (wgArticleId===0 && wgCanonicalSpecialPageName===false) { | | if (wgArticleId===0 && wgCanonicalSpecialPageName===false) { |
| − | alert(JSON.stringify(wgArticleId+ ' ' + wgCanonicalSpecialPageName + ' ' + wgTitle)); | + | |
| − | } | + | var microbubble = window.microbubble || {}; // namepsace |
| | + | |
| | + | /** |
| | + | * JQuery plugin |
| | + | */ |
| | + | jQuery.fn.getPipe = function (url) { |
| | + | var pipeFeed = new microbubble.PipeFeed(this); |
| | + | pipeFeed.parse(url); |
| | + | }; |
| | + | |
| | + | /** |
| | + | * PipeFeed Class |
| | + | * Returns an ordered list of feed items |
| | + | */ |
| | + | microbubble.PipeFeed = function (htmlElement) { |
| | + | htmlElement.html('<ol id="feed-results"></ol>'); |
| | + | var listElement = $("#feed-results"); |
| | + | |
| | + | return { |
| | + | parse: function (word) { |
| | + | if (!word) { |
| | + | htmlElement.html("No word provided"); |
| | + | } |
| | + | $.getJSON("http://pipes.yahoo.com/pipes/pipe.run?_id=eb450438ffa82162ff9a4be13c6e27e9&word=" + word + "&_render=json&_callback=?", |
| | + | |
| | + | function (json) { |
| | + | parseFeed(json, word); |
| | + | }); |
| | + | } |
| | + | }; |
| | + | |
| | + | function parseFeed(json, word) { |
| | + | var seen = {}; /* preventing double interwikis */ |
| | + | if (json.count > 0) { |
| | + | $(json.value.items).each(function () { |
| | + | var itemDetail = createInterwiki(this, word); |
| | + | if (seen[itemDetail]) $(this).remove(); |
| | + | else { |
| | + | seen[itemDetail] = true; |
| | + | $(listElement).append('<li>' + itemDetail + '</li>'); |
| | + | } |
| | + | }); |
| | + | } else { |
| | + | -htmlElement.html("<i>No interwikis found</i>"); |
| | + | } |
| | + | } |
| | + | |
| | + | function createInterwiki(item, word) { |
| | + | return '<h4>[[' + item.content + ':' + word + ']]</h4>'; |
| | + | } |
| | + | |
| | + | |
| | + | }; |
| | + | }; |
if (wgArticleId===0 && wgCanonicalSpecialPageName===false) { var microbubble = window.microbubble || {}; // namepsace /** * JQuery plugin */ jQuery.fn.getPipe = function (url) { var pipeFeed = new microbubble.PipeFeed(this); pipeFeed.parse(url); }; /** * PipeFeed Class * Returns an ordered list of feed items */ microbubble.PipeFeed = function (htmlElement) { htmlElement.html('<ol id="feed-results"></ol>'); var listElement = $("#feed-results"); return { parse: function (word) { if (!word) { htmlElement.html("No word provided"); } $.getJSON("http://pipes.yahoo.com/pipes/pipe.run?_id=eb450438ffa82162ff9a4be13c6e27e9&word=" + word + "&_render=json&_callback=?", function (json) { parseFeed(json, word); }); } }; function parseFeed(json, word) { var seen = {}; /* preventing double interwikis */ if (json.count > 0) { $(json.value.items).each(function () { var itemDetail = createInterwiki(this, word); if (seen[itemDetail]) $(this).remove(); else { seen[itemDetail] = true; $(listElement).append('<li>' + itemDetail + '</li>'); } }); } else { -htmlElement.html("<i>No interwikis found</i>"); } } function createInterwiki(item, word) { return '<h4>[[' + item.content + ':' + word + ']]</h4>'; } }; };