Code Monkey home page Code Monkey logo

webui-popover's Introduction

WebUI-Popover

A lightWeight popover plugin with jquery, enchance the popover plugin of bootstrap with some awesome new features. It works well with bootstrap, but bootstrap is not necessary!

Browser compatibility: ie8+,Chrome,Safari,Firefox,Opera

Requirement

jquery1.7+

##Features

  • fast,lightweight
  • support more placements
  • auto caculate placement
  • close button in popover
  • multipule popovers in same page
  • different styles
  • support url and iframe
  • support async mode
  • different animations
  • support backdrop

##NPM

  npm install webui-popover

##Bower

  bower install webui-popover

##CDN WebUI Popover Support CDN from version 1.2.1, avaliable on JSDELIVR

##Demo WebUI Popover Demo

##Getting Started

####Including it on your page Localfile

<link rel="stylesheet" href="jquery.webui-popover.css">
...
<script src="jquery.js"></script>
<script src="jquery.webui-popover.js"></script>

Or CDN

<link rel="stylesheet" href="https://cdn.jsdelivr.net/jquery.webui-popover/1.2.1/jquery.webui-popover.min.css">
...
<script src="https://cdn.jsdelivr.net/jquery/1.11.3/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/jquery.webui-popover/1.2.1/jquery.webui-popover.min.js"></script>

####Use the plugin as follows:

$('a').webuiPopover(options);

####Some Examples:

Simplest Popover

$('a').webuiPopover({title:'Title',content:'Content'});

Create Popover by dom element data-* attribute

<a href="#" data-title="Title" data-content="Contents..." data-placement="right">show pop</a>
$('a').webuiPopover();

Popover content can be easily setted by next element with class 'webui-popover-content'

<a href="#" >shop pop</a>
<div class="webui-popover-content">
   <p>popover content</p>
</div>
$('a').webuiPopover();

Or, just use jQuery selector (id selector recommended) to set the Popover content.

<a href="#" >shop pop</a>
<div id="myContent">
   <p>popover content</p>
</div>
$('a').webuiPopover({url:'#myContent'});

Popover with specified placement.

$('a').webuiPopover({title:'Title',content:'Content',placement:'bottom'});

Popover trigged by mouse hover.

$('a').webuiPopover({content:'Content',trigger:'hover'});

Create Sticky Popover.

$('a').webuiPopover({content:'Content',trigger:'sticky'});

Create Popover Dynamically (by new option:'selector').

<a href="#" id="addPop" class="btn btn-default"> add Pop </a>
<div class="pops">
      
</div>
 $('#addPop').on('click',function(e){
            $('<a href="#" class="show-pop data-placement="auto-bottom"  data-title="Dynamic Title" data-content="Dynamic content"> Dynamic created Pop </a>').appendTo('.pops');
        });

Popover with inversed style.

$('a').webuiPopover({content:'Content',style:'inverse'});

Popover with fixed width and height

$('a').webuiPopover({content:'Content',width:300,height:200});

Popover with close button

$('a').webuiPopover({title:'Title',content:'Content',closeable:true});

Animate the Popover

$('a').webuiPopover({title:'Title',content:'Content',animation:'pop'});

Popover with iframe

$('a').webuiPopover({type:'iframe',url:'http://getbootstrap.com'});

Async Mode

$('a').webuiPopover({
						type:'async',
						url:'https://api.github.com/',
						content:function(data){
 							var html = '<ul>';
 							for(var key in data){html+='<li>'+data[key]+'</li>';}
							html+='</ul>';
							return html;
						}
 					});

Async simply by url

$('a').webuiPopover({
   type:'async',
   url:'http://some.website/htmldata'
});

Trigger the Popover by manual

 //Initailize
 $('a').webuiPopover({trigger:'manual'});
...

 //Show it
 $('a').webuiPopover('show');

 //Hide it
 $('a').webuiPopover('hide');

Destroy the Popover

$('a').webuiPopover('destroy');

Default options

