bs3 first working version
This commit is contained in:
src
containers
editable-form
element
inputs
test
@ -24,6 +24,8 @@ Applied as jQuery method.
|
||||
containerDataName: null, //object name in element's .data()
|
||||
innerCss: null, //tbd in child class
|
||||
containerClass: 'editable-container editable-popup', //css class applied to container element
|
||||
defaults: {}, //container itself defaults
|
||||
|
||||
init: function(element, options) {
|
||||
this.$element = $(element);
|
||||
//since 1.4.1 container do not use data-* directly as they already merged into options.
|
||||
@ -101,10 +103,9 @@ Applied as jQuery method.
|
||||
throw new Error(this.containerName + ' not found. Have you included corresponding js file?');
|
||||
}
|
||||
|
||||
var cDef = $.fn[this.containerName].defaults;
|
||||
//keys defined in container defaults go to container, others go to form
|
||||
for(var k in this.options) {
|
||||
if(k in cDef) {
|
||||
if(k in this.defaults) {
|
||||
this.containerOptions[k] = this.options[k];
|
||||
} else {
|
||||
this.formOptions[k] = this.options[k];
|
||||
|
@ -11,13 +11,14 @@
|
||||
containerName: 'popover',
|
||||
//for compatibility with bootstrap <= 2.2.1 (content inserted into <p> instead of directly .popover-content)
|
||||
innerCss: $.fn.popover && $($.fn.popover.defaults.template).find('p').length ? '.popover-content p' : '.popover-content',
|
||||
|
||||
defaults: $.fn.popover.defaults,
|
||||
|
||||
initContainer: function(){
|
||||
$.extend(this.containerOptions, {
|
||||
trigger: 'manual',
|
||||
selector: false,
|
||||
content: ' ',
|
||||
template: $.fn.popover.defaults.template
|
||||
template: this.defaults.template
|
||||
});
|
||||
|
||||
//as template property is used in inputs, hide it from popover
|
||||
|
199
src/containers/editable-popover3.js
Normal file
199
src/containers/editable-popover3.js
Normal file
@ -0,0 +1,199 @@
|
||||
/**
|
||||
* Editable Popover3 (for Bootstrap 3)
|
||||
* ---------------------
|
||||
* requires bootstrap-popover.js
|
||||
*/
|
||||
(function ($) {
|
||||
"use strict";
|
||||
|
||||
//extend methods
|
||||
$.extend($.fn.editableContainer.Popup.prototype, {
|
||||
containerName: 'popover',
|
||||
containerDataName: 'bs.popover',
|
||||
innerCss: '.popover-content',
|
||||
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('destroy');
|
||||
},
|
||||
|
||||
setContainerOption: function(key, value) {
|
||||
this.container().options[key] = value;
|
||||
},
|
||||
|
||||
/**
|
||||
* move popover to new position. This function mainly copied from bootstrap-popover.
|
||||
*/
|
||||
/*jshint laxcomma: true*/
|
||||
setPosition: function () {
|
||||
|
||||
(function() {
|
||||
/*
|
||||
var $tip = this.tip()
|
||||
, inside
|
||||
, pos
|
||||
, actualWidth
|
||||
, actualHeight
|
||||
, placement
|
||||
, tp
|
||||
, tpt
|
||||
, tpb
|
||||
, tpl
|
||||
, tpr;
|
||||
|
||||
placement = typeof this.options.placement === 'function' ?
|
||||
this.options.placement.call(this, $tip[0], this.$element[0]) :
|
||||
this.options.placement;
|
||||
|
||||
inside = /in/.test(placement);
|
||||
|
||||
$tip
|
||||
// .detach()
|
||||
//vitalets: remove any placement class because otherwise they dont influence on re-positioning of visible popover
|
||||
.removeClass('top right bottom left')
|
||||
.css({ top: 0, left: 0, display: 'block' });
|
||||
// .insertAfter(this.$element);
|
||||
|
||||
pos = this.getPosition(inside);
|
||||
|
||||
actualWidth = $tip[0].offsetWidth;
|
||||
actualHeight = $tip[0].offsetHeight;
|
||||
|
||||
placement = inside ? placement.split(' ')[1] : placement;
|
||||
|
||||
tpb = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2};
|
||||
tpt = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2};
|
||||
tpl = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth};
|
||||
tpr = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width};
|
||||
|
||||
switch (placement) {
|
||||
case 'bottom':
|
||||
if ((tpb.top + actualHeight) > ($(window).scrollTop() + $(window).height())) {
|
||||
if (tpt.top > $(window).scrollTop()) {
|
||||
placement = 'top';
|
||||
} else if ((tpr.left + actualWidth) < ($(window).scrollLeft() + $(window).width())) {
|
||||
placement = 'right';
|
||||
} else if (tpl.left > $(window).scrollLeft()) {
|
||||
placement = 'left';
|
||||
} else {
|
||||
placement = 'right';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'top':
|
||||
if (tpt.top < $(window).scrollTop()) {
|
||||
if ((tpb.top + actualHeight) < ($(window).scrollTop() + $(window).height())) {
|
||||
placement = 'bottom';
|
||||
} else if ((tpr.left + actualWidth) < ($(window).scrollLeft() + $(window).width())) {
|
||||
placement = 'right';
|
||||
} else if (tpl.left > $(window).scrollLeft()) {
|
||||
placement = 'left';
|
||||
} else {
|
||||
placement = 'right';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'left':
|
||||
if (tpl.left < $(window).scrollLeft()) {
|
||||
if ((tpr.left + actualWidth) < ($(window).scrollLeft() + $(window).width())) {
|
||||
placement = 'right';
|
||||
} else if (tpt.top > $(window).scrollTop()) {
|
||||
placement = 'top';
|
||||
} else if (tpt.top > $(window).scrollTop()) {
|
||||
placement = 'bottom';
|
||||
} else {
|
||||
placement = 'right';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'right':
|
||||
if ((tpr.left + actualWidth) > ($(window).scrollLeft() + $(window).width())) {
|
||||
if (tpl.left > $(window).scrollLeft()) {
|
||||
placement = 'left';
|
||||
} else if (tpt.top > $(window).scrollTop()) {
|
||||
placement = 'top';
|
||||
} else if (tpt.top > $(window).scrollTop()) {
|
||||
placement = 'bottom';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
switch (placement) {
|
||||
case 'bottom':
|
||||
tp = tpb;
|
||||
break;
|
||||
case 'top':
|
||||
tp = tpt;
|
||||
break;
|
||||
case 'left':
|
||||
tp = tpl;
|
||||
break;
|
||||
case 'right':
|
||||
tp = tpr;
|
||||
break;
|
||||
}
|
||||
|
||||
$tip
|
||||
.offset(tp)
|
||||
.addClass(placement)
|
||||
.addClass('in');
|
||||
*/
|
||||
|
||||
|
||||
var $tip = this.tip();
|
||||
|
||||
var placement = typeof this.options.placement == 'function' ?
|
||||
this.options.placement.call(this, $tip[0], this.$element[0]) :
|
||||
this.options.placement;
|
||||
|
||||
|
||||
var pos = this.getPosition();
|
||||
var actualWidth = $tip[0].offsetWidth;
|
||||
var actualHeight = $tip[0].offsetHeight;
|
||||
var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight);
|
||||
|
||||
this.applyPlacement(calculatedOffset, placement);
|
||||
|
||||
|
||||
|
||||
}).call(this.container());
|
||||
/*jshint laxcomma: false*/
|
||||
}
|
||||
});
|
||||
|
||||
}(window.jQuery));
|
@ -10,6 +10,7 @@
|
||||
$.extend($.fn.editableContainer.Popup.prototype, {
|
||||
containerName: 'poshytip',
|
||||
innerCss: 'div.tip-inner',
|
||||
defaults: $.fn.poshytip.defaults,
|
||||
|
||||
initContainer: function(){
|
||||
this.handlePlacement();
|
||||
|
@ -12,6 +12,7 @@
|
||||
//object name in element's .data()
|
||||
containerDataName: 'ui-tooltip',
|
||||
innerCss: '.ui-tooltip-content',
|
||||
defaults: $.ui.tooltip.prototype.options,
|
||||
|
||||
//split options on containerOptions and formOptions
|
||||
splitOptions: function() {
|
||||
@ -23,10 +24,10 @@
|
||||
$.error('Please use jQueryUI with "tooltip" widget! http://jqueryui.com/download');
|
||||
return;
|
||||
}
|
||||
|
||||
//defaults for tooltip
|
||||
var cDef = $.ui[this.containerName].prototype.options;
|
||||
for(var k in this.options) {
|
||||
if(k in cDef) {
|
||||
if(k in this.defaults) {
|
||||
this.containerOptions[k] = this.options[k];
|
||||
} else {
|
||||
this.formOptions[k] = this.options[k];
|
||||
|
Reference in New Issue
Block a user