Giter Site home page Giter Site logo

jquery.avgrund.js's Introduction

Avgrund

Libscore Badge

Avgrund is a jQuery plugin for your modal boxes and popups. It uses new concept showing depth between popup and page.

It works in all modern browsers and gracefully degrade in those that do not support CSS transitions and transformations.

Tested with jQuery versions 1.4+

File size of minified version is ~1Kb.

Usage

You can simply include javascript file and init Avgrund with one line:

$('element').avgrund();

and linking avgrund.css file to the project:

<link rel="stylesheet" href="path/to/your/avgrund.css">

If you use bower then you can simply install it as:

bower install jquery.avgrund

Using plugin with Browserify

At first install plugin via NPM:

npm install jquery.avgrund
npm install jquery-browserify

In your server-side node.js (e.g. express app):

app.use(require('browserify')({
    require : ['jquery-browserify', 'jquery.avgrund']
}));

And in your browser-side you can init plugin now:

var $ = require('jquery-browserify');
require('jquery.avgrund')($);

Options

You're also able to use some of the options that let you customize it as you wish:

$('element').avgrund({
    width: 380, // max is 640px
    height: 280, // max is 350px
    showClose: false, // switch to 'true' for enabling close button
    showCloseText: '', // type your text for close button
    closeByEscape: true, // enables closing popup by 'Esc'..
    closeByDocument: true, // ..and by clicking document itself
    holderClass: '', // lets you name custom class for popin holder..
    overlayClass: '', // ..and overlay block
    enableStackAnimation: false, // enables different type of popin's animation
    onBlurContainer: '', // enables blur filter for specified block
    openOnEvent: true, // set to 'false' to init on load
    setEvent: 'click', // use your event like 'mouseover', 'touchmove', etc.
    onLoad: function (elem) { ... }, // set custom call before popin is inited..
    onUnload: function (elem) { ... }, // ..and after it was closed
    template: 'Your string content goes here..' // or function (elem) { ... }, or selector $('.content')
});

More detailed information on every option you can find here.

Documentation

Here is the list of available avgrund options:

width - string | number, default: '380px'

Set popup width (currently stict to max 640px).

height - string | number, default: '280px'

Set popup height (currently strict to max 350px).

showClose - boolean, default: false

Show/hide close button.

showCloseText - string

If you decided to show close button then you probably want to add close text to it.

closeByEscape - boolean, default: true

Allow users to close popup by clicking Esc button.

closeByDocument - boolean, default: true

Allow users to close popup by clicking everywhere on document (except popup of course).

holderClass - string

Adds custom css classes to avgrund popup, example:

$(element).avgrund({
    holderClass: 'my-custom-class'
});

results in adding this class to avgrund container:

<div class="avgrund-popin my-custom-class">...</div>
overlayClass - string

Adds custom css classes to avgrund overlay container.

enableStackAnimation - boolean, default: false

Possibility to add a bit different popup hiding animation type.

onBlurContainer - string

Class name for container element that will be blurred when popup appears, example:

$(element).avgrund({
    onBlurContainer: '#my-container'
});

Please note that currently css blur is not supported in all modern browsers.

openOnEvent - boolean, default: true

If you want to show avgrund on page load set this option value to false, example:

$(document).avgrund({
    openOnEvent: false
});
setEvent - string, default: 'click'

With this option you can manage events that will open popup on certain element:

$(element).avgrund({
    setEvent: 'mouseover' // will open popin on element's mouseover
});
onLoad - function

If you need to make some preparations or whatever before avgrund popup will be shown, example:

$(element).avgrund({
    onLoad: function (element) {
        console.log('This function will be called before dialog is initialized');
    }
});
onUnload - function

This function will be executed after popup was closed, example:

$(element).avgrund({
    onUnload: function (element) {
        console.log('This message will be shown after dialog is closed');
    }
});
template - string | function | jQuery object

Specify your content for popin here, it can be string value:

$(element).avgrund({
    template: '<p>This is popin content!</p>'
});

or function that returns content itself:

$(element).avgrund({
    template: function (element) {
        // return 'your content..'
    }
});

Also it accepts jQuery objects (dynamic as well), so you can create element with content inside your app:

<div class="content" style="display: none;">
    My content for popin!
</div>

and use it in template of popin:

$('element').avgrund({
    template: $('.content')
});

Demo

