nitdoc: merge js utils and base64 into lib/utils
[nit.git] / share / nitdoc / js / plugins / github / modalbox.js
1 /* This file is part of NIT ( http://www.nitlanguage.org ).
2
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6
7 http://www.apache.org/licenses/LICENSE-2.0
8
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14
15 Documentation generator for the nit language.
16 Generate API documentation in HTML format from nit source code.
17 */
18
19 /*
20 * Nitdoc.GitHub.ModalBox class
21 */
22 define([
23 "jquery",
24 ], function($) {
25 // Init new modal box instance
26 //TODO use DJQuery.UI Dialog: https://jqueryui.com/dialog/#modal-message
27 var ModalBox = {
28
29 // Open modal box instance
30 open: function(title, content, isError) {
31 $("body").append(
32 $(document.createElement("div"))
33 .attr("id", "nitdoc-github-modal-fade")
34 .addClass("nitdoc-github-fade")
35 )
36 .append(
37 $(document.createElement("div"))
38 .attr("id", "nitdoc-github-modal")
39 .addClass("nitdoc-github-modal")
40 .append(
41 $(document.createElement("a"))
42 .addClass("nitdoc-github-close")
43 .attr("title", "Close")
44 .append("x")
45 .click(function() { ModalBox.close() })
46 )
47 .append("<h3>" + title + "</h3>")
48 .append("<div>" + content + "</div>")
49 .append(
50 $(document.createElement("div"))
51 .addClass("nitdoc-github-buttons")
52 .append(
53 $(document.createElement("button"))
54 .addClass("nitdoc-github-button")
55 .append("Ok")
56 .click(function() { ModalBox.close() })
57 )
58 )
59 );
60
61 if(isError) {
62 $("#nitdoc-github-modal").addClass("nitdoc-github-error");
63 }
64
65 $("#nitdoc-github-modal")
66 .css({
67 top: "50%",
68 marginTop: -($("#nitdoc-github-modal").outerHeight() / 2) + "px",
69 left: "50%",
70 marginLeft: -($("#nitdoc-github-modal").outerWidth() / 2) + "px"
71 })
72 .find("button.nitdoc-github-button").focus();
73 },
74
75 // Close modal box instance
76 close: function() {
77 $("#nitdoc-github-modal").remove();
78 $("#nitdoc-github-modal-fade").remove();
79 }
80 };
81 return ModalBox;
82 });