views:

311

answers:

2

I've implemented the simplemodal plugin for JQuery. Very nice btw! Where I'm having an issue, is I have a list of links that are generated from a database, when I click one, I make a "load" call and add the results to my osx-modal-content div. How do I call the osx plugin after my load completes? If I add class=osx to my a href, the modal opens before the content get into the div.

My Function to load html:

function loadContent(id) {
  $("#osx-modal-dialog").load("Item.cfm?ID="+id+"");
  // call OSX here????
  $('#osx-modal-dialog').modal();
 }

My DIV:

<div id="osx-modal-dialog">
  <div id="osx-modal-content">
<div id="osx-modal-title">Title</div>
<div id="osx-modal-data">
 <h2>Summary</h2>
    <p>Description</p>
 <p><button class="simplemodal-close">Close</button> <span>(or press ESC or click the overlay)</span></p>
</div>
  </div>
</div>

Currently the osx plugin is looking for input or a click event. I'm not sure how to script a 'click' event ofter my load. Or maybe there is a better way to call the plugin.

Includes:

A: 

The load method has a callback parameter where you can supply a function that will be executed when the load has completed. Use this callback to do trigger the dialog.

function loadContent(id) {
    $("#osx-modal-dialog").load("Item.cfm?ID="+id+"", function() {
        $('input.show-info').unbind('click') // remove any existing handlers
                            .click( function() { // bind click on button to show dialog
             $('#osx-modal-dialog').modal();
        });
    });
}

Update: I've updated this to show how to add a click handler in the callback of load(), but I don't know what event you want to handle nor what element the event is triggered on. I'll assume that you want to show the dialog when you click a button with class "show-info".

tvanfosson
thanks for the quick reply. I can get the modal to open, my issue is calling the plugin to open the modal. The osx example has a link ex:<a href='#' class='osx'>Demo</a> and in the plugin osx.js: $("input.osx, a.osx").click(function...I need to simulate a click for 'a' with a class=osx.
dallasweb
Do you mean how do you call the loadContent() method? The code you are referencing is not simulating a click, but rather adding a handler that responds to a click and opens the dialog. You already have part of the handler -- the loadContent() function. All you need is a way to call loadContent() with the correct id based on some user action. I can add a sample click handler definition, but without more info on your html it may not be of much help.
tvanfosson
I have a link that pass the ID to the loadcontent function(<a href="javascript:loadContent('1234');">). Everything works as is. Instead of calling "$('#osx-modal-dialog').modal();" I'd like to utilize the osx plugin, But I'm not sure how to get it invoked after my data loads. If I add class=osx to my link, the osx plugin fires off before the data loads into the div and I'm one click ahead of data that gets displayed. So, I need to either simulate the a.osx click...or modify the plugin test to something I can invoke from the load.callback()
dallasweb
When do you want the dialog displayed? When they click on something else? What is that other thing?
tvanfosson
If you'd show more of your html I might be able to help more.
tvanfosson
I appreciate your willingness to help. The page lives on an intranet, I'll throw everything on public website tonight and send a link. Thanks again.
dallasweb
A: 

Here's what I would do:

Modify the OSX content (I removed most of the content and added a placeholder):

       

<div id="osx-modal-content">
               <div id="osx-modal-title">OSX Style Modal Dialog</div>
               <div id="osx-modal-data">
                       <div id="osx-data-placeholder"></div>
                       <p><button class="simplemodal-close">Close</button> <span>(or press
ESC or click the overlay)</span></p>
               </div>
       </div>

Your loadContent function:

       

function loadContent(id) {
               var d = $('#osx-modal-content');

               // load your page
               $.get("Item.cfm?ID=" + id, function(data) {

                       // replace the placeholder with the results
                       $('#osx-data-placeholder', d[0]).html(data);

                       // open the osx modal
                       d.modal({
                               overlayId: 'osx-overlay',
                               containerId: 'osx-container',
                               closeHTML: '<div class="close"><a href="#"
class="simplemodal-close">x</a></div>',
                               minHeight:80,
                               opacity:65,
                               position:['0',],
                               overlayClose:true,
                               onOpen:OSX.open,
                               onClose:OSX.close
                       });
               });
       }

I haven't tested it, but I'm pretty sure this should do the trick.

-Eric

Eric Martin
Thanks for the insight. I'm getting the error: OSX is not definedAll needed js files are getting loaded as well as osx.css. Is OSX not defined because the osx.js plugin hasn't been triggered?
dallasweb
I was assuming that you were using the js file that came with the OSX download - where the OSX var is defined. Make sure the file is loaded or add this code to that file.
Eric Martin
Thanks for the help Eric. I pulled the Var OSX...code out of the plugin and added it to my script on the calling page...works fine..not ideal, but works.
dallasweb