Check the example here: http://labs.voronianski.dev/jquery.avgrund.js/

Inspired by Hakim's demo: https://github.com/hakimel/avgrund/

Changelog

Update (Sep 28, 2013)

Added AMD and CommonJS styles support.

Update (Sep 22, 2013)

Added support jQuery selectors in template option.

Update (June 15, 2013)

Better fix for overlay and long content pages, minor add-ons.

Update (May 26, 2013)

Few fixes, and plugin is available as bower package now. So you can simply install it as:

Update (Feb 25, 2013)

A bunch of small but very useful fixes and updates, including multiple avgrund popins on a page, removing popins from DOM after deactivation (also fixed an issue to make sure avgrund close effect works) and position:fixed/transform/overflow issue for scrolled pages in -webkit.

Update (Nov 18, 2012)

Get 2 new useful options for popin that were missed before. Now you can set your custom functions before Avgrund dialog is open and after it was closed.

Update (Sep 30, 2012)

Some new updates include initializing popin without event. Also now you can set up your own event for an element. Added ability to use a custom function inside avgrund's template option. Thanks to juice49 for pull request.

Update (Aug 31, 2012)

New options added - disable closing popup by 'Esc' and 'Document click'. Blur css filter for browsers that support it (seems only webkit ones for now).

Contribution

We still have some issues to fix and make avgrund better, if you have any suggestions raise them in issues please.


MIT Licensed

enjoy!

Bitdeli Badge

jquery.avgrund.js's People

Contributors

ayoung avatar iurisilvio avatar kkirsche avatar leobalter avatar mason-stewart avatar voronianski avatar zaa 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  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

jquery.avgrund.js's Issues

Callbacks

I was also wondering how I might perform a certain action after the modal is triggered (for things like auto-focusing text inputs, etc).

Thanks, and awesome plugin!

Ajax functionality works only the first time.

I tried adding a slider to the avgrund.
Here is the code: http://dpaste.com/884036/
When I click the first time, it works normally. But after I close the avgrund-popin, and re-open it, it just shows a blank avgrund-popin without any texts.
I'm fetching the whole html through PHP stored in MySQL tables and then showing it here on avgrund through Ajax.

Jquery ignores if-else condition

Hi,

I really loved your plugin but m facing an issue while imposing an if-else block on a dropdownlist selection. I wish the plugin to appear only if the selected value in my dropdown list is "test". Kindly help.

Below is my code:

<script> ``` $(function () { $('#Content_ddl_RepCountry').change(function () { var result = $(this).val(); if (result == "test") { $(this).avgrund({ height: 200, holderClass: 'custom', showClose: true, showCloseText: 'close', onBlurContainer: '.container', closeByDocument: false, template: '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '' + '
Add New Country
Input1
' }); alert("if" + result); } else { alert("else" + result); } }); }); </script> <script type="text/javascript"> function runMyFunction() { var username = document.getElementById('test_input').value; alert(username); } ``` </script>

Not work in IE6/7 ?

The demo page also not working in IE6/7.
It seems shown with opacity 0, so can't be seen (when mouse move to right place, mouse cursor will show in pointer).

Blur?

Is there a reason you didn't use the blur on the main page from the original demo?

REady function

How can i load the popup after 2 seconds after page is loaded?

Whole page moves when script activated

It's doing this weird thing where it scales the whole page and moves it out of view (down, center). I tried removing everything except the js and css files. I also made a fiddle for it.

http://jsfiddle.net/stinkysGTI/q55P2/
and
http://ndmr.com/new/

You have to scroll way down to see the intended popup. I tried copying it exactly as it appears on your site, but no luck. I also tried changing my jquery version to 1.7.2

Any ideas why it's doing this?

Thank you

Broken CSS when closing popin

Hi there,

First of all, thank you for this great job.
Here is the problem : I'm opening a popin, then closing it. When closing, one of my div (on the background) is reduced by its "min-height" value, instead of 100% as it should be when the window is full screen.

Here are some pictures to illustrate :

  • 1 : first screen with "test" button
  • 2 : popin
  • 3 : leaving popin leaves a white space below the blue div, which is reduced to the "min-height" value

1
2
3

I didn't find it on other topics, I hope someone can help me :)

Thanks in advance !!

Pass the clicked item for use in the template option

I'd like to be able to use $(this) in the template option to get data from the clicked object.

