/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 * 
 * Contributors: IBM Corporation - initial API and implementation
 ******************************************************************************/
/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/*******************************************************************************
 * @license
 * Copyright (c) 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/*******************************************************************************
 * @license
 * Copyright (c) 2010, 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 * 
 * Contributors: IBM Corporation - initial API and implementation
 ******************************************************************************/
/**
 * @license RequireJS domReady 1.0.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
 * Available via the MIT or new BSD license.
 * see: http://github.com/jrburke/requirejs for details
 */
/*******************************************************************************
 * @license
 * Copyright (c) 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
/*******************************************************************************
 * @license
 * Copyright (c) 2010, 2011 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials are made 
 * available under the terms of the Eclipse Public License v1.0 
 * (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 * License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 
 * 
 * Contributors: IBM Corporation - initial API and implementation
 ******************************************************************************/
/*

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors:
 IBM Corporation - initial API and implementation

 Copyright (c) 2010, 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation
 RequireJS domReady 1.0.0 Copyright (c) 2010-2011, The Dojo Foundation All Rights Reserved.
 Available via the MIT or new BSD license.
 see: http://github.com/jrburke/requirejs for details

 Copyright (c) 2010, 2011 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors: IBM Corporation - initial API and implementation

 Copyright (c) 2012 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors:
 IBM Corporation - initial API and implementation

 Copyright (c) 2011 IBM Corporation and others.
 All rights reserved. This program and the accompanying materials are made 
 available under the terms of the Eclipse Public License v1.0 
 (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution 
 License v1.0 (http://www.eclipse.org/org/documents/edl-v10.html). 

 Contributors:
 IBM Corporation - initial API and implementation
*/
(function(){var h=this;if(!h.define)h.define=function(e){h.orion=h.orion||{};h.orion.Deferred=e();delete h.define}})();
define("orion/Deferred",[],function(){function h(i){if(c)d?(f.next={notify:i,next:null},f=f.next):f=d={notify:i,next:null};else{c=!0;do{for(;i;){i();if(b)d?f.next=b:d=b,f=a;d?(b=d.next,a=f,i=d.notify,d=f=null):i=null}c=!1}while(c)}}function e(){function a(){for(;d;){var i=d;d=d.next;var e=i.deferred;if(i[c])try{var f=i[c](b);f&&typeof f.then==="function"?f.then(e.resolve,e.reject,e.update):e.resolve(f)}catch(h){e.reject(h)}else e[c](b)}d=g=null}var b,c,d,g;this.resolve=function(e){if(c)throw Error("'"+
c+"' already called");c="resolve";b=e;h(a)};this.reject=function(e){if(c)throw Error("'"+c+"' already called");c="reject";b=e;h(a)};this.update=this.progress=this.notify=function(a){for(var c=d;c;){if(c.update)try{c.update(a)}catch(b){}c=c.next}};this.then=function(b,l,f){b={resolve:b,reject:l,update:f,deferred:new e};d?g.next=b:d=b;g=b;c&&h(a);return b.deferred.promise};this.promise={then:this.then};this.state=function(){return c||"wait"};this.all=function(a,b){function e(a,b){c||(l[a]=b,--d===0&&
g.resolve(l))}function i(a,d){if(!c){if(b)try{e(a,b(d));return}catch(l){d=l}g.reject(d)}}var d=a.length,l=[],g=this;d===0?this.resolve(l):a.forEach(function(a,b){a.then(e.bind(null,b),i.bind(null,b))});return this.promise}}var d,f,b,a,c=!1;e.when=function(a,b,c,d){var g;if(!(a&&typeof a.then==="function"))g=new e,g.resolve(a),a=g.promise;return a.then(b,c,d)};return e});
define("orion/xhr",["orion/Deferred"],function(h){function e(e){return encodeURIComponent(e).replace(/[!'()*]/g,function(e){return"%"+e.charCodeAt(0).toString(16).toUpperCase()})}return function(d,f,b){var b=b||{},a=arguments.length>3&&arguments[3]?arguments[3]:new XMLHttpRequest,c=new h,i=b.headers||{},l=b.log||!1,j,k;typeof i["X-Requested-With"]==="undefined"&&(i["X-Requested-With"]="XMLHttpRequest");if(b.query&&typeof b.query==="object"){var g=b.query,n=Object.keys(g),m=[];for(k=0;k<n.length;k++){var o=
n[k],r=g[o];m.push(e(o)+"="+e(r))}m.length&&(g=f.split("#"),g[0]+=(g[0].indexOf("?")===-1?"?":"&")+m.join("&"),f=g.join("#"))}if(typeof b.data!=="undefined"&&(d==="POST"||d==="PUT"))j=b.data;if(typeof b.responseType==="string")a.responseType=b.responseType;a.onreadystatechange=function(){if(a.readyState===4){var e=a.status,d=typeof a.response!=="undefined"?a.response:a.responseText,d={args:b,response:d,responseText:typeof d==="string"?d:null,status:e,url:f,xhr:a};200<=e&&e<400?c.resolve(d):(l&&console&&
console.log(Error(a.statusText)),c.reject(d))}};try{a.open(d,f,!0);if(typeof b.timeout==="number")a.timeout=b.timeout,a.addEventListener("timeout",function(a){c.reject("Timeout exceeded: "+a)});var q=Object.keys(i);for(k=0;k<q.length;k++){var p=q[k];a.setRequestHeader(p,i[p])}a.send(j)}catch(s){c.reject(s)}return c}});
define("orion/es5shim",[],function(){if(!Function.prototype.bind)Function.prototype.bind=function(h){var e=this,d=Array.prototype.slice.call(arguments,1);return d.length?function(){return arguments.length?e.apply(h,d.concat(Array.prototype.slice.call(arguments))):e.apply(h,d)}:function(){return arguments.length?e.apply(h,arguments):e.call(h)}}});
define("plugins/filePlugin/fileImpl",["orion/Deferred","orion/xhr","orion/es5shim"],function(h,e){function d(b,a){this.fileBase=b;this.workspaceBase=a}function f(b,a,c,e){var d=new h,j=new XMLHttpRequest,f;try{j.open(b,a);if(c!==null)for(f in c)c.hasOwnProperty(f)&&j.setRequestHeader(f,c[f]);j.responseType="arraybuffer";j.send(e);j.onreadystatechange=function(){j.readyState===4&&d.resolve({status:j.status,statusText:j.statusText,headers:j.getAllResponseHeaders(),response:j.response})}}catch(g){d.reject(g)}return d}
d.prototype={fetchChildren:function(b){return b===this.fileBase?this.loadWorkspace(b).then(function(a){return a.Children||[]}):e("GET",b,{headers:{"Orion-Version":"1","Content-Type":"charset=UTF-8"},timeout:15E3}).then(function(a){return(a.response?JSON.parse(a.response):{}).Children||[]})},_createWorkspace:function(b){return e("POST",this.workspaceBase,{headers:{"Orion-Version":"1",Slug:b},timeout:15E3}).then(function(a){return(a.response?JSON.parse(a.response):{}).Workspaces})},loadWorkspaces:function(){return e("GET",
this.workspaceBase,{headers:{"Orion-Version":"1"},timeout:15E3}).then(function(b){return(b.response?JSON.parse(b.response):{}).Workspaces})},loadWorkspace:function(b){b===this.fileBase&&(b=null);return e("GET",b?b:this.workspaceBase,{headers:{"Orion-Version":"1"},timeout:15E3,log:!1}).then(function(a){a=a.response?JSON.parse(a.response):{};return b?a:a.Workspaces.length>0?this.loadWorkspace(a.Workspaces[0].Location):this._createWorkspace("MyWorkspace")}.bind(this))},createProject:function(b,a,c,d){if(b){a=
{Name:a};if(c)a.ContentLocation=c;if(d)a.CreateIfDoesntExist=d;return e("POST",b,{headers:{"Orion-Version":"1","Content-Type":"application/json;charset=UTF-8"},timeout:15E3,data:JSON.stringify(a)}).then(function(a){return a.response?JSON.parse(a.response):null})}else console.error("url is undefined, make sure you're signed in before creating a project")},createFolder:function(b,a){return e("POST",b,{headers:{"Orion-Version":"1","X-Create-Options":"no-overwrite",Slug:a,"Content-Type":"application/json;charset=UTF-8"},
data:JSON.stringify({Name:a,LocalTimeStamp:"0",Directory:"true"}),timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):null})},createFile:function(b,a){return e("POST",b,{headers:{"Orion-Version":"1","X-Create-Options":"no-overwrite",Slug:a,"Content-Type":"application/json;charset=UTF-8"},data:JSON.stringify({Name:a,LocalTimeStamp:"0",Directory:"false"}),timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):null})},deleteFile:function(b){return e("DELETE",b,
{headers:{"Orion-Version":"1"},timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):null})},moveFile:function(b,a,c){return this._doCopyMove(b,a,!0,c)},copyFile:function(b,a,c){return this._doCopyMove(b,a,!1,c)},_doCopyMove:function(b,a,c,d){d||(d=b.split("/"),d=d.pop()||d.pop());return e("POST",a,{headers:{"Orion-Version":"1",Slug:d,"X-Create-Options":"no-overwrite,"+(c?"move":"copy"),"Content-Type":"application/json;charset=UTF-8"},data:JSON.stringify({Location:b,Name:d}),timeout:15E3}).then(function(a){return a.response?
JSON.parse(a.response):null})},read:function(b,a){return e("GET",b,{timeout:5E3,headers:{"Orion-Version":"1"},log:!1,query:a?{parts:"meta"}:{}}).then(function(b){return a?b.response?JSON.parse(b.response):null:b.response})},write:function(b,a,c){var d={"Orion-Version":"1","Content-Type":"text/plain;charset=UTF-8"};if(c&&c.ETag)d["If-Match"]=c.ETag;c={timeout:5E3,headers:d,data:a,log:!1};if(typeof a!=="string")a.sourceLocation?(c.query={source:a.sourceLocation},c.data=null):c.query={parts:"meta"};
return e("PUT",b,c).then(function(a){return a.response?JSON.parse(a.response):null})},remoteImport:function(b,a){var c={"Orion-Version":"1"};if(a.OptionHeader)c["X-Xfer-Options"]=a.OptionHeader;return e("POST",b,{headers:c,data:JSON.stringify(a),timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):null})},remoteExport:function(b,a){var c={"Orion-Version":"1"};if(a.OptionHeader)c["X-Xfer-Options"]=a.OptionHeader;return e("POST",b,{headers:c,data:JSON.stringify(a),timeout:15E3}).then(function(a){return a.response?
JSON.parse(a.response):null})},search:function(b,a){return e("GET","/filesearch"+a,{headers:{Accept:"application/json","Orion-Version":"1"},timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):{}})}};window.BlobBuilder=window.MozBlobBuilder||window.WebKitBlobBuilder||window.BlobBuilder;if(window.BlobBuilder)d.prototype.readBlob=function(b){return f("GET",b).then(function(a){if(window.WebKitBlobBuilder){var b=new BlobBuilder;b.append(a.response);return b.getBlob()}return a.response})},
d.prototype.writeBlob=function(b,a,c){var d={};if(c&&c.ETag)d["If-Match"]=c.ETag;a.type||(c=new BlobBuilder,a&&c.append(a),a=c.getBlob());return f("PUT",b,d,a)};return d});
define("domReady",[],function(){function h(a){for(var b=0,d;d=a[b];b++)d(c)}function e(){var b=i,c=l;a&&(b.length&&(i=[],h(b)),j.resourcesDone&&c.length&&(l=[],h(c)))}function d(){a||(a=!0,g&&clearInterval(g),e())}function f(b){a?b(c):i.push(b);return f}var b=typeof window!=="undefined"&&window.document,a=!b,c=b?document:null,i=[],l=[],j=requirejs||require||{},k=j.resourcesReady,g;if("resourcesReady"in j)j.resourcesReady=function(a){k&&k(a);a&&e()};b&&(document.addEventListener?(document.addEventListener("DOMContentLoaded",
d,!1),window.addEventListener("load",d,!1)):window.attachEvent&&(window.attachEvent("onload",d),self===self.top&&(g=setInterval(function(){try{document.body&&(document.documentElement.doScroll("left"),d())}catch(a){}},30))),document.readyState==="complete"&&d());f.withResources=function(b){a&&j.resourcesDone?b(c):l.push(b);return f};f.version="1.0.0";f.load=function(a,b,c,d){d.isBuild?c(null):f(c)};return f});var eclipse=eclipse||{};
eclipse.ServiceProvider=function(h,e){this.dispatchEvent=function(d){e.dispatchEvent.apply(e,[h,d].concat(Array.prototype.slice.call(arguments,1)))};this.unregister=function(){e.unregisterServiceProvider(h)}};
eclipse.PluginProvider=function(h){function e(a){c&&(typeof ArrayBuffer==="undefined"&&(a=JSON.stringify(a)),c===self?c.postMessage(a):c.postMessage(a,"*"))}function d(a,b){return b&&b instanceof XMLHttpRequest?{status:b.status,statusText:b.statusText}:b}function f(a){if(a.source===c){var f=typeof a.data!=="string"?a.data:JSON.parse(a.data),a=b[f.serviceId].implementation,h=a[f.method],g={id:f.id,result:null,error:null};try{var i=h.apply(a,f.params);i&&typeof i.then==="function"?i.then(function(a){g.result=
a;e(g)},function(a){g.error=a?JSON.parse(JSON.stringify(a,d)):a;e(g)},function(){e({requestId:f.id,method:"progress",params:Array.prototype.slice.call(arguments)})}):(g.result=i,e(g))}catch(m){g.error=m?JSON.parse(JSON.stringify(m,d)):m,e(g)}}}var b=[],a=!1,c=null,i={dispatchEvent:function(b,c){if(!a)throw Error("Cannot dispatchEvent. Plugin Provider not connected");var d={serviceId:b,method:"dispatchEvent",params:[c].concat(Array.prototype.slice.call(arguments,2))};e(d)},unregisterServiceProvider:function(c){if(a)throw Error("Cannot unregister. Plugin Provider is connected");
b[c]=null}};this.registerServiceProvider=function(c,d,e){if(a)throw Error("Cannot register. Plugin Provider is connected");var f=null,h=[];for(f in d)typeof d[f]==="function"&&h.push(f);f=b.length;b[f]={type:c,methods:h,implementation:d,properties:e||{}};return new eclipse.ServiceProvider(f,i)};this.connect=function(d,i){if(!a){if(typeof window==="undefined")c=self;else if(window!==window.parent)c=window.parent;else if(window.opener!==null)c=window.opener;else{i&&i("No valid plugin target");return}addEventListener("message",
f,!1);for(var k=[],g=0;g<b.length;g++)b[g]&&k.push({serviceId:g,type:b[g].type,methods:b[g].methods,properties:b[g].properties});e({method:"plugin",params:[{services:k,metadata:h||{}}]});a=!0}d&&d()};this.disconnect=function(){a&&(removeEventListener("message",f),c=null,a=!1)}};define("orion/plugin",function(){});
define("plugins/fileClientPlugin",["orion/Deferred","plugins/filePlugin/fileImpl","domReady!","orion/plugin"],function(h,e){function d(a){try{if(window.location.host===parent.location.host&&window.location.protocol===parent.location.protocol)return a.substring(parent.location.href.indexOf(parent.location.host)+parent.location.host.length)}catch(b){}return a}var f=new eclipse.PluginProvider,b=document.createElement("a");b.href="../file";var a=d(b.href);b.href="../workspace";var c=d(b.href);b.href=
"..";b=d(b.href);c=new e(a,c);f.registerServiceProvider("orion.core.file",c,{Name:"Orion Content",top:a,pattern:b});c.dispatchEvent=f.dispatchEvent;f.connect()});