From 09f1006315c29b4b67416c498dc787704e7eae91 Mon Sep 17 00:00:00 2001 From: Alexandre Terrasa Date: Tue, 18 Feb 2014 18:25:34 -0500 Subject: [PATCH] nitdoc: migrate github modalbox to JQuery.UI widget ModalBox plugin is now standalone and can be used without github plugin Signed-off-by: Alexandre Terrasa Conflicts: src/nitdoc.nit --- share/nitdoc/js/plugins/github.js | 135 +++++++++++++++++++++------- share/nitdoc/js/plugins/github/modalbox.js | 82 ----------------- share/nitdoc/js/plugins/modalbox.js | 101 +++++++++++++++++++++ share/nitdoc/styles/Nitdoc.GitHub.css | 62 +------------ share/nitdoc/styles/Nitdoc.ModalBox.css | 108 ++++++++++++++++++++++ share/nitdoc/styles/main.css | 8 +- src/nitdoc.nit | 1 + 7 files changed, 316 insertions(+), 181 deletions(-) delete mode 100644 share/nitdoc/js/plugins/github/modalbox.js create mode 100644 share/nitdoc/js/plugins/modalbox.js create mode 100644 share/nitdoc/styles/Nitdoc.ModalBox.css diff --git a/share/nitdoc/js/plugins/github.js b/share/nitdoc/js/plugins/github.js index 5b8ca2f..92405d9 100644 --- a/share/nitdoc/js/plugins/github.js +++ b/share/nitdoc/js/plugins/github.js @@ -24,12 +24,12 @@ define([ "jquery", "github-api", + "plugins/modalbox", "plugins/github/loginbox", - "plugins/github/modalbox", "plugins/github/commentbox", "utils", "Markdown.Converter" -], function($, GithubAPI, LoginBox, ModalBox, CommentBox) { +], function($, GithubAPI) { var GithubUser = function(login, password, repo, branch) { this.login = login; this.password = password; @@ -92,11 +92,13 @@ define([ _checkLoginInfos: function(infos) { if(!infos.login || !infos.password || !infos.repo || !infos.branch) { - ModalBox.open( - "Sign in error", - "Please enter your GitHub username, password, repository and branch.", - true - ); + $("

") + .text("Please enter your GitHub username, password, repository and branch.") + .modalbox({ + title: "Sign in error", + isError: true + }) + .modalbox("open"); return false; } else { return true; @@ -110,25 +112,31 @@ define([ this.activate(this.user, this.origin); } else { if(isok == "error:login") { - ModalBox.open( - "Sign in error", - "The username, password, repo or branch you entered is incorrect.", - true - ); + $("

") + .text("The username, password, repo or branch you entered is incorrect.") + .modalbox({ + title: "Github sign in error", + isError: true + }) + .modalbox("open"); } else if(isok == "error:sha") { - ModalBox.open( - "Base commit not found", - "The provided Github repository must contain the base commit '" + UI.origin.sha + "'", - true - ); + $("

") + .text("The provided Github repository must contain the base commit '" + UI.origin.sha + "'.") + .modalbox({ + title: "Github base commit error", + isError: true + }) + .modalbox("open"); } else if(isok == "error:profile") { - ModalBox.open( - "Incomplete Github profile", - "Please set your public name and email in your " + + $("

") + .text("Please set your public name and email in your " + "GitHub profile." + - "

Your public profile informations are used to sign-off your commits.", - true - ); + "

Your public profile informations are used to sign-off your commits.") + .modalbox({ + title: "Github profile error", + isError: true + }) + .modalbox("open"); } } } @@ -223,7 +231,12 @@ define([ .bind("commentbox_preview", function(event, data) { var converter = new Markdown.Converter() var html = converter.makeHtml(data.value); - ModalBox.open("Preview", html, false); + $("

") + .html(html) + .modalbox({ + title: "Preview comment" + }) + .modalbox("open"); }) .bind("commentbox_open", function(event, data) { GithubUI.openedComments++; @@ -318,7 +331,13 @@ define([ edit.newContent = this._mergeComment(edit.oldContent, edit.newComment, edit.location); edit.request = this._pushChanges(edit) if(!edit.request) { - ModalBox.open("Unable to commit changes!", response, true); + $("

") + .text("Unable to commit changes.
" + response) + .modalbox({ + title: "Github commit error", + isError: true + }) + .modalbox("open"); return; } this._saveRequest(edit); @@ -349,31 +368,61 @@ define([ _pushChanges: function(edit) { var baseTree = GithubAPI.getTree(this.user, this.origin.sha); if(!baseTree.sha) { - ModalBox.open("Unable to locate base tree!", baseTree.status + ": " + baseTree.statusText, true); + $("

") + .text("Unable to locate base tree.
" + baseTree.status + ": " + baseTree.statusText) + .modalbox({ + title: "Github commit error", + isError: true + }) + .modalbox("open"); return false; } console.log("Base tree: " + baseTree.url); var newBlob = GithubAPI.createBlob(this.user, edit.newContent); if(!newBlob.sha) { - ModalBox.open("Unable to create new blob!", newBlob.status + ": " + newBlob.statusText, true); + $("

") + .text("Unable to create new blob.
" + newBlob.status + ": " + newBlob.statusText) + .modalbox({ + title: "Github commit error", + isError: true + }) + .modalbox("open"); return false; } console.log("New blob: " + newBlob.url); var newTree = GithubAPI.createTree(this.user, baseTree, edit.location.path, newBlob); if(!newTree.sha) { - ModalBox.open("Unable to create new tree!", newTree.status + ": " + newTree.statusText, true); + $("

") + .text("Unable to create new tree.
" + newTree.status + ": " + newTree.statusText) + .modalbox({ + title: "Github commit error", + isError: true + }) + .modalbox("open"); return false; } console.log("New tree: " + newTree.url); var newCommit = GithubAPI.createCommit(this.user, edit.message, baseTree.sha, newTree); if(!newCommit.sha) { - ModalBox.open("Unable to create new commit!", newCommit.status + ": " + newCommit.statusText, true); + $("

") + .text("Unable to create new commit.
" + newCommit.status + ": " + newCommit.statusText) + .modalbox({ + title: "Github commit error", + isError: true + }) + .modalbox("open"); return false; } console.log("New commit: " + newCommit.url); var pullRequest = GithubAPI.createPullRequest(this.user, edit.title, "Pull request from Nitdoc", this.origin, newCommit.sha); if(!pullRequest.number) { - ModalBox.open("Unable to create pull request!", pullRequest.status + ": " + pullRequest.statusText, true); + $("

") + .text("Unable to create pull request.
" + pullRequest.status + ": " + pullRequest.statusText) + .modalbox({ + title: "Github commit error", + isError: true + }) + .modalbox("open"); return false; } console.log("New pull request: " + pullRequest.url); @@ -384,13 +433,25 @@ define([ _closePullRequest: function(number) { var requests = JSON.parse(localStorage.requests); if(!requests[number]) { - ModalBox.open("Unable to close pull request!", "Pull request " + number + "not found", true); + $("

") + .text("Unable to close pull request.
" + "Pull request " + number + "not found") + .modalbox({ + title: "Github commit error", + isError: true + }) + .modalbox("open"); return false; } // close pull request var res = GithubAPI.updatePullRequest(this.user, "Closed from Nitdoc", "", "closed", requests[number].request); if(!res.id) { - ModalBox.open("Unable to close pull request!", res.status + ": " + res.statusText, true); + $("

") + .text("Unable to close pull request.
" + res.status + ": " + res.statusText) + .modalbox({ + title: "Github commit error", + isError: true + }) + .modalbox("open"); return false; } // update in localstorage @@ -413,7 +474,13 @@ define([ _getFileContent: function(githubUrl) { var origFile = GithubAPI.getFile(this.user, githubUrl); if(!origFile.content) { - ModalBox.open("Unable to locate source file!", origFile.status + ": " + origFile.statusText, true); + $("

") + .text("Unable to locate source file.
" + origFile.status + ": " + origFile.statusText) + .modalbox({ + title: "Github commit error", + isError: true + }) + .modalbox("open"); return; } var base64Content = origFile.content.substring(0, origFile.content.length - 1) @@ -458,7 +525,7 @@ define([ _doUpdateRequest: function(event, baseArea, request) { baseArea.commentbox("open", this.user, request.request.number); - } + }, } // Get github plugin data diff --git a/share/nitdoc/js/plugins/github/modalbox.js b/share/nitdoc/js/plugins/github/modalbox.js deleted file mode 100644 index 6070a3e..0000000 --- a/share/nitdoc/js/plugins/github/modalbox.js +++ /dev/null @@ -1,82 +0,0 @@ -/* This file is part of NIT ( http://www.nitlanguage.org ). - - 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. - - Documentation generator for the nit language. - Generate API documentation in HTML format from nit source code. -*/ - -/* - * Nitdoc.GitHub.ModalBox class - */ -define([ - "jquery", -], function($) { - // Init new modal box instance - //TODO use DJQuery.UI Dialog: https://jqueryui.com/dialog/#modal-message - var ModalBox = { - - // Open modal box instance - open: function(title, content, isError) { - $("body").append( - $(document.createElement("div")) - .attr("id", "nitdoc-github-modal-fade") - .addClass("nitdoc-github-fade") - ) - .append( - $(document.createElement("div")) - .attr("id", "nitdoc-github-modal") - .addClass("nitdoc-github-modal") - .append( - $(document.createElement("a")) - .addClass("nitdoc-github-close") - .attr("title", "Close") - .append("x") - .click(function() { ModalBox.close() }) - ) - .append("

" + title + "

") - .append("
" + content + "
") - .append( - $(document.createElement("div")) - .addClass("nitdoc-github-buttons") - .append( - $(document.createElement("button")) - .addClass("nitdoc-github-button") - .append("Ok") - .click(function() { ModalBox.close() }) - ) - ) - ); - - if(isError) { - $("#nitdoc-github-modal").addClass("nitdoc-github-error"); - } - - $("#nitdoc-github-modal") - .css({ - top: "50%", - marginTop: -($("#nitdoc-github-modal").outerHeight() / 2) + "px", - left: "50%", - marginLeft: -($("#nitdoc-github-modal").outerWidth() / 2) + "px" - }) - .find("button.nitdoc-github-button").focus(); - }, - - // Close modal box instance - close: function() { - $("#nitdoc-github-modal").remove(); - $("#nitdoc-github-modal-fade").remove(); - } - }; - return ModalBox; -}); diff --git a/share/nitdoc/js/plugins/modalbox.js b/share/nitdoc/js/plugins/modalbox.js new file mode 100644 index 0000000..86e244f --- /dev/null +++ b/share/nitdoc/js/plugins/modalbox.js @@ -0,0 +1,101 @@ +/* This file is part of NIT ( http://www.nitlanguage.org ). + + 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. + + Documentation generator for the nit language. + Generate API documentation in HTML format from nit source code. +*/ + +define([ + "jquery", + "jQueryUI" +], function($) { + $.widget("nitdoc.modalbox", { + options: { + id: "nitdoc-dialog", + title: "Title", + isError: false, + }, + + _create: function() { + this._addFade(); + this._makeDialog(); + }, + + open: function() { + this._dialog + .show() + .css({ + top: "50%", + marginTop: -(this._dialog.outerHeight() / 2) + "px", + left: "50%", + marginLeft: -(this._dialog.outerWidth() / 2) + "px" + }) + .find(".nitdoc-dialog-buttons button:first").focus(); + + this._fade.show(); + }, + + close: function() { + this._fade.hide(); + this._dialog.hide(); + }, + + _addFade: function() { + this._fade = $("
") + .hide() + .attr("id", "nitdoc-dialog-fade-" + this.options.id) + .addClass("nitdoc-dialog-fade"); + $("body").append(this._fade); + }, + + _makeDialog: function() { + this._dialog = $("
") + .hide() + .attr("id", this.options.id) + .addClass("nitdoc-dialog") + .append( + $("
") + .addClass("nitdoc-dialog-header") + .append( + $("

") + .text(this.options.title) + ) + .append( + $("