MediaWiki:Common.js/Wikinews:Syndication

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

//

//custom rss using CSpurrier's tool
//yes i know the js is ugly
$(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>';
os_initHandlers("categories0",'customrssform',document.getElementById('categories0'));});

if (typeof Bawolff !== "object") Bawolff = {};
//Bawolff.rssC = 0;
if (typeof Bawolff.rssC !== "object") {
    Bawolff.rssC = {};
} else {
    throw new Error("overlapping object names (bawolff.rssC)");
}


Bawolff.rssC.catcount = 0;

Bawolff.rssC.addCat = function() {
Bawolff.rssC.catcount++
var last = document.getElementById("addmorecat");
var newcat = document.createElement("li");
var newinput = document.createElement("input");
var elmId = "categories" + Bawolff.rssC.catcount;
newinput.id = elmId;
newinput.name = elmId;
newinput.type = "text";
newinput.length = "15";
newcat.appendChild(newinput)
document.getElementById("catul").insertBefore(newcat, last);
//Enable suggestions:
os_initHandlers(elmId,'customrssform',newinput);
}

Bawolff.rssC.submit = function() {
//fix categories to single arg
var cats = document.createElement("input");
cats.type = "hidden";
cats.name = "categories";
catlist = [];
var catToAdd;
for (var i = 0; i <= Bawolff.rssC.catcount;i++) {
catToAdd = document.getElementById("categories" + i ).value;
if (catToAdd.length > 9 && catToAdd.substring(1, 9) === "ategory:") {
    catToAdd = catToAdd.substring(9);
}
catlist[i] = catToAdd;
}
var catcat = catlist.join("|");

/* If someone didn't full out field. kill blank cats*/
catcat = catcat.replace(/\|{2,}/g, "|");
if (catcat.charAt(0) === "|") {
    catcat = catcat.substring(1);
}
if (catcat.charAt(catcat.length-1) === "|") {
    catcat = catcat.substring(0, catcat.length-1);
}
cats.value = catcat;
document.getElementById("customrssform").appendChild(cats);
}

//