Skip to content

Commit

Permalink
fix grammer error
Browse files Browse the repository at this point in the history
  • Loading branch information
sandywalker committed Sep 6, 2016
1 parent 0e31c52 commit d1ab83e
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 34 deletions.
5 changes: 3 additions & 2 deletions demo/test-issue197.html
Expand Up @@ -15,11 +15,12 @@
<script type="text/javascript">
$(function() {
$('body').webuiPopover({
selector:'.show-pop'
selector:'.show-pop',
trigger:'hover'
})

$('#addPop').on('click',function(e){
$('<a href="#" class="show-pop btn btn-success" data-title="Dynamic Title" data-content="Dynamic content"> Dynamic created Pop </a>').appendTo('.pops');
$('<a href="#" class="show-pop btn btn-success" data-placement="auto-bottom" data-width="300" data-height="200" data-title="Dynamic Title" data-content="Dynamic content"> Dynamic created Pop </a>').appendTo('.pops');
});
});
</script>
Expand Down
57 changes: 47 additions & 10 deletions dist/jquery.webui-popover.js
Expand Up @@ -31,6 +31,7 @@
height: 'auto',
trigger: 'click', //hover,click,sticky,manual
style: '',
selector: false, // jQuery selector, if a selector is provided, popover objects will be delegated to the specified.
delay: {
show: null,
hide: 300
Expand Down Expand Up @@ -156,21 +157,26 @@
this._targetclick = false;
this.init();
_srcElements.push(this.$element);
return this;

}

WebuiPopover.prototype = {
//init webui popover
init: function() {
if (this.$element[0] instanceof document.constructor && !this.options.selector) {
throw new Error('`selector` option must be specified when initializing ' + this.type + ' on the window.document object!');
}

if (this.getTrigger() !== 'manual') {
//init the event handlers
if (this.getTrigger() === 'click' || isMobile) {
this.$element.off('click touchend').on('click touchend', $.proxy(this.toggle, this));
this.$element.off('click touchend', this.options.selector).on('click touchend', this.options.selector, $.proxy(this.toggle, this));
} else if (this.getTrigger() === 'hover') {
this.$element
.off('mouseenter mouseleave click')
.on('mouseenter', $.proxy(this.mouseenterHandler, this))
.on('mouseleave', $.proxy(this.mouseleaveHandler, this));
.off('mouseenter mouseleave click', this.options.selector)
.on('mouseenter', this.options.selector, $.proxy(this.mouseenterHandler, this))
.on('mouseleave', this.options.selector, $.proxy(this.mouseleaveHandler, this));
}
}
this._poped = false;
Expand All @@ -189,6 +195,13 @@
this.show();
}

if (this.options.selector) {
this._options = $.extend({}, this.options, {
trigger: 'manual',
selector: ''
});
}

},
/* api methods and actions */
destroy: function() {
Expand All @@ -215,6 +228,17 @@
this.$target.remove();
}
},
getDelegateOptions: function() {
var options = {};

this._options && $.each(this._options, function(key, value) {
if (defaults[key] !== value) {
options[key] = value;
}
});

return options;
},
/*
param: force boolean value, if value is true then force hide the popover
param: event dom event,
Expand Down Expand Up @@ -273,12 +297,22 @@
}, autoHide);
}
},
delegate: function(eventTarget) {
var self = $(eventTarget).data('plugin_' + pluginName);
if (!self) {
self = new WebuiPopover(eventTarget, this.getDelegateOptions());
$(eventTarget).data('plugin_' + pluginName, self);
}
return self;
},
toggle: function(e) {
var self = this;
if (e) {
e.preventDefault();
e.stopPropagation();
self = this.delegate(e.currentTarget);
}
this[this.getTarget().hasClass('in') ? 'hide' : 'show']();
self[self.getTarget().hasClass('in') ? 'hide' : 'show']();
},
hideAll: function() {
hideAllPop();
Expand Down Expand Up @@ -438,9 +472,6 @@
$iframe.width(iframeWidth).height(iframeHeight);
}




if (!this.options.arrow) {
this.$target.css({
'margin': 0
Expand Down Expand Up @@ -704,8 +735,11 @@
},

/* event handlers */
mouseenterHandler: function() {
mouseenterHandler: function(e) {
var self = this;
if (e) {
self = this.delegate(e.currentTarget);
}
if (self._timeout) {
clearTimeout(self._timeout);
}
Expand All @@ -715,8 +749,11 @@
}
}, this.getDelayShow());
},
mouseleaveHandler: function() {
mouseleaveHandler: function(e) {
var self = this;
if (e) {
self = this.delegate(e.currentTarget);
}
clearTimeout(self._enterTimeout);
//key point, set the _timeout then use clearTimeout when mouse leave
self._timeout = setTimeout(function() {
Expand Down

0 comments on commit d1ab83e

Please sign in to comment.