ASP.NET MVC 2 中的模型验证和元数据
from:
from:
1,首先我在页面中使用validate的插件进行表单的验证,
在这个时候,只有在form中的button为submit类型时才会自动触发验证事件.
The plugin provide some function to work with it:
$('#container a').nyroModal();When using the gallery modal, you can also use these functions:
When you open a modal using an Ajax request, the scripts included in the loaded page are executed folowing these rules:
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!
You have 3 different ways to modify the settings:
$('a.nyroModal').nyroModal({bgColor: '#ffffff'});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*$', // Regex to find images
addImageDivTitle: false, // Indicate if the div title should be inserted
defaultImgAlt: 'Image', // Default alt attribute for the images
setWidthImgTitle: true, // Set the width to the image title
ltr: true, // Right to left by default. Put to false for Hebrew or Left to Right language
gallery: null, // Gallery name if provided
galleryLinks: 'PrevNext', // Use .nyroModalPrev and .nyroModalNext to set the navigation link
galleryCounts: galleryCounts, // Callback to show the gallery count
galleryLoop: false, // Indicate if the gallery should loop
zIndexStart: 100,
cssOpt: { // Default CSS option for the nyroModal Div. Some will be overwritten or updated when using IE6
bg: {
position: 'absolute',
overflow: 'hidden',
top: 0,
left: 0,
height: '100%',
width: '100%'
},
wrapper: {
position: 'absolute',
top: '50%',
left: '50%'
},
wrapper2: {
},
content: {
},
loading: {
position: 'absolute',
top: '50%',
left: '50%',
marginTop: '-50px',
marginLeft: '-50px'
}
},
wrap: { // Wrapper div used to style the modal regarding the content type
div: '',
ajax: '',
form: '',
formData: '',
image: '',
swf: '',
iframe: '',
iframeForm: '',
manual: ''
},
closeButton: 'Close', // Adding automaticly as the first child of #nyroModalWrapper
title: null, // Modal title
titleFromIframe: true, // When using iframe in the same domain, try to get the title from it
openSelector: '.nyroModal', // selector for open a new modal. will be used to parse automaticly at page loading
closeSelector: '.nyroModalClose', // selector to close the modal
contentLoading: 'Cancel', // Loading div content
errorClass: 'error', // CSS Error class added to the loading div in case of error
contentError: 'The requested content cannot be loaded.
Please try again later.
Close', // Content placed in the loading div in case of error
handleError: null, // Callback in case of error
showBackground: showBackground, // Show background animation function
hideBackground: hideBackground, // Hide background animation function
endFillContent: null, // Will be called after filling and wraping the content, before parsing closeSelector and openSelector and showing the content
showContent: showContent, // Show content animation function
endShowContent: null, // Will be called once the content is shown
beforeHideContent: null, // Will be called just before the modal closing
hideContent: hideContent, // Hide content animation function
showTransition: showTransition, // Show the transition animation (a modal is already shown and a new one is requested)
hideTransition: hideTransition, // Hide the transition animation to show the content
showLoading: showLoading, // show loading animation function
hideLoading: hideLoading, // hide loading animation function
resize: resize, // Resize animation function
endResize: null, // Will be called one the content is resized
updateBgColor: updateBgColor, // Change background color animation function
endRemove: null // Will be called once the modal is totally gone
};As an effort to be as more flexible as possible, the plugin provide many callbacks that you can use to alter the data at different time in the process. To be more clear, here is the full process with all possible callback:
The object elts will contain these parameters:
To read more about the animation callback, see below.
You can redefine the animation as you want. To do so, you'll rewrite completly the animation function. That mean you can whatever you want. If you want simply show the element without any animation, you can simply do an show in the element and execute the callback. That's it.
To be more convenient, all animation callback function takes the exact same parameters:
The best way to start an animation function is probably to copy/paste his content from the plugin, see how it works and what is doing and then start edit it.
When positionning the loading or the content, you'll probably center it. To do so we usually use this king of CSS:
#element {
position: fixed;
width: 500px;
height: 300px;
margin-left: -250px; // -width / 2
margin-top: -150px; // -height / 2
}And it should works. But you probably know that IE6 doesn't understand the position fixed. That's why you have to use settings.marginScrollTop and settings.marginScrollLeft to be sure your element is well centered. These values will be equal to zero in the convenient browser, and equal to the scroll values in IE6. When showing the content, 2 others values are available to set the margin: settings.marginLeft and settings.marginTop. For example, the CSS for the content wrapper is set like that:
function showContent(elts, settings, callback) {
elts.contentWrapper
.css({ // Reset the CSS at the start position
marginTop: (-100/2 + settings.marginScrollTop)+'px',
marginLeft: (-100/2 + settings.marginScrollLeft)+'px',
height: '100px',
width: '100px',
opacity: 0
})
.show()
.animate({ // Set the width
width: settings.width+'px',
marginLeft: (settings.marginLeft)+'px',
opacity: 0.5
}, {duration: 350})
.animate({ // Set the height
height: settings.height+'px',
marginTop: (settings.marginTop)+'px',
opacity: 1
}, {complete: callback, duration: 350});
}Because understand how the modal is resized could be a nightmare, here is the explanation about how works nyroModal.
Firstly, there is minWidth and minHeight which will apply everytime regardless the modal content type. By default, these values are set to 150 by 150.
Then the modal window will never goes outside the viewport. If a dimension will be outside, it's decreased to fit with the view port.
There is a padding parameter (20 by default) used to space the external boundary of the modal from the viewport.
Regarding the images, they will be resized proportionnaly if they are to big to respect the padding described below.
When you make an Ajax Request, you'll show HTML content. In nyroModal, the size requested will be the real content size available inside the #nyroModalContent div. That mean the content inside the padding of the #nyroModalContent div will be the requested dimensions. For example, requested a 500 by 500 pixels size will result for the #nyroModalContent of these values (screenshot made with Firebug):
Why do that?
Imagine working on a website using nyroModal. When requested your modal with different size, you'll take care of the content to fit exactly with the design. That works and everybody is happy.
But 3 months later the design has to be changed regarding the nyroModal looks and feel for adding some margin or border.
As the dimensions is the content inside the modal, changing the dimensions of the margin, padding or border of the wrapper or content won't change the shown dimensions. To make the change you only have to change your CSS and check for some modal if it's work as expected.