GithubHelp home page GithubHelp logo

kylefox / jquery-modal Goto Github PK

View Code? Open in Web Editor NEW
2.6K 74.0 663.0 301 KB

The simplest possible modal for jQuery

Home Page: http://jquerymodal.com/

License: Other

JavaScript 70.41% CSS 29.59%
jquery-modal modal-plugin jquery javascript modal dialog

jquery-modal's Introduction

A simple & lightweight method of displaying modal windows with jQuery.

For quick examples and demos, head to jquerymodal.com.

Why another modal plugin?

Most plugins I've found try to do too much, and have specialized ways of handling photo galleries, iframes and video. The resulting HTML & CSS is often bloated and difficult to customize.

By contrast, this plugin handles the two most common scenarios I run into

  • displaying an existing DOM element
  • loading a page with AJAX

and does so with as little HTML & CSS as possible.

Installation

You can install jquery-modal with npm:

npm install jquery-modal

or with Bower:

bower install jquery-modal

or use the hosted version from cdnjs:

<!-- Remember to include jQuery :) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>

<!-- jQuery Modal -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.2/jquery.modal.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.2/jquery.modal.min.css" />

Using Rails? Check out the jquery-modal-rails plugin!

jQuery Requirements: As of version 0.3.0, jQuery 1.7 is required. If you're using an earlier version of jQuery you can use the v.0.2.5 tag.

Naming conflict with Bootstrap: Bootstrap's modal uses the same $.modal namespace. If you want to use jquery-modal with Bootstrap, the simplest solution is to manually modify the name of this plugin.

Opening

Method 1: Automatically attaching to links

The simplest approach is to add rel="modal:open" to your links and use the href attribute to specify what to open in the modal.

Open an existing DOM element by ID:

<form id="login-form" class="modal">
  ...
</form>

<a href="#login-form" rel="modal:open">Login</a>

Load a remote URL with AJAX:

<a href="login.html" rel="modal:open">Login</a>

Method 2: Manually

You can manually open a modal by calling the .modal() method on the element:

<form id="login-form" class="modal">
  ...
</form>
$('#login-form').modal();

You can also invoke .modal() directly on links:

<a href="#ex5" data-modal>Open a DOM element</a>
<a href="ajax.html" data-modal>Open an AJAX modal</a>
$('a[data-modal]').click(function(event) {
  $(this).modal();
  return false;
});

Compatibility Fallback

You can provide a clean fallback for users who have JavaScript disabled by manually attaching the modal via the data-modal attribute. This allows you to write your links pointing to the href as normal (fallback) while enabling modals where JavaScript is enabled.

<!-- By default link takes user to /login.html -->
<a href="/login.html" data-modal="#login-modal">Login</a>

<!-- Login modal embedded in page -->
<div id="login-modal" class="modal">
  ...
</div>

<!-- For browsers with JavaScript, open the modal. -->
<script>
  $(function() {
    $('a[data-modal]').on('click', function() {
      $($(this).data('modal')).modal();
      return false;
    });
  });
</script>

Fade Transitions

By default the overlay & window appear instantaneously, but you can enable a fade effect by specifying the fadeDuration option.

$('a.open-modal').click(function(event) {
  $(this).modal({
    fadeDuration: 250
  });
  return false;
});

This will fade in the overlay and modal over 250 milliseconds simultaneously. If you want the effect of the overlay appearing before the window, you can specify the fadeDelay option. This indicates at what point during the overlay transition the window transition should begin.

So if you wanted the window to fade in when the overlay's was 80% finished:

$(elm).modal({
  fadeDuration: 250,
  fadeDelay: 0.80
});

Or, if you wanted the window to fade in a few moments after the overlay transition has completely finished:

$(elm).modal({
  fadeDuration: 250,
  fadeDelay: 1.5
});

The fadeDelay option only applies when opening the modal. When closing the modal, both the modal and the overlay fade out simultaneously according to the fadeDuration setting.

Fading is the only supported transition.

Closing

Because there can be only one modal active at a single time, there's no need to select which modal to close:

$.modal.close();

Similar to how links can be automatically bound to open modals, they can be bound to close modals using rel="modal:close":

<a href="#close" rel="modal:close">Close window</a>

(Note that modals loaded with AJAX are removed from the DOM when closed).

