43
44
"application/x-javascript" : "text",
44
45
"application/javascript" : "text",
45
46
"application/json" : "text",
46
"application/xml" : "text"
47
"application/xml" : "text",
48
"application/ogg" : "audio",
49
"image/svg+xml": "object"
49
52
/* Mapping MIME types to icons, just the file's basename */
332
/* Need to make a 2nd ajax call, this time get the actual file
334
callback = function(response)
336
/* Read the response and set up the page accordingly */
337
handle_contents_response(path, response);
339
/* Call the server and request the listing. */
341
args = shallow_clone_object(url_args);
344
/* This time, get the contents of the file, not its metadata */
345
args['return'] = "contents";
346
ajax_call(callback, service_app, path, args, "GET");
336
/* Read the response and set up the page accordingly */
337
var content_type = current_file.type;
338
handle_contents_response(path, content_type, url_args);
348
341
update_actions(isdir);
351
function handle_contents_response(path, response)
344
function handle_contents_response(path, content_type)
353
346
/* Treat this as an ordinary file. Get the file type. */
354
var content_type = response.getResponseHeader("Content-Type");
347
//var content_type = response.getResponseHeader("Content-Type");
355
348
var handler_type = get_handler_type(content_type);
356
would_be_handler_type = handler_type;
357
349
/* handler_type should now be set to either
358
* "text", "image", "audio" or "binary". */
350
* "text", "image", "video", "audio" or "binary". */
359
351
switch (handler_type)
362
handle_text(path, response.responseText,
363
would_be_handler_type);
354
handle_text(path, content_type);
366
/* TODO: Custom image handler */
367
handle_binary(path, response.responseText);
360
handle_video(path, content_type);
370
/* TODO: Custom audio handler */
371
handle_binary(path, response.responseText);
363
handle_audio(path, content_type);
366
handle_object(path, content_type);
374
369
handle_binary(path);
554
554
div.appendChild(par2);
557
/** Displays an image file.
559
function handle_image(path)
561
/* Disable save button */
562
using_codepress = false;
563
disable_save_if_safe();
566
var url = app_url(service_app, path) + "?return=contents";
569
var img = $("<img />");
570
img.attr("alt", path);
571
img.attr("src", url);
574
var div = $('<div class="padding" />');
575
div.append('<h1>Image Preview</h1>');
577
$("#filesbody").append(div);
580
/** Displays a video.
582
function handle_video(path, type)
584
/* Disable save button and hide the save panel */
585
using_codepress = false;
586
disable_save_if_safe();
589
var url = app_url(service_app, path) + "?return=contents";
590
var download_url = app_url(download_app, path);
592
/* Fallback Download Link */
593
var link = $('<p>Could not display video in browser.<p><p><a /></p>');
594
var a = link.find('a');
595
a.attr("href", download_url);
596
a.text("Download " + path);
598
/* Fallback Object Tag */
599
var obj = $('<object />');
600
obj.attr("type", type);
601
obj.attr("data", url);
604
/* HTML 5 Video Tag */
605
var video = $('<video controls="true" autoplay="true" />');
606
video.attr("src", url);
607
var support = video[0].canPlayType && video[0].canPlayType(type);
608
if (support != "probably" && support != "maybe") {
614
var div = $('<div class="padding" />');
615
div.append('<h1>Video Preview</h1>');
617
$("#filesbody").append(div);
620
/** Display audio content
622
function handle_audio(path, type)
624
/* Disable save button and hide the save panel */
625
using_codepress = false;
626
disable_save_if_safe();
629
var url = app_url(service_app, path) + "?return=contents";
630
var download_url = app_url(download_app, path);
632
/* Fallback Download Link */
633
var link = $('<p>Could not display audio in browser.<p><p><a /></p>');
634
var a = link.find('a');
635
a.attr("href", download_url);
636
a.text("Download " + path);
638
/* Fallback Object Tag */
639
var obj = $('<object />');
640
obj.attr("type", type);
641
obj.attr("data", url);
644
/* HTML 5 Audio Tag */
645
var audio = $('<audio controls="true" autoplay="true" />');
646
audio.attr("src", url);
647
var support = audio[0].canPlayType && audio[0].canPlayType(type);
648
if (support != "probably" && support != "maybe") {
654
var div = $('<div class="padding" />');
655
div.append('<h1>Audio Preview</h1>');
657
$("#filesbody").append(div);
660
/** Display generic object content
662
function handle_object(path, content_type)
664
/* Disable save button and hide the save panel */
665
using_codepress = false;
666
disable_save_if_safe();
669
var url = app_url(service_app, path) + "?return=contents";
670
var download_url = app_url(download_app, path);
672
/* Fallback Download Link */
673
var link = $('<p><a /></p>');
674
var a = link.find('a');
675
a.attr("href", download_url);
676
a.text("Download " + path);
679
var obj = $('<object width="100%" height="500px" />');
680
obj.attr("type", content_type);
681
obj.attr("data", url);
682
obj.append('Could not load object');
685
var div = $('<div class="padding" />');
686
div.append('<h1>Preview</h1>');
689
$("#filesbody").append(div);
557
692
/* Enable or disable actions1 moreactions actions. Takes either a single
558
693
* name, or an array of them.*/
559
694
function set_action_state(names, which, allow_on_revision)