From 6356edefaea3fe78969c53fec2d371cb8f42d820 Mon Sep 17 00:00:00 2001 From: Jose Antonio Marquez Date: Thu, 3 May 2012 15:28:38 -0700 Subject: Full CSS support on open Add full CSS for files on open (including loading cross-domain). This is only for files that are opened. --- js/io/system/coreioapi.js | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'js/io/system/coreioapi.js') diff --git a/js/io/system/coreioapi.js b/js/io/system/coreioapi.js index a06f45c6..1e6518fe 100755 --- a/js/io/system/coreioapi.js +++ b/js/io/system/coreioapi.js @@ -192,6 +192,23 @@ exports.CoreIoApi = Montage.create(Component, { set: function(value) { this._fileServiceURL = value; } + }, + //////////////////////////////////////////////////////////////////// + //File service API URL + _webServiceURL: { + enumerable: false, + value: '/web' + }, + //////////////////////////////////////////////////////////////////// + // + webServiceURL: { + enumerable: false, + get: function() { + return String(this.rootUrl+this._webServiceURL); + }, + set: function(value) { + this._webServiceURL = value; + } }, //////////////////////////////////////////////////////////////////// //Directory service API URL @@ -647,6 +664,53 @@ exports.CoreIoApi = Montage.create(Component, { } }, //////////////////////////////////////////////////////////////////// + // Reads an external file (cross-domain) + // Parameters: + // the file parameter must contain the following properties + // url: string value containing the full file path/URL i.e. "http://google.com/motorola.html" + // binary parameter is optional if the content is to be binary + // Return values: + // returns an object with two properties + // success: boolean indicating if the call succeeded or failed + // content: string containing the file contents + // status: int indicating the request HTTP status code + // 200 - the file was read and its contents were returned + // 404 - the file does not exist + // 500 - unknown server error occurred + readExternalFile: { + enumerable: false, + value: function(file) { + // + var retValue = {success:null, content:null, status:null}; + // + if(file && file.url && file.url.length) { + try { + var serviceURL = this._prepareServiceURL(this.webServiceURL, ''), + xhr = new XMLHttpRequest(); + // + xhr.open("GET", serviceURL+"?url="+file.url, false); + if (file.binary) xhr.setRequestHeader("return-type", "binary"); + xhr.setRequestHeader("Content-Type", "text/plain"); + xhr.send(); + // + if (xhr.readyState === 4) { + retValue.status = xhr.status; + if(xhr.status == 200) { + retValue.content = xhr.response; + } + retValue.success = true; + } + } + catch(error) { + xhr = null; + retValue.success = false; + } + } + // + return retValue; + } + }, + //////////////////////////////////////////////////////////////////// // Create a new directory/folder // Parameters: // the dir parameter must contain the following properties -- cgit v1.2.3