Checking current state

  • Use $.modal.isActive() to check if a modal is currently being displayed.
  • Use $.modal.getCurrent() to retrieve a reference to the currently active modal instance, if any.

Options

These are the supported options and their default values:

$.modal.defaults = {
  closeExisting: true,    // Close existing modals. Set this to false if you need to stack multiple modal instances.
  escapeClose: true,      // Allows the user to close the modal by pressing `ESC`
  clickClose: true,       // Allows the user to close the modal by clicking the overlay
  closeText: 'Close',     // Text content for the close <a> tag.
  closeClass: '',         // Add additional class(es) to the close <a> tag.
  showClose: true,        // Shows a (X) icon/link in the top-right corner
  modalClass: "modal",    // CSS class added to the element being displayed in the modal.
  blockerClass: "modal",  // CSS class added to the overlay (blocker).

  // HTML appended to the default spinner during AJAX requests.
  spinnerHtml: '<div class="rect1"></div><div class="rect2"></div><div class="rect3"></div><div class="rect4"></div>',

  showSpinner: true,      // Enable/disable the default spinner during AJAX requests.
  fadeDuration: null,     // Number of milliseconds the fade transition takes (null means no transition)
  fadeDelay: 1.0          // Point during the overlay's fade-in that the modal begins to fade in (.5 = 50%, 1.5 = 150%, etc.)
};

Events

The following events are triggered on the modal element at various points in the open/close cycle (see below for AJAX events).

$.modal.BEFORE_BLOCK = 'modal:before-block';    // Fires just before the overlay (blocker) appears.
$.modal.BLOCK = 'modal:block';                  // Fires after the overlay (block) is visible.
$.modal.BEFORE_OPEN = 'modal:before-open';      // Fires just before the modal opens.
$.modal.OPEN = 'modal:open';                    // Fires after the modal has finished opening.
$.modal.BEFORE_CLOSE = 'modal:before-close';    // Fires when the modal has been requested to close.
$.modal.CLOSE = 'modal:close';                  // Fires when the modal begins closing (including animations).
$.modal.AFTER_CLOSE = 'modal:after-close';      // Fires after the modal has fully closed (including animations).

The first and only argument passed to these event handlers is the modal object, which has four properties:

modal.$elm;       // Original jQuery object upon which modal() was invoked.
modal.options;    // Options passed to the modal.
modal.$blocker;   // The overlay element.
modal.$anchor;    // Anchor element originating the event.

So, you could do something like this:

$('#purchase-form').on($.modal.BEFORE_CLOSE, function(event, modal) {
  clear_shopping_cart();
});

AJAX

Basic support