In my use-case, I have a bunch of links with the class of video on which I call avgrund. I'd like to get the href of the clicked item so I can use it in the displaying.

jQuery selector as template doesn't work

I can't get the jQuery selector as template to work. On top of the 1.2.0 :

  • Download the package
  • Add a #template div and style it
  • Add template: $('#template') to the avgrund call.
  • Modal is blank

Thank you !

Ajax support for avgrund.

I have named certain ids. I click on them and the popin is displayed with the information from server through Ajax [I'm sending the id-name that was clicked and that particular id is matched and the results are fetched]. However, I have to double click in order to get the popin displayed.

preventDefault for links

When set avgrund for links, it did not prevent going through that link. It will be great to have this, because sometimes you need fallback when js is disabled.

template class content doesn't work.

My content for popin!

$('element').avgrund({
template: $(".content")
});

When I click element i set , It pop up but nothing in there.

and I remove style="display:none;" , it works but The default page will show the content .

Vertical position is wrong if page content is longer than window height

I really liked this plugin! However, testing it's behaviour for bugs on the demo site revealed an issue that prevents me from using it.
Please have a look at the screenshots to see the issue.

Screenshot before triggering the dialog
screen shot 2014-04-14 at 11 12 36

Screenshot after the dialog is triggered
screen shot 2014-04-14 at 11 12 48

as you can clearly see, half the dialog is outside the window.

Select2 doesn't work with Avgrund popin

Hello,
I'm trying to implement select2 into an Avgrund popin but nothing happens when clicking on the select element... I've tried it out of the popin, it perfectly works. I have no console error...
Does anyone know the problem ?
Thanks in advance,
Lo

Edit : here is a fiddle http://jsfiddle.net/QgWa2/17/

add seperate .close() method

As it was requested by users - add ability to close popup with single method call (this change also needs some plugin pattern modification).

Maybe another useful methods could be added as well.

CSS3 transition issues in IE and Firefox

Hello, and first of all: great plugin!

I'd wanted to ask you if you know a fix for two CSS related problems I encountered using avgrund though:

  • IE9 won't apply the body.avgrund-active {-ms-transform: scale(0.9);} to children elements that use fixed positioning (they will stay fixed as in FIXED). All other browser will apply this correctly. Is there a way to work around this?
  • Firefox (v13 - [EDIT: just updated to v15 and it's still the same]) will somehow ruin the "depth-like"-effect as the popin will be scaled back (just like the background) instead of scaled up (like in all other browsers), therefore losing the illusion of z-movement. This is also visible in your demo page. I guess this might be caused by FF ignoring the preceding transform rules whereas other browser will add them up (I ain't no CSS3 wizard, so this is just an assumption)?

If you have any tip or fix for that I'd be super-thankful.

In any case: thank you!

Scroll To Top on Launch

Is there anyway to avoid that the page content scrolls to the top when the modal is opened? It would be much smoother and less jarring if it maintained the current scroll position. It might be a factor of your removing scrollbars (if you are doing this)...in which case, maybe removal of scrollbars can be an option?

Dynamic content fails to load

template = typeof options.template === 'function' ?
options.template(self) : options.template;

...instead of...

template = typeof options.template === 'function' ?
options.template(self) :
options.template instanceof jQuery ?
options.template.html() :
options.template;

...and also...

var div = $('<div class="avgrund-popin ' + options.holderClass + '"></div>');
div.append(template);
 body.append(div);

...instead of...

body.append('<div class="avgrund-popin ' + options.holderClass + '">'
+ template + '</div>');

Fluid layout support

Hi,

I am trying to use this plugin with twitter bootstraps fluid grid system. Due to (i think) the fixed pixel dimensions the popup does not behave well when the browser is resized. It might be nice to have percentage based layout and dimensions option.

What do you think?

Regards,

Jamie

"avgrund-popin custom stack" not displaying

Hello,

I am having a bit of trouble with the .custom box not displaying over the overlay. I see it on my view source but for some reason, it will not show on the front end. Any tips on what I am doing wrong? Thanks

-sophy

Close button CSS

Shouldn't this code snippet be in avgrund.css?

.avgrund-close {
    display: block;
    text-transform: uppercase;
    color: #555;
    text-decoration: none;
    position: absolute;
    top: 6px;
    right: 10px;
    font-size: 13px;
}

Its included in styles.css. In most of the cases, perhaps we would not want to include styles.css which is the CSS file for the demo on your Github pages.

Scroll

Hi. I'm using avgrund on a page and the content is a table. This table is long and the scroll dont work. How can i activate the scroll?
untitled-1

Explicit activate and deactivate

It would be nice to include the option to explicitly activate and deactivate, possibly similar to jqueryui $().dialog("open")

Long content pages

When using Avgrund on a page with long content you will need to tackle with current overlay -webkit behavior. Currently if parent element has transform property, all position: fixed child elements will behave as absolute. Also overflow: hidden doesn't work for child elements inside transformed one with fixed or absolute position.

As a solution you can use onLoad plugin option:

...
onLoad: function (elem) {
    // scroll to the top
}

Links to the chromium bugs, etc. - #7 (comment)

Center pop-up in window

I just started using Avgrund for a project, and it's working really well.

I have an <iframe> containing a video from youtube popping up, and it seems to be working well so far. However, the pop-up is opening at the top of the page, instead of in the center. Is there any easy fix for this?

Dynamic created Modal contents should be removed after closeing the Modal window

I have many links on a page, click on one link would pop up one Modal window with the link details in it.

After many clicks on different links, I would have many divs as follows:

<div class="avgrund-overlay "></div>
<div class="avgrund-popin ">link1....</div>
<div class="avgrund-overlay "></div>
<div class="avgrund-popin ">link2....</div>
....

The Close action doesn't remove that dynamic created Modal contents.

So I have to use the onUnload function to remove them after close the Modal window.

I checked the Demo, it doesn't have such a problem, but the Modal content is already there, so it's different from my problem.

I also tried to bind the avgrund method to as many elements as I can, the results were same.

So is it a problem for dynamic created Modal contents?

Thanks.

Overlay is darker second time round.

Thought I'd let you know of a little issue I am having.

When clicking the trigger to show the popin everything is fine, however when closing and re-clicking once again, the overlay is much darker than before.

I can't seem to track why this is happening, nothing in the CSS is different regarding opacities.

It is also doing it on your demo.

Any ideas?

Problem on webkit with blurry text

I had big problem with webkit based browsers (tested new Opera and Chrome) with text and content inside modal being blurry on animation end.
So what solved was to add :
-webkit-transform: translateZ(0px) !important;
on to .avgrund-active class... Dirty solution, and probably not the right one, but it works for me. I guess the problem was with font smoothing or something, my knowledge of this doesn't go that far :)

ajax support for template

I would like to use this plugin for my modal windows through my application, but would require getting the information from the server first, is there a way you can incorporate ajax templates?

Access jquery template variables in asp.net codebehind

My code creates a dynamic textbox and button in the avgrund template. I wish to fetch the value entered in the textbox in my asp.net codebehind (c#). Below is my code:

$(function () {
$('#Content_ddl_RepCountry').change(function () {
var result = $(this).val();

 if (result == "test") {
     $(this).avgrund({
         height: 200,
         holderClass: 'custom',
         showClose: true,
         showCloseText: 'close',
         onBlurContainer: '.container',
         closeByDocument: false,
         template:
         '<table id="tbl_heading" width="100%" height="100%">' +
         '<tr>' +
         '<td colspan="2"><span id="heading" class="heading">Add New Country</span></td>' +
         '</tr>' +
         '<tr>' +
         '<td colspan="2"></td>' +
         '</tr>' +
         '<tr>' +
         '<td class="P_td_label"><span id="test_span">Input1</span></td>' +
         '<td><input type="text" id="test_input" /></td>' +
         '</tr>' +
         '<tr>' +
         '<td colspan="2"><input type="submit" text="Save" id="btn_test" onclick="runMyFunction();return false" class="button"/></td>' +
         '</tr>' +
         '</table>'
     });


    }
    else {
         this.clearAttributes();

    }
});

});

Popup invisible when clicking too fast while closing

Browser: Google Chrome 39

When clicking outside the popup to close it (so, anywhere within the document), and click the "show popup" button while the popup hasn't been fully closed (or has only just closed), the page does blur / go dark, but no popup is shown.

Reproduction:

  • Go here: http://jsfiddle.net/m923boou/
  • Click "show" to open the popup
  • Now click anywhere to close it. While its being closed, hit "show" again.

The problem

The screen is grayed out, but there is no popup.

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.