Initial commit

This commit is contained in:
Khanh Ngo
2015-12-13 16:34:12 +07:00
commit 2dac8205f6
3113 changed files with 514935 additions and 0 deletions

View File

@ -0,0 +1,49 @@
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
banner:
'/*!\n'+
' * Bootstrap Confirmation <%= pkg.version %>\n'+
' * Copyright 2013 Nimit Suwannagate <ethaizone@hotmail.com>\n'+
' * Copyright <%= grunt.template.today("yyyy") %> Damien "Mistic" Sorel <http://www.strangeplanet.fr>\n'+
' * Licensed under the Apache License, Version 2.0 (the "License")\n'+
' */',
// compress js
uglify: {
options: {
banner: '<%= banner %>\n'
},
dist: {
files: {
'bootstrap-confirmation.min.js': [
'bootstrap-confirmation.js'
]
}
}
},
// jshint tests
jshint: {
lib: {
files: {
src: [
'bootstrap-confirmation.js'
]
}
}
}
});
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.registerTask('default', [
'uglify'
]);
grunt.registerTask('test', [
'jshint'
]);
};

View File

@ -0,0 +1,17 @@
# Bootstrap-Confirmation
[![Bower version](https://badge.fury.io/bo/bootstrap-confirmation2.svg)](http://badge.fury.io/bo/bootstrap-confirmation2)
Bootstrap plugin for on-place confirm boxes using Popover.
## Documentation
http://mistic100.github.io/Bootstrap-Confirmation
## Changes from original one
- Bootstrap 3 compatible
- Fix double event fires
- Automatic handle of links (without need of custom callback)

View File

@ -0,0 +1,258 @@
/*!
* Bootstrap Confirmation
* Copyright 2013 Nimit Suwannagate <ethaizone@hotmail.com>
* Copyright 2014 Damien "Mistic" Sorel <http://www.strangeplanet.fr>
* Licensed under the Apache License, Version 2.0 (the "License")
*/
(function ($) {
'use strict';
// Confirmation extends popover.js
if (!$.fn.popover) throw new Error('Confirmation requires popover.js');
// CONFIRMATION PUBLIC CLASS DEFINITION
// ===============================
var Confirmation = function (element, options) {
this.init('confirmation', element, options);
var that = this;
if (!this.options.selector) {
// get existing href and target
if (this.$element.attr('href')) {
this.options.href = this.$element.attr('href');
this.$element.removeAttr('href');
if (this.$element.attr('target')) {
this.options.target = this.$element.attr('target');
}
}
// cancel original event
this.$element.on(that.options.trigger, function(e, ack) {
if (!ack) {
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
}
});
// trigger original event on confirm
this.$element.on('confirmed.bs.confirmation', function(e) {
$(this).trigger(that.options.trigger, [true]);
});
// manage singleton
this.$element.on('show.bs.confirmation', function(e) {
if (that.options.singleton) {
// close all other popover already initialized
$(that.options._selector).not($(this)).filter(function() {
return $(this).data('bs.confirmation') !== undefined;
}).confirmation('hide');
}
});
}
if (!this.options._isDelegate) {
// manage popout
this.eventBody = false;
this.uid = this.$element[0].id || this.getUID('group_');
this.$element.on('shown.bs.confirmation', function(e) {
if (that.options.popout && !that.eventBody) {
var $this = $(this);
that.eventBody = $('body').on('click.bs.confirmation.'+that.uid, function(e) {
if ($(that.options._selector).is(e.target)) {
return;
}
// close all popover already initialized
$(that.options._selector).filter(function() {
return $(this).data('bs.confirmation') !== undefined;
}).confirmation('hide');
$('body').off('click.bs.'+that.uid);
that.eventBody = false;
});
}
});
}
};
Confirmation.DEFAULTS = $.extend({}, $.fn.popover.Constructor.DEFAULTS, {
placement: 'top',
title: 'Are you sure?',
html: true,
href: false,
popout: false,
singleton: false,
target: '_self',
onConfirm: $.noop,
onCancel: $.noop,
btnOkClass: 'btn-xs btn-primary',
btnOkIcon: 'glyphicon glyphicon-ok',
btnOkLabel: 'Yes',
btnCancelClass: 'btn-xs btn-default',
btnCancelIcon: 'glyphicon glyphicon-remove',
btnCancelLabel: 'No',
template:
'<div class="popover confirmation">' +
'<div class="arrow"></div>' +
'<h3 class="popover-title"></h3>' +
'<div class="popover-content text-center">'+
'<div class="btn-group">'+
'<a class="btn" data-apply="confirmation"></a>'+
'<a class="btn" data-dismiss="confirmation"></a>'+
'</div>'+
'</div>'+
'</div>'
});
Confirmation.prototype = $.extend({}, $.fn.popover.Constructor.prototype);
Confirmation.prototype.constructor = Confirmation;
Confirmation.prototype.getDefaults = function () {
return Confirmation.DEFAULTS;
};
// custom init keeping trace of selectors
Confirmation.prototype.init = function(type, element, options) {
$.fn.popover.Constructor.prototype.init.call(this, type, element, options);
this.options._isDelegate = false;
if (options.selector) { // container of buttons
this.options._selector = this._options._selector = options._root_selector +' '+ options.selector;
}
else if (options._selector) { // children of container
this.options._selector = options._selector;
this.options._isDelegate = true;
}
else { // standalone
this.options._selector = options._root_selector;
}
};
Confirmation.prototype.setContent = function () {
var that = this,
$tip = this.tip(),
o = this.options;
$tip.find('.popover-title')[o.html ? 'html' : 'text'](this.getTitle());
// configure 'ok' button
$tip.find('[data-apply="confirmation"]')
.addClass(o.btnOkClass)
.html(o.btnOkLabel)
.prepend($('<i></i>').addClass(o.btnOkIcon), ' ')
.off('click')
.one('click', function(e) {
that.getOnConfirm.call(that).call(that.$element);
that.$element.trigger('confirmed.bs.confirmation');
that.leave(that);
});
// add href to confirm button if needed
if (o.href && o.href != "#") {
$tip.find('[data-apply="confirmation"]').attr({
href: o.href,
target: o.target
});
}
// configure 'cancel' button
$tip.find('[data-dismiss="confirmation"]')
.addClass(o.btnCancelClass)
.html(o.btnCancelLabel)
.prepend($('<i></i>').addClass(o.btnCancelIcon), ' ')
.off('click')
.one('click', function(e) {
that.getOnCancel.call(that).call(that.$element);
that.$element.trigger('canceled.bs.confirmation');
that.leave(that);
});
$tip.removeClass('fade top bottom left right in');
// IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do
// this manually by checking the contents.
if (!$tip.find('.popover-title').html()) {
$tip.find('.popover-title').hide();
}
};
Confirmation.prototype.getOnConfirm = function() {
if (this.$element.attr('data-on-confirm')) {
return getFunctionFromString(this.$element.attr('data-on-confirm'));
}
else {
return this.options.onConfirm;
}
};
Confirmation.prototype.getOnCancel = function() {
if (this.$element.attr('data-on-cancel')) {
return getFunctionFromString(this.$element.attr('data-on-cancel'));
}
else {
return this.options.onCancel;
}
};
/*
* Generates an anonymous function from a function name
* function name may contain dots (.) to navigate through objects
* root context is window
*/
function getFunctionFromString(functionName) {
var context = window,
namespaces = functionName.split('.'),
func = namespaces.pop();
for (var i=0, l=namespaces.length; i<l; i++) {
context = context[namespaces[i]];
}
return function() {
context[func].call(this);
};
}
// CONFIRMATION PLUGIN DEFINITION
// =========================
var old = $.fn.confirmation;
$.fn.confirmation = function (option) {
var options = (typeof option == 'object' && option) || {};
options._root_selector = this.selector;
return this.each(function () {
var $this = $(this),
data = $this.data('bs.confirmation');
if (!data && option == 'destroy') {
return;
}
if (!data) {
$this.data('bs.confirmation', (data = new Confirmation(this, options)));
}
if (typeof option == 'string') {
data[option]();
}
});
};
$.fn.confirmation.Constructor = Confirmation;
// CONFIRMATION NO CONFLICT
// ===================
$.fn.confirmation.noConflict = function () {
$.fn.confirmation = old;
return this;
};
}(jQuery));

View File

@ -0,0 +1,7 @@
/*!
* Bootstrap Confirmation 2.1.2
* Copyright 2013 Nimit Suwannagate <ethaizone@hotmail.com>
* Copyright 2014 Damien "Mistic" Sorel <http://www.strangeplanet.fr>
* Licensed under the Apache License, Version 2.0 (the "License")
*/
!function(a){"use strict";function b(a){for(var b=window,c=a.split("."),d=c.pop(),e=0,f=c.length;f>e;e++)b=b[c[e]];return function(){b[d].call(this)}}if(!a.fn.popover)throw new Error("Confirmation requires popover.js");var c=function(b,c){this.init("confirmation",b,c);var d=this;this.options.selector||(this.$element.attr("href")&&(this.options.href=this.$element.attr("href"),this.$element.removeAttr("href"),this.$element.attr("target")&&(this.options.target=this.$element.attr("target"))),this.$element.on(d.options.trigger,function(a,b){b||(a.preventDefault(),a.stopPropagation(),a.stopImmediatePropagation())}),this.$element.on("confirmed.bs.confirmation",function(){a(this).trigger(d.options.trigger,[!0])}),this.$element.on("show.bs.confirmation",function(){d.options.singleton&&a(d.options._selector).not(a(this)).filter(function(){return void 0!==a(this).data("bs.confirmation")}).confirmation("hide")})),this.options._isDelegate||(this.eventBody=!1,this.uid=this.$element[0].id||this.getUID("group_"),this.$element.on("shown.bs.confirmation",function(){if(d.options.popout&&!d.eventBody){{a(this)}d.eventBody=a("body").on("click.bs.confirmation."+d.uid,function(b){a(d.options._selector).is(b.target)||(a(d.options._selector).filter(function(){return void 0!==a(this).data("bs.confirmation")}).confirmation("hide"),a("body").off("click.bs."+d.uid),d.eventBody=!1)})}}))};c.DEFAULTS=a.extend({},a.fn.popover.Constructor.DEFAULTS,{placement:"top",title:"Are you sure?",html:!0,href:!1,popout:!1,singleton:!1,target:"_self",onConfirm:a.noop,onCancel:a.noop,btnOkClass:"btn-xs btn-primary",btnOkIcon:"glyphicon glyphicon-ok",btnOkLabel:"Yes",btnCancelClass:"btn-xs btn-default",btnCancelIcon:"glyphicon glyphicon-remove",btnCancelLabel:"No",template:'<div class="popover confirmation"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content text-center"><div class="btn-group"><a class="btn" data-apply="confirmation"></a><a class="btn" data-dismiss="confirmation"></a></div></div></div>'}),c.prototype=a.extend({},a.fn.popover.Constructor.prototype),c.prototype.constructor=c,c.prototype.getDefaults=function(){return c.DEFAULTS},c.prototype.init=function(b,c,d){a.fn.popover.Constructor.prototype.init.call(this,b,c,d),this.options._isDelegate=!1,d.selector?this.options._selector=this._options._selector=d._root_selector+" "+d.selector:d._selector?(this.options._selector=d._selector,this.options._isDelegate=!0):this.options._selector=d._root_selector},c.prototype.setContent=function(){var b=this,c=this.tip(),d=this.options;c.find(".popover-title")[d.html?"html":"text"](this.getTitle()),c.find('[data-apply="confirmation"]').addClass(d.btnOkClass).html(d.btnOkLabel).prepend(a("<i></i>").addClass(d.btnOkIcon)," ").off("click").one("click",function(){b.getOnConfirm.call(b).call(b.$element),b.$element.trigger("confirmed.bs.confirmation"),b.leave(b)}),d.href&&c.find('[data-apply="confirmation"]').attr({href:d.href,target:d.target}),c.find('[data-dismiss="confirmation"]').addClass(d.btnCancelClass).html(d.btnCancelLabel).prepend(a("<i></i>").addClass(d.btnCancelIcon)," ").off("click").one("click",function(){b.getOnCancel.call(b).call(b.$element),b.$element.trigger("canceled.bs.confirmation"),b.leave(b)}),c.removeClass("fade top bottom left right in"),c.find(".popover-title").html()||c.find(".popover-title").hide()},c.prototype.getOnConfirm=function(){return this.$element.attr("data-on-confirm")?b(this.$element.attr("data-on-confirm")):this.options.onConfirm},c.prototype.getOnCancel=function(){return this.$element.attr("data-on-cancel")?b(this.$element.attr("data-on-cancel")):this.options.onCancel};var d=a.fn.confirmation;a.fn.confirmation=function(b){var d="object"==typeof b&&b||{};return d._root_selector=this.selector,this.each(function(){var e=a(this),f=e.data("bs.confirmation");(f||"destroy"!=b)&&(f||e.data("bs.confirmation",f=new c(this,d)),"string"==typeof b&&f[b]())})},a.fn.confirmation.Constructor=c,a.fn.confirmation.noConflict=function(){return a.fn.confirmation=d,this}}(jQuery);

View File

@ -0,0 +1,33 @@
{
"name": "bootstrap-confirmation2",
"version": "2.1.2",
"homepage": "https://github.com/mistic100/Bootstrap-Confirmation",
"authors": [
"ethaizone",
{
"name": "Damien \"Mistic\" Sorel",
"homepage": "http://www.strangeplanet.fr"
}
],
"description": "Bootstrap plugin for on-place confirm boxes using Popover",
"main": "bootstrap-confirmation.js",
"keywords": [
"confirmation",
"popup"
],
"dependencies" : {
"bootstrap": ">=3.2.0"
},
"license": "Apache",
"repository": {
"type": "git",
"url": "git://github.com/mistic100/Bootstrap-Confirmation.git"
},
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}

View File

@ -0,0 +1,37 @@
{
"name": "bootstrap-confirmation2",
"version": "2.1.2",
"homepage": "https://github.com/mistic100/Bootstrap-Confirmation",
"description": "Bootstrap plugin for on-place confirm boxes using Popover",
"authors": [
"ethaizone",
{
"name": "Damien \"Mistic\" Sorel",
"homepage": "http://www.strangeplanet.fr"
}
],
"main": "bootstrap-confirmation.js",
"dependencies" : {
"bootstrap": "3.x.x"
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-contrib-uglify": "~0.4.0",
"grunt-contrib-jshint": "~0.10.0"
},
"keywords": [
"confirmation",
"popup"
],
"license": "Apache",
"repository": {
"type": "git",
"url": "git://github.com/mistic100/Bootstrap-Confirmation.git"
},
"bugs": {
"url": "https://github.com/mistic100/Bootstrap-Confirmation/issues"
},
"scripts": {
"test": "grunt test --force"
}
}