jQuery Modal uses $.get for basic AJAX support. A simple spinner will be displayed by default (if you've included modal.css) and will have the class modal-spinner. If you've set the modalClass option, the spinner will be prefixed with that class name instead.

You can add text or additional HTML to the spinner with the spinnerHtml option, or disable the spinner entirely by setting showSpinner: false.

The default spinner is from the excellent SpinKit by Tobias Ahlin ๐Ÿ‘

Events

The following events are triggered when AJAX modals are requested.

$.modal.AJAX_SEND = 'modal:ajax:send';
$.modal.AJAX_SUCCESS = 'modal:ajax:success';
$.modal.AJAX_FAIL = 'modal:ajax:fail';
$.modal.AJAX_COMPLETE = 'modal:ajax:complete';

The handlers receive no arguments. The events are triggered on the <a> element which initiated the AJAX modal.

More advanced AJAX handling

It's a good idea to provide more robust AJAX handling -- error handling, in particular. Instead of accommodating the myriad $.ajax options jQuery provides, jquery-modal makes it possible to directly modify the AJAX request itself.

Simply bypass the default AJAX handling (i.e.: don't use rel="modal")

<a href="ajax.html" rel="ajax:modal">Click me!</a>

and make your AJAX request in the link's click handler. Note that you need to manually append the new HTML/modal in the success callback:

$('a[rel="ajax:modal"]').click(function(event) {

  $.ajax({

    url: $(this).attr('href'),

    success: function(newHTML, textStatus, jqXHR) {
      $(newHTML).appendTo('body').modal();
    },

    error: function(jqXHR, textStatus, errorThrown) {
      // Handle AJAX errors
    }

    // More AJAX customization goes here.

  });

  return false;
});

Note that the AJAX response must be wrapped in a div with class modal when using the second (manual) method.

Bugs & Feature Requests

Found a bug? MEH!

Just kidding. Please create an issue and include a publicly-accessible demonstration of the bug. Dropbox or JSFiddle work well for demonstrating reproducable bugs, but you can use anything as long as it's publicly accessible. Your issue is much more likely to be resolved/merged if it includes a fix & pull request.

Have an idea that improves jquery-modal? Awesome! Please fork this repository, implement your idea (including documentation, if necessary), and submit a pull request.

I don't use this library as frequently as I used to, so if you want to see a fix/improvement you're best off submitting a pull request. Bugs without a test case and/or improvements without a pull request will be shown no mercy and closed!

Contributing

Maintainers Wanted

This library became more popular and active than I ever expected, and unfortunately I don't have time to maintain it myself.

If you are interested in helping me maintain this library, please let me know โ€” I would love your help!

Read more about becoming a maintainer ยป

I'd especially like people who would be excited about working towards a brand new jQuery Modal 2.0. See my Proposal for jQuery Modal 2.0 for more details & discussion.

How to contribute

I welcome improvements to this plugin, particularly with:

  • Performance improvements
  • Making the code as concise/efficient as possible
  • Bug fixes & browser compatibility

Please fork and send pull requests, or create an issue. Keep in mind the spirit of this plugin is minimalism so I'm very picky about adding new features.

Tips for development/contributing

  • Make sure dependencies are installed: npm install
  • After modifying jquery.modal.js and/or jquery.modal.css, you can optionally regenerate the minified files with gulp min and gulp css respectively.
  • Make sure you have updated documentation (README.md and/or examples/index.html) if necessary. Pull requests without documentation updates will be rejected.
  • Maintainers should increment version numbers and run gulp changelog when cutting a new release.

Support

Please post a question on StackOverflow. Commercial support by email is also available โ€” please contact [email protected] for rates. Unfortunately I am unable to provide free email support.

License (MIT)

jQuery Modal is distributed under the [MIT License](Learn more at http://opensource.org/licenses/mit-license.php):

Copyright (c) 2012 Kyle Fox

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

jquery-modal's People

Contributors

adiospace avatar alexwhin avatar artem-tim avatar bensmithett avatar chrisjlee avatar christiannaths avatar cryde avatar dei79 avatar denis-sokolov avatar devdaveo avatar dubfriend avatar elidupuis avatar emkae avatar garybenade avatar jaguadoromero avatar joonas-lahtinen avatar kyaido avatar kylefox avatar mciparelli avatar muzll0dr avatar paaatrick avatar ryanjones avatar sebastiandedeyne avatar xfra35 avatar xyanide avatar yokuyama avatar zjr 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

jquery-modal's Issues

Modal in z-indexed content

There's an issue when a modal content is inside a z-indexed parent.
Since the parent has its own z-index set, its children (modal included) will inherit that z-index. So regardless of the z-index you put for a modal it will be ruled by its parent. A workaround would be to detach modal bit from where it is and append to the body, so it's treated with it's own z-index. When modal is closed then we append it back to its original place.

Modal content must always be (invisible) display:none. Would be great if this was an option.

For example: A site may have references (anchors) to footnotes. The footnotes should always be visible. When user clicks on the link (anchor) for a footnote, the modal should appear, and close when requested (like it does now), but the original footnote should NOT disappear during this process.

I think it would be ideal to have another option that would allow the user to control this behavior.

close/resize functions should not be prototype methods

Calling $.fn.modal.close(); and $.fn.modal.resize() is a bit gross. These methods behave as functions because they close the current modal, regardless of which object they were invoked upon.

A more correct solution would be $.modal.close() and $.modal.resize()

  • This would be a backwards-incompatible change and thus the version number should be bumped accordingly.
  • Don't forget to update README.

Links within Modal

How do I add links within a modal that closes the modal and goes to the linked page when clicked?

Scroll modal window content

I didn't manage to make scrolling content of modal window. Basically you can look at Example 3: resizing on your demo page. After several resizes, modal window exceeds browser window but it still not scrollable.

Listening to all events on document raises a performance concern

This is not a bug, but this plugin listens by default to all the events ever happen anywhere in the document, and once they are triggered it checks if the target is a[rel=modal:open] or a[rel=modal:close].

This will happen on events such as any keyboard event, focus (any element), blur (any element). etc.

When working with large documents that have more than basic interactions, at some point it will become a performance issue, specially on older browsers, or slower CPUs (low end android tablets for instance).

I know ll your example relies on just setting <a rel="modal:open"> magic, and its great for non-programmers, but this also make it a no-go for real world applications.

Maybe that magic could live on a separate file?
Then both programmers and non-programmers can use it out of the box without modifying the source code.

call modal from a function

am having hard time to make an ajax call for content from a function and feed that data into modal.

switch(page) {
case "Urlset":
var urlstring = 'urlset_edit.php?urlset_db_id='+selectedurlsetid+'&srXXbv=XX01&srtid=tcwi6ujp4utcv1&action='+actiontype;
//alert("page is set to " + page + ", and action to " + actiontype + "!");
//console.log(urlstring);

        if (actiontype == 'Edit' && selectedurlsetid == ''){
            alert ('Please select a Urlset to edit');
        }
      else {
            $.ajax({

              url: urlstring,
              success: function(newHTML, textStatus, jqXHR) {
                $(newHTML).appendTo('body').modal();      
              },
              error: function(jqXHR, textStatus, errorThrown) {
                // Handle AJAX errors
              }
              // More AJAX customization goes here.
            });
      }
    break;

    default:
        var urlstring = 'urlset_edit.php?urlset_db_id='+selectedurlsetid+'&srXXbv=XX01&srtid=tcwi6ujp4utcv1&action='+actiontype;
        //alert("page is set to " + page + ", and action to " + actiontype + "!");
        if (actiontype == 'Edit' && selectedstateid == ''){
             alert ('Please select a State to edit');
        }
        else {
        // more stuff
        }

}

Modal exceeds browsers viewable area

Is there a way to make the modal only fill the viewable height of the browser if content exceeds the viewable area. Then I could implement a scroll for the content as needed. I looked around but I didn't see anything right off.

Add fade in/fade out effect

Hi,
it is possible to add an option to fade in and fade out the modal instead of instantly showing and hiding it?

The instant show/hide is good for some scenarios but for others a 'transition' is better.
To a lot of non-web people it take some time to figure out why all the screen is suddenly 'kind of black' and that a modal just opened. A 400 ms transition can fix this problem!

Thanks!

[enhancement] Add missing bower.json.

Hey, maintainer(s) of kylefox/jquery-modal!

We at VersionEye are working hard to keep up the quality of the bower's registry.

We just finished our initial analysis of the quality of the Bower.io registry:

7530 - registered packages, 224 of them doesnt exists anymore;

We analysed 7306 existing packages and 1070 of them don't have bower.json on the master branch ( that's where a Bower client pulls a data ).

Sadly, your library kylefox/jquery-modal is one of them.

Can you spare 15 minutes to help us to make Bower better?

Just add a new file bower.json and change attributes.

{
  "name": "kylefox/jquery-modal",
  "version": "1.0.0",
  "main": "path/to/main.css",
  "description": "please add it",
  "license": "Eclipse",
  "ignore": [
    ".jshintrc",
    "**/*.txt"
  ],
  "dependencies": {
    "<dependency_name>": "<semantic_version>",
    "<dependency_name>": "<Local_folder>",
    "<dependency_name>": "<package>"
  },
  "devDependencies": {
    "<test-framework-name>": "<version>"
  }
}

Read more about bower.json on the official spefication and nodejs semver library has great examples of proper versioning.

NB! Please validate your bower.json with jsonlint before commiting your updates.

Thank you!

Timo,
twitter: @versioneye
email: [email protected]
VersionEye - no more legacy software!

Multiple append "close" button

If you open modal window, then close and open it again there is multiple close button in source of page. Each time you close/open the same window a new button is added to modal.

Close Event on clicking X or calling modal:close

Hi is there a way to detect if a user click on X (close) button and then I can open a new modal for him/her?

I wants to get an event on closing the modal using X prefferably. So that I can open a new one with a message for user.

Please Help..

Thanks

Stop video playback?

I have an implementation where I'm using the modal to display and play a video from vimeo; however, when users click on the backdrop and exit the modal, the video keeps playing. To stop the video , you have to reclick the link and press the pause button, then exit out.

Is there a way I can pass the "hey pause/stop the video" command when users exit the modal? I'm investigating this myself, but if there was a known quick answer, I'd be happy for that, too :)

Working with Images

How do I get the modal to open a single image?

I'm trying to click a thumbnail and show the full size image in the modal, is this possible?

$.modal.close() return element

In Readme:

TODO: this should be changed so that when called on a specific element, the element is returned (normal jQuery fashion).

Why not return the element whenever $.modal.close() is called?

Multiple Modals

I know the docs say there can only be one modal at a time, but that's not what I'm finding. I have a link within a modal that opens another modal. What happens is I can stack modals over modals, but when I close the top-most one, I can't then close the others underneath it.

Modal default class (Bootstrap clash)

If you have bootstraps modal plugin on the page you'll end up with some css clashes. They can be over ridden, but it would be nice to maybe have a unique class or something specifically for this library?

IE:
.jq-modal {
}

Or possibly we could have an option to set the class?

modal is not destroyed when closed

When using ajax to construct modals on the page the element itself is just hidden when it is closed, this causes all sorts of problems when sending another ajax request using values from the modal as the browser will pick the value from the first hidden modal.

auto width

Hi, you don't set a fixed height so it can expand vertically, great. But why de default css comes with a fixed width: 400px?

Why not start with a auto width so the modal's content decide?

Ajax with filtering seems to disable the modal, with no discernible reason

When using filter() to grab a specific div inside the target html, modal fails. Here's my code:

$('a.quickview').click(function(event) {
      event.preventDefault();
      $.ajax({
      url: $(this).attr('href'),
      dataType: 'html',
      success: function(data, textStatus, jqXHR) {
        html = data;
        var newHTML = $(data).html();
        var oneval = $(newHTML).filter('#test').html();
        $(oneval).prependTo('body').modal();
      },
      error: function(jqXHR, textStatus, errorThrown) {
        // Handle AJAX errors
        alert('error');
      }
      // More AJAX customization goes here.
    });
    return false;
 });

The code works up to modal(). The data is prepended, but no modal occurs. But there is no error and no message indicating any failure.

When not filtering the data, modal() works fine.

AJAX calls don't show modal until request is complete

Would be nice if the modal would show right away (with a spinner or something) to provide instant feedback to the user rather than it looking like nothing happened.

Is this doable while still keeping things nice and simple? Loving the simplicity of this lib, by the way :)

