MediaWiki:Common.js/Wikinews:Syndication

From Wikinews, the free news source you can write!
Jump to: navigation, search

//

  1. //custom rss using CSpurrier's tool
    
  2. //yes i know the js is ugly
    
  3. addOnloadHook(function() {document.getElementById("RSScreator").innerHTML= '<form id="customrssform" method="GET" action="http://toolserver.org/~bawolff/rss/rss.php" onsubmit="Bawolff.rssC.submit()"><fieldset> <legend>Custom RSS</legend><ul><li><label for="lang">Language:</label> <select id="lang" name="lang"><option name="en" value="en" selected="selected">English</option></select><input type="hidden" name="family" value="wikinews"/></li><li>Categories: <ul id="catul"><li><input id="categories0" name="categories0" type="text" value="Published" length="15"/></li><li id="addmorecat"><a href="javascript:Bawolff.rssC.addCat();void 0;">add more</a></li></ul></li></ul><input type="hidden" name="ns14" value="1"/><input type="hidden" name="desc" value="Wikinews, the free news source you can write. For more information, or to see all stories, visit http://en.wikinews.org"/><input type="hidden" name="notcategories" value="Disputed|No_publish|brief"/><input type="hidden" name="title" value="Latest Wikinews (custom)"/><input type="submit" class="rss" style="cursor:pointer" name="Get RSS" value="Get RSS"></fieldset></form>';
    
  4. os_initHandlers("categories0",'customrssform',document.getElementById('categories0'));});
    
  5.  
    
  6. if (typeof Bawolff !== "object") Bawolff = {};
    
  7. //Bawolff.rssC = 0;
    
  8. if (typeof Bawolff.rssC !== "object") {
    
  9.     Bawolff.rssC = {};
    
  10. } else {
    
  11.     throw new Error("overlapping object names (bawolff.rssC)");
    
  12. }
    
  13.  
    
  14.  
    
  15. Bawolff.rssC.catcount = 0;
    
  16.  
    
  17. Bawolff.rssC.addCat = function() {
    
  18. Bawolff.rssC.catcount++
    
  19. var last = document.getElementById("addmorecat");
    
  20. var newcat = document.createElement("li");
    
  21. var newinput = document.createElement("input");
    
  22. var elmId = "categories" + Bawolff.rssC.catcount;
    
  23. newinput.id = elmId;
    
  24. newinput.name = elmId;
    
  25. newinput.type = "text";
    
  26. newinput.length = "15";
    
  27. newcat.appendChild(newinput)
    
  28. document.getElementById("catul").insertBefore(newcat, last);
    
  29. //Enable suggestions:
    
  30. os_initHandlers(elmId,'customrssform',newinput);
    
  31. }
    
  32.  
    
  33. Bawolff.rssC.submit = function() {
    
  34. //fix categories to single arg
    
  35. var cats = document.createElement("input");
    
  36. cats.type = "hidden";
    
  37. cats.name = "categories";
    
  38. catlist = [];
    
  39. var catToAdd;
    
  40. for (var i = 0; i <= Bawolff.rssC.catcount;i++) {
    
  41. catToAdd = document.getElementById("categories" + i ).value;
    
  42. if (catToAdd.length > 9 && catToAdd.substring(1, 9) === "ategory:") {
    
  43.     catToAdd = catToAdd.substring(9);
    
  44. }
    
  45. catlist[i] = catToAdd;
    
  46. }
    
  47. var catcat = catlist.join("|");
    
  48.  
    
  49. /* If someone didn't full out field. kill blank cats*/
    
  50. catcat = catcat.replace(/\|{2,}/g, "|");
    
  51. if (catcat.charAt(0) === "|") {
    
  52.     catcat = catcat.substring(1);
    
  53. }
    
  54. if (catcat.charAt(catcat.length-1) === "|") {
    
  55.     catcat = catcat.substring(0, catcat.length-1);
    
  56. }
    
  57. cats.value = catcat;
    
  58. document.getElementById("customrssform").appendChild(cats);
    
  59. }
    
  60.  
    
  61. //