Permalink
Browse files

Refactor Ajax features and add ajax setting in nmObj

  • Loading branch information...
1 parent 2a1e1af commit 1ff104065fb155520ad2c6e52ec1753473ae7bf0 @nyroDev committed Oct 21, 2012
Showing with 16 additions and 17 deletions.
  1. +3 −6 js/jquery.nyroModal.filters.form.js
  2. +10 −11 js/jquery.nyroModal.filters.link.js
  3. +3 −0 js/jquery.nyroModal.js
@@ -25,13 +25,12 @@ jQuery(function($, undefined) {
},
load: function(nm) {
var data = {};
- $.map(nm.opener.serializeArray(), function(d){
+ $.map(nm.opener.serializeArray(), function(d) {
data[d.name] = d.value;
});
if (nm.store.form.sel)
data[nm.selIndicator] = nm.store.form.sel.substring(1);
-
- var ajax = $.extend(true, { type : 'get', dataType : 'text' }, nm.ajax || {}, {
+ $.ajax($.extend(true, { type : 'get', dataType : 'text' }, nm.ajax || {}, {
@ADmad
ADmad Jan 1, 2013

Why specify dateType as "text" instead of letting the default jquery behavior of guessing type based on MIME type of response?
Specifying dataType causes jquery to also set the accepts accordingly, "text/plain" in case of dataType = "text". This caused me problems as my application does different things based on Accept header.

If found that I could override the dataType using the ajax key in nyromodal options (which btw is not listed on nyromodal.nyrodev.com) which solved my problem. But it would be better to not specify the dataType by default.

url: nm.store.form.url,
data: data,
type: nm.opener.attr('method') ? nm.opener.attr('method') : undefined,
@@ -41,9 +40,7 @@ jQuery(function($, undefined) {
error: function(jqXHR) {
nm._error(jqXHR);
}
- });
-
- $.ajax(ajax);
+ }));
},
destroy: function(nm) {
nm.opener.off('submit.nyroModal');
@@ -24,17 +24,16 @@ jQuery(function($, undefined) {
});
},
load: function(nm) {
- var ajax = $.extend(true, {}, nm.ajax || {}, {
- url: nm.store.link.url,
- data: nm.store.link.sel ? [{name: nm.selIndicator, value: nm.store.link.sel.substring(1)}] : undefined,
- success: function(data) {
- nm._setCont(data, nm.store.link.sel);
- },
- error: function(jqXHR) {
- nm._error(jqXHR);
- }
- });
- $.ajax(ajax);
+ $.ajax($.extend(true, {}, nm.ajax || {}, {
+ url: nm.store.link.url,
+ data: nm.store.link.sel ? [{name: nm.selIndicator, value: nm.store.link.sel.substring(1)}] : undefined,
+ success: function(data) {
+ nm._setCont(data, nm.store.link.sel);
+ },
+ error: function(jqXHR) {
+ nm._error(jqXHR);
+ }
+ }));
},
destroy: function(nm) {
nm.opener.off('click.nyroModal');
@@ -38,6 +38,9 @@ jQuery(function($, undefined) {
// Specific confirguation for DOM filter
domCopy: false, // Indicates if DOM element should be copied or moved
+ // Specific confirguation for link and form filters
+ ajax: {}, // Ajax options to be used in link and form filter
+
// Specific confirguation for image filter
imageRegex: '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$', // Regex used to detect image link

0 comments on commit 1ff1040

Please sign in to comment.