Skip to content

Commit cec9d1e

Browse files
committed
Initial Import
0 parents  commit cec9d1e

File tree

10 files changed

+4305
-0
lines changed

10 files changed

+4305
-0
lines changed

.gitignore

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# OS or Editor folders
2+
.DS_Store
3+
.idea
4+
npm-debug.log
5+
# Folders to ignore
6+
node_modules
7+
/nbproject/private/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2018 JavaTMP (http://www.javatmp.com)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

dist/bootstrap-actionable.min.js

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

gulpfile.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*!
2+
* bootstrap-actionable v1.0.0 (http://javatmp.com)
3+
* A small Javascript code that help implement click event actions for <a> and <button> tags by declarative way
4+
* and provide functionalities to load AJAX content in Bootstrap Modal Wrapper instance.
5+
*
6+
* Copyright 2018 JavaTMP
7+
* Licensed under MIT (https://github.com/JavaTMP/bootstrap-actionable/blob/master/LICENSE)
8+
*/
9+
10+
var gulp = require('gulp');
11+
var rename = require('gulp-rename');
12+
var uglify = require('gulp-uglify');
13+
var del = require('del');
14+
var eslint = require('gulp-eslint');
15+
16+
gulp.task('clean', function () {
17+
return del(['./dist']);
18+
});
19+
20+
gulp.task('dist', ["clean"], function (cb) {
21+
return gulp.src('./js/bootstrap-actionable.js')
22+
.pipe(eslint({
23+
"env": {"browser": true, "node": true, "jquery": true},
24+
"rules": {
25+
"semi": 2,
26+
"eqeqeq": 1,
27+
"quotes": 0,
28+
"no-trailing-spaces": 1,
29+
"eol-last": 1,
30+
"no-unused-vars": 0,
31+
"no-underscore-dangle": 1,
32+
"no-alert": 1,
33+
"no-lone-blocks": 1
34+
},
35+
"globals": ["jQuery", "$"]
36+
}))
37+
.pipe(eslint.format())
38+
.pipe(uglify({output: {comments: /^!/}}))
39+
.pipe(rename({suffix: '.min'}))
40+
.pipe(gulp.dest('./dist/'));
41+
});
42+
43+
gulp.task('default', ["dist"], function () {
44+
// place code for your default task here
45+
});

js/bootstrap-actionable.js

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/*!
2+
* bootstrap-actionable v1.0.0 (http://javatmp.com)
3+
* A small Javascript code that help implement click event actions for <a> and <button> tags by declarative way
4+
* and provide functionalities to load AJAX content in Bootstrap Modal Wrapper instance.
5+
*
6+
* Copyright 2018 JavaTMP
7+
* Licensed under MIT (https://github.com/JavaTMP/bootstrap-actionable/blob/master/LICENSE)
8+
*/
9+
10+
(function (root, factory) {
11+
"use strict";
12+
// CommonJS module is defined
13+
if (typeof module !== "undefined" && module.exports) {
14+
module.exports = factory(require("jquery"), require("bootstrap"), require("bootstrap-modal-wrapper"));
15+
}
16+
// AMD module is defined
17+
else if (typeof define === "function" && define.amd) {
18+
define("bootstrap-actionable", ["jquery", "bootstrap"], function ($) {
19+
return factory($);
20+
});
21+
} else {
22+
// planted over the root!
23+
root.BootstrapActionable = factory(root.jQuery, root.BootstrapModalWrapperFactory);
24+
}
25+
26+
}(this, function ($, BootstrapModalWrapperFactory) {
27+
"use strict";
28+
29+
var defaults = {
30+
loadingHtml: "Loading ...",
31+
ajaxHttpMethod: "GET",
32+
ajaxContainerReady: "ajax-container-ready"
33+
};
34+
35+
// The actual plugin constructor
36+
function BootstrapActionable() {
37+
this.options = $.extend({}, defaults);
38+
this.init();
39+
}
40+
41+
BootstrapActionable.prototype.init = function () {
42+
// Initialize Actionable plugin by listening on click event for any actionType attribute value
43+
var $this = this;
44+
$("body").on("click", '[actionType]', function (event) {
45+
event.preventDefault();
46+
var actionType = $(this).attr("actionType") ? $(this).attr("actionType") : "ajax";
47+
var actionScope = $(this).attr("actionScope") ? $(this).attr("actionScope") : "html";
48+
if (actionType === "ajax-model") {
49+
var href = $(this).attr("href") ? $(this).attr("href") : $(this).attr("actionLink");
50+
$this.fetchAjaxContentByModal(href);
51+
} else if (actionType === "action-ref") {
52+
var actionRefName = $(this).attr("action-ref-by-name") ? $(this).attr("action-ref-by-name") : "";
53+
if ($(actionScope + " [action-name='" + actionRefName + "']").length > 0)
54+
$(actionScope + " [action-name='" + actionRefName + "']:first").trigger("click");
55+
} else if (actionType === "action-ref-href") {
56+
var actionRefName = $(this).attr("action-ref-by-href") ? $(this).attr("action-ref-by-href") : "";
57+
if ($(actionScope + " [href='" + actionRefName + "']").length > 0) {
58+
var linkTag = $(actionScope + " [href='" + actionRefName + "']:first");
59+
// check if current link tag has attribute target
60+
if (linkTag.attr('target')) {
61+
window.open(linkTag.attr("href"), linkTag.attr('target'));
62+
} else {
63+
$(linkTag).trigger("click");
64+
}
65+
}
66+
} else {
67+
console.log("ERROR: No Action handler attached for actionType=[" + actionType + "]");
68+
}
69+
});
70+
};
71+
72+
BootstrapActionable.prototype.fetchAjaxContentByModal = function (remoteUrl, passData) {
73+
var $this = this;
74+
var ajaxModalContainer = BootstrapModalWrapperFactory.createModal({
75+
message: $this.options.loadingHtml,
76+
closable: false,
77+
closeByBackdrop: false,
78+
closeByKeyboard: false
79+
});
80+
ajaxModalContainer.originalModal.removeClass("fade");
81+
ajaxModalContainer.originalModal.find(".modal-dialog").css({transition: 'all .3s'});
82+
83+
ajaxModalContainer.show();
84+
85+
if (passData === undefined) {
86+
passData = {};
87+
}
88+
89+
passData["ajaxModalId"] = ajaxModalContainer.options.id;
90+
91+
$.ajax({
92+
type: $this.options.ajaxHttpMethod,
93+
dataType: "html",
94+
url: remoteUrl,
95+
data: {},
96+
success: function (response, textStatus, jqXHR) {
97+
// make sure the modal dialog is open before update
98+
// its body with ajax response and triggering javaTmpAjaxContainerReady event.
99+
var timeOut = 700;
100+
function runWhenDialogOpen() {
101+
// console.log("time out [" + Math.round(timeOut / 2) + "], isOpen [" + ajaxModalContainer.isOpen + "], is show [" + ajaxModalContainer.originalModal.hasClass("show") + "]");
102+
if (ajaxModalContainer.isOpen) {
103+
ajaxModalContainer.updateSize("modal-lg");
104+
setTimeout(function () {
105+
ajaxModalContainer.updateMessage(response);
106+
setTimeout(function () {
107+
$("#" + ajaxModalContainer.options.id).trigger($this.options.ajaxContainerReady, [ajaxModalContainer]);
108+
}, 0);
109+
}, 350);
110+
} else {
111+
timeOut = timeOut <= 50 ? 50 : Math.round(timeOut / 2);
112+
setTimeout(runWhenDialogOpen, timeOut);
113+
114+
}
115+
}
116+
runWhenDialogOpen();
117+
}
118+
});
119+
};
120+
121+
return new BootstrapActionable();
122+
}));

nbproject/project.properties

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
file.reference.bootstrap-actionable-public_html=public_html
2+
file.reference.bootstrap-actionable-test=test
3+
file.reference.NetBeansProjects-bootstrap-actionable=.
4+
files.encoding=UTF-8
5+
site.root.folder=${file.reference.NetBeansProjects-bootstrap-actionable}

nbproject/project.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://www.netbeans.org/ns/project/1">
3+
<type>org.netbeans.modules.web.clientproject</type>
4+
<configuration>
5+
<data xmlns="http://www.netbeans.org/ns/clientside-project/1">
6+
<name>bootstrap-actionable</name>
7+
</data>
8+
</configuration>
9+
</project>

0 commit comments

Comments
 (0)