Cascading modal

How can i do a cascading modal form ? (modal form in modal form)

Can the Modal be Responsive?

Hello,

Is it possible to make the modal responsive? I have a modal with the CSS:

width: 80%;
max-width: 480px;

This, in theory, would make the modal to be smaller than the window.
But never to become to large on big screens ...

But when I resize the window the modal has a strange behavior ...

Does any one knows if there is a way to make this work?

Thank You,
Miguel

Usability Issue: Allow scrolling

This is one that a lot of modals get wrong (but if you look at any major site, they get it right).

If the content of the modal is too large to fit on screen, users should be able to scroll the modal content (especially images). I settled on this plugin but this usability issue is a show-stopper.

You can test this by making the browser really small on the demo page and loading a modal which doesn't fit. Then try scrolling.

Bump a / Tag a version?

eh?

Looks like you've written the version as 0.5.2 in the source. However, the tag on the repository is at v0.2.5. So if certain applications try to glean version information about your repository via the tag (bower, perhaps?), they'll end up downloading the quite old v0.2.5 and their user will likely hit an issue about the fact that .live() is deprecated and maybe some other things.

Background Page Scrolling

What's the best way to stop the page from scrolling when the modal dialog box is open? I want content within the box to be able to scroll but not the background (i.e. page).

Fade transition double click bug

