forked from vitalets/x-editable
-
Notifications
You must be signed in to change notification settings - Fork 257
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
163 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* Editable Popover for Bootstrap 4 based on Popper.js | ||
* --------------------- | ||
* requires bootstrap-popover.js | ||
*/ | ||
(function ($) { | ||
"use strict"; | ||
|
||
//extend methods | ||
$.extend($.fn.editableContainer.Popup.prototype, { | ||
containerName: 'popover', | ||
containerDataName: 'bs.popover', | ||
innerCss: '.popover-body', | ||
defaults: $.fn.popover.Constructor.DEFAULTS, | ||
|
||
initContainer: function(){ | ||
$.extend(this.containerOptions, { | ||
trigger: 'manual', | ||
selector: false, | ||
content: ' ', | ||
template: this.defaults.template | ||
}); | ||
|
||
//as template property is used in inputs, hide it from popover | ||
var t; | ||
if(this.$element.data('template')) { | ||
t = this.$element.data('template'); | ||
this.$element.removeData('template'); | ||
} | ||
|
||
this.call(this.containerOptions); | ||
|
||
if(t) { | ||
//restore data('template') | ||
this.$element.data('template', t); | ||
} | ||
}, | ||
|
||
/* show */ | ||
innerShow: function () { | ||
this.call('show'); | ||
}, | ||
|
||
/* hide */ | ||
innerHide: function () { | ||
this.call('hide'); | ||
}, | ||
|
||
/* destroy */ | ||
innerDestroy: function() { | ||
this.call('dispose'); | ||
}, | ||
|
||
setContainerOption: function(key, value) { | ||
this.container().options[key] = value; | ||
}, | ||
|
||
setPosition: function () { | ||
(function() {}).call(this.container()); | ||
}, | ||
|
||
tip: function() { | ||
return this.container() ? $(this.container().tip) : null; | ||
} | ||
}); | ||
|
||
}(window.jQuery)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
Editableform based on Twitter Bootstrap 3 | ||
*/ | ||
(function ($) { | ||
"use strict"; | ||
|
||
//store parent methods | ||
var pInitInput = $.fn.editableform.Constructor.prototype.initInput; | ||
|
||
$.extend($.fn.editableform.Constructor.prototype, { | ||
initTemplate: function() { | ||
this.$form = $($.fn.editableform.template); | ||
this.$form.find('.control-group').addClass('form-group'); | ||
this.$form.find('.editable-error-block').addClass('help-block'); | ||
}, | ||
initInput: function() { | ||
pInitInput.apply(this); | ||
|
||
var emptyInputClass = this.input.options.inputclass === null || this.input.options.inputclass === false; | ||
var defaultClass = 'form-control-sm'; | ||
|
||
//bs3 add `form-control` class to standard inputs | ||
var stdtypes = 'text,select,textarea,password,email,url,tel,number,range,time,typeaheadjs'.split(','); | ||
if(~$.inArray(this.input.type, stdtypes)) { | ||
this.input.$input.addClass('form-control'); | ||
if(emptyInputClass) { | ||
this.input.options.inputclass = defaultClass; | ||
this.input.$input.addClass(defaultClass); | ||
} | ||
} | ||
|
||
//apply size class also to buttons (to fit size of control) | ||
var $btn = this.$form.find('.editable-buttons'); | ||
var classes = emptyInputClass ? [defaultClass] : this.input.options.inputclass.split(' '); | ||
for(var i=0; i<classes.length; i++) { | ||
// `btn-sm` is default now | ||
/* | ||
if(classes[i].toLowerCase() === 'input-sm') { | ||
$btn.find('button').addClass('btn-sm'); | ||
} | ||
*/ | ||
if(classes[i].toLowerCase() === 'input-lg') { | ||
$btn.find('button').removeClass('btn-sm').addClass('btn-lg'); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
//buttons | ||
$.fn.editableform.buttons = | ||
'<button type="submit" class="btn btn-primary btn-sm editable-submit">'+ | ||
'<i class="fa fa-check" aria-hidden="true"></i>'+ | ||
'</button>'+ | ||
'<button type="button" class="btn btn-default btn-sm editable-cancel">'+ | ||
'<i class="fa fa-times" aria-hidden="true"></i>'+ | ||
'</button>'; | ||
|
||
//error classes | ||
$.fn.editableform.errorGroupClass = 'has-error'; | ||
$.fn.editableform.errorBlockClass = null; | ||
//engine | ||
$.fn.editableform.engine = 'bs4'; | ||
}(window.jQuery)); |