JAL-4012 tweak release notes wording for legacy.uniprot
[jalview.git] / examples / biojson-doc / docson-swagger.js
1 /*
2  * Copyright 2013 Laurent Bovet <laurent.bovet@windmaster.ch>
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 var allDefinitions;
18 var counter = 0;
19
20 function createDoc(definitions, type) {
21     counter++;
22     var docson = "/docson/index.html";
23     if(!allDefinitions) {
24         allDefinitions = {};
25         function receiveMessage(event) {
26             if (event.data.id && event.data.id == "docson") {
27                 var frame = $("#docson-"+event.data.url.split("$")[2]);
28                 if (event.data.action == "resized") {
29                     frame.get(0).width = event.data.width + 18;
30                     frame.get(0).height = event.data.height + 36;
31                     frame.parents("td").width(event.data.width + 24)
32                 }
33                 if (event.data.action == "ready") {
34                     frame.get(0).contentWindow.postMessage({ id: "docson", action: "load", definitions: allDefinitions, type: event.data.url.split("$")[1]}, "*");
35                 }
36             }
37         }
38         window.addEventListener("message", receiveMessage, false);
39     }
40     $.extend(allDefinitions, definitions);
41     return "<iframe class='docson-frame' id='docson-" + counter + "' style='padding: 0; border: 0; width:100%; background: transparent' src='" + docson + "#$" + type + "$"+counter+"'></iframe>"
42 }
43
44 SwaggerOperation.prototype.getSignature = function(type, models) {
45     var collectionType, isPrimitive;
46     if(this.isCollectionType) {
47         collectionType = this.isCollectionType(type);
48     } else {
49         collectionType = this.isListType(type);
50     }
51     isPrimitive = ((collectionType != null) && models[collectionType]) || (models[type] != null) ? false : true;
52     if (isPrimitive) {
53         return type;
54     } else {
55         if (collectionType != null) {
56             return "<p class='stronger'>" + type + "</p>" + createDoc(this.resource.rawModels, collectionType);
57         } else {
58             return createDoc(this.resource.rawModels, type);
59         }
60     }
61 };
62
63 $(document).on("click", ".toggleOperation", function() {
64     $(this).parents(".operations").find(".docson-frame").each(function(k, frame) {
65         frame.contentWindow.postMessage({id: "docson", action: "resize"}, "*");
66     });
67 });