{
    placement:'auto',//values: auto,top,right,bottom,left,top-right,top-left,bottom-right,bottom-left,auto-top,auto-right,auto-bottom,auto-left,horizontal,vertical
    container: document.body,// The container in which the popover will be added (i.e. The parent scrolling area). May be a jquery object, a selector string or a HTML element. See https://jsfiddle.net/1x21rj9e/1/
    width:'auto',//can be set with  number
    height:'auto',//can be set with  number
    trigger:'click',//values:  click,hover,manual(handle events by your self),sticky(always show after popover is created);
    selector:false,// jQuery selector, if a selector is provided, popover objects will be delegated to the specified. 
    style:'',// Not to be confused with inline `style=""`, adds a classname to the container for styling, prefixed by `webui-popover-`. Default '' (light theme), 'inverse' for dark theme
    animation:null, //pop with animation,values: pop,fade (only take effect in the browser which support css3 transition)
    delay: {//show and hide delay time of the popover, works only when trigger is 'hover',the value can be number or object
        show: null,
        hide: 300
    },
    async: {
        type:'GET', // ajax request method type, default is GET
        before: function(that, xhr, settings) {},//executed before ajax request
        success: function(that, data) {}//executed after successful ajax request
        error: function(that, xhr, data) {} //executed after error ajax request
    },
    cache:true,//if cache is set to false,popover will destroy and recreate
    multi:false,//allow other popovers in page at same time
    arrow:true,//show arrow or not
    title:'',//the popover title, if title is set to empty string,title bar will auto hide
    content:'',//content of the popover,content can be function
    closeable:false,//display close button or not
    direction:'', // direction of the popover content default is ltr ,values:'rtl';
    padding:true,//content padding
    type:'html',//content type, values:'html','iframe','async'
    url:'',//if type equals 'html', value should be jQuery selecor.  if type equels 'async' the plugin will load content by url.
    backdrop:false,//if backdrop is set to true, popover will use backdrop on open
    dismissible:true, // if popover can be dismissed by  outside click or escape key
    autoHide:false, // automatic hide the popover by a specified timeout, the value must be false,or a number(1000 = 1s).
    offsetTop:0,  // offset the top of the popover
    offsetLeft:0,  // offset the left of the popover
    onShow: function($element) {}, // callback after show
    onHide: function($element) {}, // callback after hide
}

###Global Methods

In some situation, you may want to manipulate the plugin like 'show/hide' popovers by global methods. The new object WebuiPopovers is introduced and exposed to the global window object, so you can access these methods like 'WebuiPopovers.someMethod()...'.

Here are examples of calling code.

//Show Popover by click other element.
$('a').on('click',function(e){
	e.stopPropagation(); // Stop event propagation is needed, otherwise may trigger the document body click event handled by plugin.
	WebuiPopovers.show('#el');
});

// Show Popover with options
WebuiPopovers.show('#el',{title:' hello popover',width:300});


//Hide Popover by jQuery selector
WebuiPopovers.hide('#el');

//Hide All Popovers
WebuiPopovers.hideAll();

//Update the Popover content 
WebuiPopovers.updateContent('.btn-showpop','some html or text');


//Update the Popover content  async
WebuiPopovers.updateContentAsync('.btn-showpop','http://someUrl');

//Set global default options
WebuiPopovers.setDefaultOptions(options);

Full Methods

 	WebuiPopovers.show(selector,options); // Show popover by jQuery selector,the  options parameter is optional
	WebuiPopovers.hide(selector); // Hide  popover by jQuery selector
	WebuiPopovers.hideAll(); // Hide all popovers
	WebuiPopovers.create(selector,options);// Create and init the popover by jQuery selector.
	WebuiPopovers.isCreated(selector); // Check if the popover is already create and bind to the selector.
	WebuiPopovers.updateContent(selector,newContent) //Update the Popover content after the popover is created.
	WebuiPopovers.updateContentAsync(selector,url) //Update the Popover content asynchronously after the popover is created.
	WebuiPopovers.setDefaultOptions(options) //Change the global default options.