Under example 7, click the "example" link once and you'll get the correct behaviour:

screen shot 2014-05-15 at 5 21 12 pm

Double click quickly on the link and you'll get this bugged modal:

screen shot 2014-05-15 at 5 20 59 pm

This is a bug that users reported in our app so I'm reporting it here. If I find a fix then I'll send a pull request.

Thanks.

Embedded Tweet

It seems that the modal breaks when you try to put an embedded Tweet in it. Only the background gets dark but the modal doesn't show up. If you close the modal and open it again without reloading the page the modal works just fine and the Tweet displays correctly.

Edit: It seems that the problem is due to the fake height of the Tweet, the modal is positioned at -2700px.

Add support for jQuery with .noConflict() mode

When using jQuery with .noConflict() mode, jquery-modal throws error:

Cannot read property 'fn' of undefined

It can be easily fixed by replacing })(); with })(jQuery); and adding it as an argument on the begining of script - (function($) {. This way, even if jQuery was detatched from $ variable, plugin will work.

Naming conflict with bootstrap

I ran into the same issue #33 was having. I was getting a grey, unclickable background but the modal wouldn't show.

The problem seems to be the name of the plugin because it runs into a naming conflict with Bootstrap! So I replaced every occurrence of the word "modal" with "jmodal" in the plugin and now it works as expected.

I suggest using another variable for the global namespace, since bootstrap is widely used.

P.S.: I opened a new issue so people using bootstrap will find the solution faster.

blocker is not always defined.

unblock: function() {
this.blocker.remove();
Uncaught TypeError: Cannot call method 'remove' of undefined
},

The modal works in chrome and firefox but it won't work in IE with until this error gets resolved. Any ideas?

Modal is behind the blocker.

Triggering the modal via javascript is putting content behind the curtain (not in front as it was supposed to). This looks like a problem with z-indexs.

How can I fix this?

Fetching partial HTML in AJAX?

I was hoping you could lend me some insight about using .load() in place of .get() to fetch a partial from another page? Or is there perhaps a better way to implement this type of request?

To be clear, I have an external page but I only want the content of, say, div#content rather than the entire page. Any insight you could offer would be truly appreciated.

Advanced Ajax handling not jQuery 1.9 friendly

When invoking the modal using by using the advanced Ajax handling method the console returns

Uncaught Error: Syntax error, unrecognized expression: ...

$('.open-modal').on('click', function(){
    $.ajax({
        url: $(this).find('a').attr('href'),
        success: function(data, textStatus, jqXHR){
            $(data).appendTo('body').modal();
        }
    });
});

I'm trigging the event on a div container as opposed to an anchor tag.

The method above seems to work up to jQuery 1.8.2 but not 1.9.

However invoking the ajax modal on an anchor tag using rel="modal:open" works in 1.9.

Vertical positioning

It appears to centre vertically on the page, rather than fixed within the current screen/view. This results in having to scroll to see the dialog. Specifically seeing this issue within an iframe.

Next/Previous Arrows for Modals

Is there a fairly straightforward method to be able to add Previous/Next arrows to the modals, so viewers can cycle through a set of items (a portfolio, with images and content in the modals - hence why I'm not just using a lightbox) rather than having to close out and click on the next image to open its modal?

Vertical Positioning (again)

Is there a particular reason you're using height on line 119 to calculate the height rather than outerHeight? If the modal is padded - as in the example CSS - it doesn't center it vertically properly. It's a little too low.

A problem opening a new Modal from a link within AJAX loaded content

Hi Kyle,

Great work on the Modal.

I am just having one problem opening a new Modal from a link inside AJAX content.

The content loaded from AJAX is contained between <div class="modal"></div> and nothing else above or below and doesn't include any META tags only DIVS.

Here is the link inside the Modal

<a href="#open" id="open">Open</a>

and the Jscript in the main document

$('#open').click(function(event) {
event.preventDefault();
thisURL = "modal/content.asp";
$.get(thisURL, function(html) {
$(html).appendTo('body').modal();
});
});

Thanks for your help in advance.

Matt

bind to the close event ?

hi
I'd like to add some Js to the close event, is there a way to bind to it ?
something like this
$.modal.close( function(event){
alert();
} );

How to bind events before modal is opened?

How to bind events to modal before $.modal is triggered? Something like:

$(document).bind('reveal.modal', function() {
  alert('Hello world');
});

I have some functions that need to start with every ajax modal open.
Thanks in advance.

width of the modal window.

I can't resize the width of the modal.
I'm using rails and I have:

<%= link_to "Istruzioni", instructions_path, :rel => "modal:open", :id => "#istruzioni_modal" %>

in the css I have:

istruzioni_modal { width: 700px; }

but the modal window is not resized.

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.