/*

 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, 2014 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 2.0.1 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
 Available via the MIT or new BSD license.
 see: http://github.com/requirejs/domReady for details

 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
*/
(function(c,k){"function"===typeof define&&define.amd?define("orion/Deferred",k):"object"===typeof exports?module.exports=k():(c.orion=c.orion||{},c.orion.Deferred=k())})(this,function(){function c(){for(var g;g=a.shift();)g();b=!1}function k(g){a.push(g);b||(b=!0,d())}function f(b){return function(a){b(a)}}function e(){function b(){for(var l;l=n.shift();){var a=l.deferred,m="fulfilled"===h?"resolve":"reject";l=l[m];if("function"===typeof l)try{var g=l(q),d=g&&("object"===typeof g||"function"===typeof g)&&
g.then;if("function"===typeof d)if(g===a.promise)a.reject(new TypeError);else{var e=g.cancel;"function"===typeof e?a._parentCancel=e.bind(g):delete a._parentCancel;d.call(g,f(a.resolve),f(a.reject),f(a.progress))}else a.resolve(g)}catch(c){a.reject(c)}else a[m](q)}}function a(l){delete m._parentCancel;h="rejected";q=l;n.length&&k(b)}function d(l){function c(z){return function(a){(!h||"assumed"===h)&&z(a)}}delete m._parentCancel;try{var f=l&&("object"===typeof l||"function"===typeof l)&&l.then;if("function"===
typeof f)if(l===m)a(new TypeError);else{h="assumed";var t=l&&l.cancel;if("function"!==typeof t){var s=new e;l=s.promise;try{f(s.resolve,s.reject,s.progress)}catch(u){s.reject(u)}t=l.cancel;f=l.then}q=l;f.call(l,c(d),c(a));m._parentCancel=t.bind(l)}else h="fulfilled",q=l,n.length&&k(b)}catch(r){c(a)(r)}}function c(){var b=m._parentCancel;b?(delete m._parentCancel,b()):h||(b=Error("Cancel"),b.name="Cancel",a(b))}var q,h,n=[],m=this;this.resolve=function(a){h||d(a);return m};this.reject=function(b){h||
a(b);return m};this.progress=function(a){h||n.forEach(function(b){if(b.progress)try{b.progress(a)}catch(g){}});return m.promise};this.cancel=function(){m._parentCancel?setTimeout(c,0):c();return m};this.then=function(a,d,c){var f=new e;f._parentCancel=m.promise.cancel;n.push({resolve:a,reject:d,progress:c,deferred:f});("fulfilled"===h||"rejected"===h)&&k(b);return f.promise};this.promise={then:m.then,cancel:m.cancel}}var a=[],b=!1,d=function(){if("undefined"!==typeof process&&"function"===typeof process.nextTick){var a=
process.nextTick;return function(){a(c)}}if("function"===typeof MutationObserver){var b=document.createElement("div");(new MutationObserver(c)).observe(b,{attributes:!0});return function(){b.setAttribute("class","_tick")}}return function(){setTimeout(c,0)}}();e.all=function(a,b){function d(a,b){k||(h[a]=b,0===--f&&m.resolve(h))}function c(a,g){if(!k){if(b)try{d(a,b(g));return}catch(e){g=e}m.reject(g)}}var f=a.length,h=[],k=!1,m=new e;m.then(void 0,function(){k=!0;a.forEach(function(a){a.cancel&&a.cancel()})});
0===f?m.resolve(h):a.forEach(function(a,b){a.then(d.bind(void 0,b),c.bind(void 0,b))});return m.promise};e.when=function(a,b,d,c){var f;a&&"function"===typeof a.then||(f=new e,f.resolve(a),a=f.promise);return a.then(b,d,c)};return e});
define("orion/xhr",["orion/Deferred"],function(c){function k(c,e,a,b){var d="undefined"!==typeof a.response?a.response:a.responseText,g;try{g=a.status}catch(k){g=0}c={args:e,response:d,responseText:"string"===typeof d?d:null,status:g,url:c,xhr:a};"undefined"!==typeof b&&(c.error=b);return c}return function(f,e,a){a=a||{};var b=3<arguments.length&&arguments[3]?arguments[3]:new XMLHttpRequest,d=new c,g=a.headers||{},p=a.log||!1,v;"undefined"===typeof g["X-Requested-With"]&&(g["X-Requested-With"]="XMLHttpRequest");
if("undefined"!==typeof a.data&&("POST"===f||"PUT"===f))v=a.data;var t=!1,q=!1;d.promise.then(void 0,function(a){t=!0;!q&&(a instanceof Error&&"Cancel"===a.name)&&b.abort()});b.onabort=function(){q=!0;if(!t){var a=Error("Cancel");a.name="Cancel";d.reject(a)}};b.onload=function(){var c=k(e,a,b);200<=b.status&&400>b.status?d.resolve(c):(d.reject(c),p&&"undefined"!==typeof console&&console.log(Error(b.statusText)))};b.onerror=function(){var c=k(e,a,b);d.reject(c);p&&"undefined"!==typeof console&&console.log(Error(b.statusText))};
b.onprogress=function(a){a.xhr=b;d.progress(a)};try{b.open(f,e,!0);"string"===typeof a.responseType&&(b.responseType=a.responseType);if("number"===typeof a.timeout)if("number"===typeof b.timeout)b.timeout=a.timeout,b.addEventListener("timeout",function(c){d.reject(k(e,a,b,"Timeout exceeded"))});else{var h=setTimeout(function(){d.reject(k(e,a,b,"Timeout exceeded"))},a.timeout);d.promise.then(clearTimeout.bind(null,h),clearTimeout.bind(null,h))}Object.keys(g).forEach(function(a){b.setRequestHeader(a,
g[a])});b.send(v||null)}catch(n){d.reject(k(e,a,b,n))}return d.promise}});
(function(c,k){"function"===typeof define&&define.amd?define("orion/plugin",["orion/Deferred"],k):"object"===typeof exports?module.exports=k(require("orion/Deferred")):(c.orion=c.orion||{},c.orion.PluginProvider=k(c.orion.Deferred))})(this,function(c){function k(c,e){this.__objectId=c;this.__methods=e}return function(f){function e(a){n&&("undefined"===typeof ArrayBuffer&&(a=JSON.stringify(a)),n===self?n.postMessage(a):n.postMessage(a,"*"))}function a(){var a=[];Object.keys(u).forEach(function(b){var c=
u[b];a.push({serviceId:b,names:c.names,methods:c.methods,properties:c.properties})});return{headers:q||{},services:a}}function b(a,b){if(b&&b instanceof XMLHttpRequest){var c,d;try{c=b.status,d=b.statusText}catch(g){c=0,d=""}return{status:c||0,statusText:d}}return b}function d(a){var c=a?JSON.parse(JSON.stringify(a,b)):a;a instanceof Error&&(c.__isError=!0,c.message=c.message||a.message,c.name=c.name||a.name);return c}function g(a){if(!n)return(new c).reject(Error("plugin not connected"));a.id=String(m++);
var b=new c;x[a.id]=b;b.then(null,function(b){h&&(b instanceof Error&&"Cancel"===b.name)&&r({requestId:a.id,method:"cancel",params:b.message?[b.message]:[]})});var d=Object.prototype.toString;a.params.forEach(function(c,g){if("[object Object]"===d.call(c)&&!(c instanceof k)){var e,f;for(e in c)"[object Function]"===d.call(c[e])&&(f=f||[],f.push(e));if(f){var h=l++;s[h]=c;e=function(){delete s[h]};b.then(e,e);a.params[g]=new k(h,f)}}});r(a);return b.promise}function p(a,b){a||0===a?r({id:a,result:null,
error:b}):console.log(b)}function v(a,b,c,e){e.forEach(function(a,b){if(a&&"undefined"!==typeof a.__objectId){var c={};a.__methods.forEach(function(b){c[b]=function(){return g({objectId:a.__objectId,method:b,params:Array.prototype.slice.call(arguments)})}});e[b]=c}});var f=void 0===typeof a?null:{id:a,result:null,error:null};try{var h=c.apply(b,e);f&&(h&&"function"===typeof h.then?(w[a]=h,h.then(function(b){delete w[a];f.result=b;r(f)},function(b){w[a]&&(delete w[a],f.error=d(b),r(f))},function(){r({responseId:a,
method:"progress",params:Array.prototype.slice.call(arguments)})})):(f.result=h,r(f)))}catch(k){f&&(f.error=d(k),r(f))}}function t(a){if(!(a.source!==n&&"undefined"!==typeof window)){a="string"!==typeof a.data?a.data:JSON.parse(a.data);try{if(a.method){var b=a.method,c=a.params||[];if("serviceId"in a){var d=u[a.serviceId];d||p(a.id,"service not found");d=d.implementation;b in d?v(a.id,d,d[b],c):p(a.id,"method not found")}else if("objectId"in a){var e=s[a.objectId];e||p(a.id,"object not found");!b in
e?v(a.id,e,e[b],c):p(a.id,"method not found")}else if("requestId"in a){var f=w[a.requestId];f&&("cancel"===b&&f.cancel)&&f.cancel.apply(f,c)}else if("responseId"in a){var g=x[a.responseId];g&&("progress"===b&&g.progress)&&g.progress.apply(g,c)}else throw Error("Bad method: "+a.method);}else{var h=x[String(a.id)];delete x[String(a.id)];a.error?h.reject(a.error):h.resolve(a.result)}}catch(k){console.log("Plugin._messageHandler "+k)}}}var q=f,h=!1,n=null,m=0,l=0,y=0,w={},x={},s={},u={},r=e;this.updateHeaders=
function(a){if(h)throw Error("Cannot update headers. Plugin Provider is connected");q=a};this.registerServiceProvider=this.registerService=function(a,b,c){if(h)throw Error("Cannot register service. Plugin Provider is connected");"string"===typeof a?a=[a]:Array.isArray(a)||(a=[]);var d=null,e=[];for(d in b)"function"===typeof b[d]&&e.push(d);u[y++]={names:a,methods:e,implementation:b,properties:c||{},listeners:{}}};this.connect=function(b,c){if(!h){if("undefined"===typeof window)n=self;else if(window!==
window.parent)n=window.parent;else if(null!==window.opener)n=window.opener;else{c&&c("No valid plugin target");return}addEventListener("message",t,!1);var d={method:"plugin",params:[a()]};e(d);h=!0}b&&b()};this.disconnect=function(){h&&(removeEventListener("message",t),n=null,h=!1)}}});
define("domReady",[],function(){function c(){if(!d){d=!0;a&&clearInterval(a);var b=p;if(d&&b.length){p=[];var c;for(c=0;c<b.length;c+=1)b[c](g)}}}function k(a){d?a(g):p.push(a);return k}var f,e,a,b="undefined"!==typeof window&&window.document,d=!b,g=b?document:null,p=[];if(b){if(document.addEventListener)document.addEventListener("DOMContentLoaded",c,!1),window.addEventListener("load",c,!1);else if(window.attachEvent){window.attachEvent("onload",c);e=document.createElement("div");try{f=null===window.frameElement}catch(v){}e.doScroll&&
(f&&window.external)&&(a=setInterval(function(){try{e.doScroll(),c()}catch(a){}},30))}"complete"===document.readyState&&c()}k.version="2.0.1";k.load=function(a,b,c,d){d.isBuild?c(null):k(c)};return k});
define("plugins/preferencesPlugin",["orion/xhr","orion/plugin","domReady!"],function(c,k){function f(a){this.location=a}f.prototype={get:function(a){return c("GET",this.location+a,{headers:{"Orion-Version":"1"},timeout:15E3,log:!1}).then(function(a){return a.response?JSON.parse(a.response):null})},put:function(a,d){return c("PUT",this.location+a,{data:JSON.stringify(d),headers:{"Orion-Version":"1"},contentType:"application/json;charset\x3dUTF-8",timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):
null})},remove:function(a,d){return c("DELETE",this.location+a+"?key\x3d"+encodeURIComponent(d),{headers:{"Orion-Version":"1"},contentType:"application/json;charset\x3dUTF-8",timeout:15E3}).then(function(a){return a.response?JSON.parse(a.response):null})}};var e=document.createElement("a");e.href="../prefs/user";var a=e.href;e.href="../mixloginstatic/LoginWindow.html";e=new k({name:"Orion Preferences",version:"1.0",description:"This plugin provides access to user preferences.",login:e.href});a=new f(a);
e.registerService("orion.core.preference.provider",a,{});e.connect()});
//@ sourceMappingURL=preferencesPlugin.js.map