Welcome to visit my github page: [http://sandywalker.github.io/]

webui-popover's People

Contributors

aborn avatar andrius-senulis avatar anlumo avatar avilyn avatar briandela avatar checoxshall avatar dukejeffrie avatar dupontbenoit avatar hamway avatar iamdanthedev avatar ilyazolotarov avatar irazasyed avatar jeremyvignelles avatar jorrit avatar limodou avatar migliori avatar mikaelporttila avatar raven-worx avatar sandywalker avatar vadimkuragkovskiy avatar w00fz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

webui-popover's Issues

Load content by url is empty with iframe: false

I think getContent function is slightly wrong.

if (this.options.iframe){
  this.content = $('<iframe frameborder="0"></iframe>').attr('src',this.options.url);
}else{
  $.ajax({
    url:this.options.url,
    type:'GET',
    async:false,
    success:function(data){
      this.content = data;   -------> "this" is not WebuiPopover object
    }
  });
}

Public Bower package

Is there a reason why this nice plugin is marked as private in the bower.json?
This prevent it to be registered as a public package available on bower:

bower register webui-popover https://github.com/sandywalker/webui-popover.git
bower EPRIV         The package you are trying to register is marked as private

would be great to have it public, thanks!

The arrow is misplaced when using async and auto

I'm using async content, and the arrow changes place after the content is loaded. I understand that this is because it doesn't know the content's dimensions, but should reposition after loading it.

captura_sin_titulo_101514_100102_am
(clicked in the first icon)

It works fine if fixed with and auto dimensions

Callbacks

Hi, I'm having issues using the callbacks, they don't seem to execute. Is there an issue?

popover placement bug when html is height:100%

Hi,
i've face a bug using this nice plugin in a fresh new theme.
Popover are positioned well at loading. But when we scroll, others popovers are not calculated well.
after spending few hours trying to understand what was the problem, i've found it :
html tag was having a height:100% specified in the CSS.
removing this fixed the problem.

But it might be a good thing to try to have this in the plugin ? (scrolltop is not detected when html is height:100%)

Can you please add the appropriate LICENCE.txt

Great job on the plugin.
Are you licensing for open use? Please add the licensing you prefer otherwise this can't be used on corporate websites. Simply add a LICENSE.txt to the root with reference.

is it possible to initialize pop and show in one click

hi

thanks for wonderful plugin ๐Ÿ‘ i wanted to initiate the popup when user click on a button and show the popup right away. Simply, in one click, initialize and show.

Could u pls give me some sample code as well

thanks :)

Programmatically open and close popover

After creating the popover:

$('#element-id').webuiPopover({
    title: 'Title',
    content: 'Content'
});

Functions like this would be excellent:

$('#element-id').webuiPopoverShow();

$('#element-id').webuiPopoverHide();

tag data attrs dont overwrite options attrs

@sandywalker
I think that options set by data attribute should always overwrite options set by javascript instance...
What do you think?
Atm for example

getDelayShow:function(){
    return this.options.delay.show||this.$element.attr('data-delay-show');
},

there is no way to change show delay (or other attributes) by data attribute
we need such cahnge:

getDelayShow:function(){
    return this.$element.attr('data-delay-show')||this.options.delay.show;
},

and we need to check if data attribute is set (is not undefined) becouse it can be set to '0'

I can make such changes

popover in async mode does not recognize hover

Hi,

there is a small bug in setContentASync.
if popovers loads content via ajax and you meanwhile leave the popover trigger element it shows the popover when ajax requests completes. so there is an displayed popover although you are the element no more hovering.

an idea would be:

in setContentASync / success function

if ($(that).find('.tt:hover').length) {
that.displayContent();
}

.tt is in our case the class for the popover trigger elements.

Wrong popover position

Hi.
I've Just found this awesome plugin :)
It works well on provided examples, but when I try to add it to my Wordpress plugin, the Popovers show up in wrong position and I can't find out why.
Can you check it?
Thanks

Wail until images are loaded

Hi,

i use webui-popover to show a detailed / bigger image of a product if you hover the product image:

popover is bound to .img-hover:
$('.img-hover').webuiPopover({
type: 'html',
content: function(data) {
return '';
},
placement: 'auto',
trigger: 'hover',
constrains: 'vertical',
delay: 1,
multi: false,
arrow: true,
closeable: false,
padding: true
});

