X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=examples%2Fbiojson-doc%2Fdocson-swagger.js;fp=examples%2Fbiojson-doc%2Fdocson-swagger.js;h=80ffaafad0a3744145f80d35cefe2bba400d6066;hb=fddf3084802b37e5cee17829e32692a4aac3e60d;hp=0000000000000000000000000000000000000000;hpb=7e5b8f22ed3a1b76f6389a4c7d6b7ebc7f9bf74d;p=jalview.git diff --git a/examples/biojson-doc/docson-swagger.js b/examples/biojson-doc/docson-swagger.js new file mode 100755 index 0000000..80ffaaf --- /dev/null +++ b/examples/biojson-doc/docson-swagger.js @@ -0,0 +1,67 @@ +/* + * Copyright 2013 Laurent Bovet + * + * 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. + */ + +var allDefinitions; +var counter = 0; + +function createDoc(definitions, type) { + counter++; + var docson = "/docson/index.html"; + if(!allDefinitions) { + allDefinitions = {}; + function receiveMessage(event) { + if (event.data.id && event.data.id == "docson") { + var frame = $("#docson-"+event.data.url.split("$")[2]); + if (event.data.action == "resized") { + frame.get(0).width = event.data.width + 18; + frame.get(0).height = event.data.height + 36; + frame.parents("td").width(event.data.width + 24) + } + if (event.data.action == "ready") { + frame.get(0).contentWindow.postMessage({ id: "docson", action: "load", definitions: allDefinitions, type: event.data.url.split("$")[1]}, "*"); + } + } + } + window.addEventListener("message", receiveMessage, false); + } + $.extend(allDefinitions, definitions); + return "" +} + +SwaggerOperation.prototype.getSignature = function(type, models) { + var collectionType, isPrimitive; + if(this.isCollectionType) { + collectionType = this.isCollectionType(type); + } else { + collectionType = this.isListType(type); + } + isPrimitive = ((collectionType != null) && models[collectionType]) || (models[type] != null) ? false : true; + if (isPrimitive) { + return type; + } else { + if (collectionType != null) { + return "

" + type + "

" + createDoc(this.resource.rawModels, collectionType); + } else { + return createDoc(this.resource.rawModels, type); + } + } +}; + +$(document).on("click", ".toggleOperation", function() { + $(this).parents(".operations").find(".docson-frame").each(function(k, frame) { + frame.contentWindow.postMessage({id: "docson", action: "resize"}, "*"); + }); +});