explorer.js
$(function() {
var routeTiddlers = 'http://tiddlyweb.tiddlyspace.com/bags/tiddlyweb_public/tiddlers.json?select=tag:httpapi;render=1'
, host = 'tiddlyweb.tiddlyspace.com'
, routeInfo = {}
, defaultRecipe = 'tiddlyweb_public'
, defaultBag = 'tiddlyweb_public'
, repMap = {text: 'text/plain',
'html': 'text/html',
'json': 'application/json',
'wiki': 'text/x-tiddlywiki',
}
, notGetMessage = "Only GET is support for interaction.
";
$.ajaxSetup({
beforeSend: function(xhr) {
xhr.setRequestHeader("X-ControlView", "false");
}
});
// XXX: make me real
function errorMessage() {
console.log('something went wrong');
}
// Process the route info in proper data.
function processRouteInfo(tiddlers) {
$.each(tiddlers, function(index, tiddler) {
var title = tiddler.title
routeInfo[title] = {
text: tiddler.render,
method: [],
rep: []
};
$.each(tiddler.tags, function(tagIndex, tag) {
if (tag.match(/^method:/)) {
routeInfo[title].method.push(tag.replace(/^method:/, ''));
}
if (tag.match(/^rep:/)) {
routeInfo[title].rep.push(tag.replace(/^rep:/, ''));
}
});
});
updateForm();
}
// update the form with proper route info
// XXX: this really ought to be sorted
function updateForm() {
var selector = $('select[name="route"]');
selector.empty();
$('.raw').empty();
$.each(routeInfo, function(key, value) {
var option = $('');
}
}
function updateMessage(ev) {
var text = $('select=[name="route"]').val();
$('input[type="text"]').each(function(index) {
var value = $(this).val();
var name = $(this).attr('name');
text = text.replace('{' + name + '}', encodeURIComponent(value));
});
$('#uri').text(text);
}
// Start up by getting current route info.
function getRouteInfo() {
$.ajax({
url: routeTiddlers,
type: 'GET',
dataType: 'json',
success: processRouteInfo,
error: errorMessage,
});
}
getRouteInfo();
});
Syndicated 2012-03-30 14:06:54 (Updated 2012-03-30 14:44:41) from cdent
