nyroModal的使用方法
The plugin provide some function to work with it:
- nyroModal(); is the basic function to set the click or submit function. To add the nyroModal functionnality to all links containing in #container, you’ll do: $('#container a').nyroModal();
Pretty long, right? As all jQuery plugin, the chain is not broken. That mean you can use it like all other jQuery functions. You can also set the settings as an object paramter to overwrite the default parameter.
- nyroModalManual(); will execute the same action like a click in a real link. You can simulate an user click or create your modal content. See demos to better understand.
- $.nyroModalSettings(settings); could be used to change the default settings if no modal are started or the current settings if a modal is currently shown. For example, it will be pretty useful to change the modal size or background color from an Ajax request. If you call this function with the width, height, and/or bgColor parameters while the modal is already shown, the related animation function will be called.
- $.nyroModalRemove(); will simply remove the modal. Could be useful if you need to close after a time or something else.
When using the gallery modal, you can also use these functions:
- $.nyroModalNext(); Go to the next image. Return the link which opened the image if successful or false if nothing was done
- $.nyroModalPrev(); Go to the previous image. Return the link which opened the image if successful or false if nothing was done
When you open a modal using an Ajax request, the scripts included in the loaded page are executed folowing these rules:
- If the modal is a targeting content, only the scripts inside this element are executed
- If the modal isn’t targeting: - All the inline script are executed
- The scripts with a src attribute to load a javascript file are loaded only if they are the attribute rel=”forceLoad”. This avoid the reload of jQuery for example
If you need to investigate what’s going on with your modal, you could enable the debug. But sometimes, it’s not enough and you want more. You could overwrite the function nyroModalDebug(msg, elts, settings); to do what ever you want!
Settings
You have 3 different ways to modify the settings:
- Directly modify $.fn.nyroModal.settings. These settings will be used by default for every modal which will be open
- Set at first parameter to the nyroModal(); function. Example: $('a.nyroModal').nyroModal({bgColor: '#ffffff'});
- Use the $.nyroModalSettings(settings); function
Here is the complete usable settings list, with their default values.
$.fn.nyroModal.settings = { debug: false, // Show the debug in the background blocker: false, // Element which will be blocked by the modal windowResize: true, // indicates if the modal should resize when the window is resized modal: false, // Esc key or click backgrdound enabling or not type: '', // nyroModal type (form, formData, iframe, image, etc...) forceType: null, // Used to force the type from: '', // Dom object where the call come from hash: '', // Eventual hash in the url processHandler: null, // Handler just before the real process selIndicator: 'nyroModalSel', // Value added when a form or Ajax is sent with a filter content formIndicator: 'nyroModal', // Value added when a form is sent content: null, // Raw content if type content is used bgColor: '#000000', // Background color ajax: {}, // Ajax option (url, data, type, success will be overwritten for a form, url and success only for an ajax call) swf: { // Swf player options if swf type is used. wmode: 'transparent' }, width: null, // default Width If null, will be calculate automatically height: null, // default Height If null, will be calculate automatically minWidth: 400, // Minimum width minHeight: 300, // Minimum height resizable: true, // Indicate if the content is resizable. Will be set to false for swf autoSizable: true, // Indicate if the content is auto sizable. If not, the min size will be used padding: 20, // padding for the max modal size regexImg: '[^.].(jpg|jpeg|png|tiff|gif|bmp)\s*