it creates a popover and as content it takes the data-hover value which is the path to another image and returns an image tag.
the problem is, that the image is not yet loaded if the popover appears the first time (on hover).
if the image is finaly loaded the popover does not change its position but shows the image and now the popover is so big it flows over the actual normal product image instead of appears above or below.
is there a possibility to wait, till all images (in this case only one image) are loaded and then show the popover (or at least an waiting/loading image).
thank you!

auto placement horizontal bug

bug

I just discovered placement bug when using data-placement="auto" and data-contrains="horizontal"

placement on the right side works fine

I did change height of title bar a bit with css tho so I guess it can be issue but as I said placement on the right side works fine...

Cancel ajax request on hide

Hi,

thanks for this cool jquery plugin :-)

But it would be a little bit cooler, if you can implement a cancelation of the ajax request if it is still running during hiding the popover. You can achieve this by calling xhr.abort().

Best regards,
Niklas

Not correct popover position with epub.js library

Hi, first thanks for cool library!
I have strange thing when working with epub.js library(that's for rendering epub books).
In first page popover works correctly but when move to another pages popover show strange position things left: 1700px; and above. You can see example of working here(click on words with red background):
http://178.62.232.188:9000/reader/#epubcfi(/6/2[id116]!4/36/2/1:3)

if links not working here is screenshots
Here is working well
Popover woks

But here not at all
Popover not woks

Async.Success is not called

I think there is a bug in jquery.webui-popover.js:288

 if (that.options.async.before){
     that.options.async.success(that, data);
 }

should be

 if (that.options.async.success){
     that.options.async.success(that, data);
 }

Otherwise, the async success method is not called.

bug in README.md

async: {
before: function(that, xhr) {},//executed before ajax request
success: success(that, data) {}//executed after successful ajax request
},

should be
async: {
before: function(that, xhr) {},//executed before ajax request
success: function(that, data) {}//executed after successful ajax request
},

Cache option doesnt work

I have a problem with cache, the plugin works fine, but i try use the cache false and the html is the same when this changed.
please verify the option cache.

jQuery("#theme_user_popover_button").webuiPopover({ 
    html : true,
    placement: 'bottom-left',
    container: 'body',
    viewport: '.main-container',
    cache: false,
    content: function() {
      return jQuery("#theme_user_popover_content").html();
    }
});

Wrong arrow position on big elements

First of all, thanks for the great work on this plugin!

I'm having an issue using it on large elements. Basically, I have a div element with dynamic height and everytime the height is big enough, the arrow's position is wrong.

It seems like the arrow's y position is in the middle of the div element, while the popover's y position remains on the top of the element.

Sometimes it works as expected on elements that are not close to the top of the page.

Here are some screenshots describing this issue:

If this element has 50px of height, the popover appears as expected.
screen shot 2015-02-10 at 18 15 16

But, if I increase the height to 100px, this is the result:
screen shot 2015-02-10 at 18 12 44

And, if I have a 500px height, this is what I get:
screen shot 2015-02-10 at 18 12 26

And here, the second popover works as expected
screen shot 2015-02-10 at 18 45 57

And this is the code that I'm using for this test:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
  <link rel="stylesheet" href="jquery.webui-popover.css" />
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js" ></script>
  <script src="jquery.webui-popover.js" ></script>
  <style type="text/css">
  body{
    background-color: #666666;
  }
  #popover_test{
    width: 100px;
    height: 400px;
    background: #00ccff;
    border: 1px solid blue;
  }
   #popover_test2{
    width: 100px;
    height: 200px;
    background: #00ccff;
    border: 1px solid blue;
  }
  </style>
  <script type="text/javascript">
    $(document).ready(function(){
        $('#popover_test').webuiPopover({
                constrains: 'horizontal', 
                trigger:'click',
                multi: true,
                content: 'content'
        });

        $('#popover_test2').webuiPopover({
                constrains: 'horizontal', 
                trigger:'click',
                multi: true,
                content: 'content'
        });

    }); 
  </script>
</head>
<body>
    <div id="popover_test"></div>
    <div id="popover_test2"></div>
</body>
</html>

