This repository was archived by the owner on Feb 6, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjquery.res.min.js
More file actions
16 lines (16 loc) · 7.81 KB
/
Copy pathjquery.res.min.js
File metadata and controls
16 lines (16 loc) · 7.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
/*!
* Copyright 2016 Hochschule der Medien (HdM) / Stuttgart Media University
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
!function(t){"use strict";t.res=function(e,r){function n(){this.queries=[]}function s(t){this._parent=t||null,this.start=null,this.count=null,this.usercontext=[],this.controllercontext=[],this.props=[]}function o(t,e,r,n){this._parent=t||null,this.name=e||null,this.value=r||null,this.descs=n||[]}function i(t,e,r){this.ref=t,this.start=e||void 0,this.count=r||void 0}function u(e){this._nextIndex=0,this.responses=[];var r=this;e.find("response").each(function(e,n){r.responses.push(new a(t(n)))})}function a(e){this._nextIndex=0,this.ref=e.attr("ref")||null,this.expired="true"===e.attr("expired"),this.start=void 0===e.attr("start")?null:parseInt(e.attr("start")),this.count=void 0===e.attr("count")?null:parseInt(e.attr("count")),this.total=void 0===e.attr("total")?null:parseInt(e.attr("count")),this.resources=[];var r=this;e.find("resource").each(function(e,n){r.resources.push(new p(t(n)))})}function p(e){this.about=e.attr("about"),this.globalAts=[],this.props=[];var r=this;e.find("globalAt").each(function(e,n){r.globalAts.push(t(n).text())}),e.find("prop").each(function(e,n){var s=new o(null,t(n).attr("name"),t(n).attr("val"));t(n).find("descriptor").each(function(e,r){s.addDesc(t(r).attr("name"),t(r).attr("val"))}),r.props.push(s)})}function h(){this.resources=[],this._dataReadyCounter=0,this._tmpXML=null,this._$deferred=null}function c(t){this._parent=t,this.name=null,this.file=null,this.inherit=void 0,this.props=[]}function l(t){var e=(new XMLSerializer).serializeToString(t[0]);return e.replace(/^<(queries|upload)([^>]*)>/g,"<$1>")}if(e=/\/$/.exec(e)?e:e+"/",!/^https/i.test(e))throw"HTTPS only! The url "+e+" is not secure!";var d={password:null,username:null},f=t.extend({},d,r);return n.prototype.addQuery=function(){var t=new s(this);return this.queries.push(t),t},n.prototype.addRef=function(t,e,r){return this.queries.push(new i(t,e,r)),this},n.prototype.toXMLString=function(){for(var e=t("<queries>"),r=0;r<this.queries.length;r++)e.append(this.queries[r].toXML());return l(e)},n.prototype.send=function(){var r=t.Deferred(),n=this.toXMLString();return console.log(n),t.ajax({url:e+"query",contentType:"text/xml",crossDomain:!0,data:n,dataType:"xml",method:"POST",password:f.password,processData:!1,username:f.username}).done(function(e){r.resolve(new u(t(e)))}).fail(function(t,e,n){r.reject({error:n,status:t.status})}),r.promise()},s.prototype.complete=function(){return this._parent},s.prototype.setStart=function(t){return this.start=t,this},s.prototype.setCount=function(t){return this.count=t,this},s.prototype.addUsercontext=function(t,e){return this.usercontext.push({name:t,value:e}),this},s.prototype.addControllercontext=function(t,e){return this.controllercontext.push({name:t,value:e}),this},s.prototype.addProp=function(t,e,r){return this.props.push(new o(this,t,e,r)),this},s.prototype.addPropWithDescs=function(t,e){var r=new o(this,t,e);return this.props.push(r),r},s.prototype.toXML=function(){var e=t("<query></query>");if(null!==this.start&&e.attr("start",this.start),null!==this.count&&e.attr("count",this.count),this.usercontext.length>0){for(var r=t("<usercontext></usercontext>"),n=0;n<this.usercontext.length;n++){var s=t("<prop>").attr("name",this.usercontext[n].name).attr("val",this.usercontext[n].value);r.append(s)}e.append(r)}if(this.controllercontext.length>0){for(var o=t("<controllercontext></controllercontext>"),i=0;i<this.controllercontext.length;i++)o.append(t("<prop>").attr("name",this.controllercontext[i].name).attr("val",this.controllercontext[i].value));e.append(o)}for(var u=0;u<this.props.length;u++)e.append(this.props[u].toXML());return e},o.prototype.complete=function(){return this._parent},o.prototype.addDesc=function(t,e){return this.descs.push({name:t,value:e}),this},o.prototype.toXML=function(){for(var e=t("<prop>").attr("name",this.name).attr("val",this.value),r=0;r<this.descs.length;r++){var n=t("<descriptor>").attr("name",this.descs[r].name).attr("val",this.descs[r].value);e.append(n)}return e},i.prototype.toXML=function(){return t("<query>").attr("ref",this.ref).attr("start",this.start).attr("count",this.count)},u.prototype.numberOfResponses=function(){return this.responses.length},u.prototype.firstResponse=function(){return this.responses[0]},u.prototype.hasNextResponse=function(){return this._nextIndex<this.responses.length},u.prototype.nextResponse=function(){return this.responses[this._nextIndex++]},u.prototype.resetResponse=function(){return this._nextIndex=0,this},u.prototype.getVeryFirstGlobalAt=function(){return this.firstResponse().firstResource().getFirstGlobalAt()},a.prototype.hasRef=function(){return null!==this.ref},a.prototype.hasMoreOnServer=function(){},a.prototype.numberOfResources=function(){return this.resources.length},a.prototype.firstResource=function(){return this.resources[0]},a.prototype.hasNextResource=function(){return this._nextIndex<this.resources.length},a.prototype.nextResource=function(){return this.resources[this._nextIndex++]},a.prototype.resetResource=function(){return this._nextIndex=0,this},p.prototype.getFirstGlobalAt=function(){return this.globalAts.length>0?this.globalAts[0]:null},h.prototype.addResource=function(){var t=new c(this);return this.resources.push(t),t},h.prototype._dataReady=function(){++this._dataReadyCounter===this.resources.length&&this._realSend()},h.prototype.send=function(){this._tmpXML=t("<upload></upload>");for(var e=0;e<this.resources.length;e++)this._tmpXML.append(this.resources[e].toXML());return this._$deferred=t.Deferred(),this._$deferred.promise()},h.prototype._realSend=function(){var r=l(this._tmpXML),n=this;this._tmpXML=null,this._dataReadyCounter=0,t.ajax({url:e+"upload",contentType:"text/xml",crossDomain:!0,data:r,dataType:"xml",method:"POST",password:f.password,processData:!1,username:f.username,xhrFields:{withCredentials:!0}}).done(function(e){var r=[];t(e).find("resource").each(function(){r.push({status:t(this).attr("status"),name:t(this).attr("name"),message:t(this).find("message").text()})}),n._$deferred.resolve(r)}).fail(function(t,e,r){n._$deferred.reject({error:r,status:t.status})})},c.prototype.complete=function(){return this._parent},c.prototype.setName=function(t){return this.name=t,this},c.prototype.setInherit=function(t){return this.inherit=t,this},c.prototype.setFileInput=function(t){return window.File&&window.FileReader&&window.FileList&&window.Blob?0===t.length?(console.log("Could not find file input."),this):t[0].files[0]?(this.file=t[0].files[0],this):(console.log("No file selected"),this):(console.log("The File APIs are not fully supported in this browser."),this)},c.prototype.addProp=function(t,e,r){return this.props.push(new o(this,t,e,r)),this},c.prototype.addPropWithDescs=function(t,e){var r=new o(this,t,e);return this.props.push(r),r},c.prototype.toXML=function(){for(var e=this,r=t("<resource></resource>"),n=t("<props></props>").attr("inherit",this.inherit),s=0;s<this.props.length;s++)n.append(this.props[s].toXML());r.append(n);var o=t("<resourceData></resourceData>").append(t("<name></name>").text(this.name)),i=new FileReader;return i.onloadend=function(){var r=/^data:([^\/,]+\/[^,;]+)?(;[^,]+)?,(.*)$/g,n=r.exec(i.result);o.append(t("<data></data>").text(n[3])),e._parent._dataReady()},i.readAsDataURL(this.file),r.append(o),r},{queries:function(){return new n},upload:function(){return new h}}}}(jQuery);