I'm testing on Safari 8.0.3, Chrome 40.0.2214.93 and Firefox 35.0.1

Add "main" to bower.json

I would recommend updating your bower.json file to the following:

{
  "name": "webui-popover",
  "version": "1.1.0",
  "authors": [
    "sandywalker <[email protected]>"
  ],
  "description": "webui popover",
  "keywords": [
    "jquery",
    "plugins"
  ],
  "license": "MIT",
  "private": true,
  "ignore": [
    "**/.*",
    "node_modules",
    "bower_components",
    "test",
    "tests"
  ],
  "main": [
    "dist/jquery.webui-popover.css",
    "dist/jquery.webui-popover.js"
  ],
  "dependencies": {
      "jquery": "^2.0.0"
}

That way bower will correctly install the needed dependencies (jquery), and a task runner like grunt will include the correct files in the code.

Animation for close

Would be nice to have the chosen animation take place for when the popover closes as well.

async requests with images in content

i noticed some problems if placement is top and content loads via ajax request. if there is an image in content the popover appears over the element, but if the images is fully loaded the popover slips over the element for the height of the image.
is it possible to reset the position if all images are loaded?
Also if the ajax request is not yet finished and you leave the bound element during the request the popover will not close. it only works if the content is already cached.
thank you

In modal window it does not work.

I tried set a popover in a modal window, and the popover is always attached to de document.body, so the popover does not appear next to the element which was applied the plugin in the modal.

auto top bottom

Hi sandywalker,

first, thank you for this great popover feature!
i need a special placement for my popovers. they should only pop on top, or on bottom related to the scrolling position, so the popover is always visible for the user.
how do i have to configure the webui-popover plugin?

thanks!

Drag and maxmization features requirement

What about adding drag and maximization support to webui-popover?

For maximization, the options could be:

maxWidth: 'none' // 'none' is default means can't be maximized,
// 'auto' means maximize to full document width
// 'n%' means enlarge to n percent of full document width
maxHeight: //just like above

if one of maxWidth and maxHeight is not 'none', it'll place a maximization icon int the right-top cornor of the popup dialog.

auto placement: popup could appear outside current viewPort

When using auto placement option, sometimes, especially on mobile, the chosen placement option will place part of the popup outside of the current viewPort (i.e. will require scrolling to view completely), when another placement would not.

Here's an example: http://jsfiddle.net/6gjn1fgr/7/

Just resize the result frame to 300px or so.

Clicking the red div will use auto, and pick right placement: right placement

Clicking the blue div will force top-right placement: top-right placement

This occurs because the code that choose a placement when using auto doesn't consider the target (popup) width, in relation to pageX and the element width. If it did, it would notice that pageX + elementWidth + targetWidth > clientWidth, and wouldn't use right, but prefer top-right or bottom-right in that case.

If you have a preferred method on how to fix this, I could work on it, and submit a pull request. Just wanted to check how you think this should be resolved, to better serve everyone.

Thanks.

placement right/left improvement

@sandywalker
would be great is placement left or right could position popover window in visible window space - I made graphic showing expected effect
would it be hard to implement such smart placement?
dont know if making extra options left-auto/right-auto would be good idea... maybe its better to implement such feature to existing left/right placement options

popover

Fade in?

I've had success adding this simple CSS rule to make the popover fade in:

.webui-popover {
  -webkit-animation: fadein 0.4s; /* Safari, Chrome and Opera > 12.1 */
     -moz-animation: fadein 0.4s; /* Firefox < 16 */
      -ms-animation: fadein 0.4s; /* Internet Explorer */
       -o-animation: fadein 0.4s; /* Opera < 12.1 */
          animation: fadein 0.4s;
}

@keyframes fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Firefox < 16 */
@-moz-keyframes fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Safari, Chrome and Opera > 12.1 */
@-webkit-keyframes fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Internet Explorer */
@-ms-keyframes fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

/* Opera < 12.1 */
@-o-keyframes fadein {
    from { opacity: 0; }
    to   { opacity: 1; }
}

Just thought you might consider adding fade-in/out as an option?

via: http://stackoverflow.com/questions/11679567/using-css-for-fade-in-effect-on-page-load

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.