Skip to content

Commit

Permalink
Refactor Ajax features and add ajax setting in nmObj
Browse files Browse the repository at this point in the history
  • Loading branch information
nyroDev committed Oct 21, 2012
1 parent 2a1e1af commit 1ff1040
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 17 deletions.
9 changes: 3 additions & 6 deletions js/jquery.nyroModal.filters.form.js
Expand Up @@ -25,13 +25,12 @@ jQuery(function($, undefined) {
}, },
load: function(nm) { load: function(nm) {
var data = {}; var data = {};
$.map(nm.opener.serializeArray(), function(d){ $.map(nm.opener.serializeArray(), function(d) {
data[d.name] = d.value; data[d.name] = d.value;
}); });
if (nm.store.form.sel) if (nm.store.form.sel)
data[nm.selIndicator] = nm.store.form.sel.substring(1); data[nm.selIndicator] = nm.store.form.sel.substring(1);

$.ajax($.extend(true, { type : 'get', dataType : 'text' }, nm.ajax || {}, {

This comment has been minimized.

Copy link
@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.

var ajax = $.extend(true, { type : 'get', dataType : 'text' }, nm.ajax || {}, {
url: nm.store.form.url, url: nm.store.form.url,
data: data, data: data,
type: nm.opener.attr('method') ? nm.opener.attr('method') : undefined, type: nm.opener.attr('method') ? nm.opener.attr('method') : undefined,
Expand All @@ -41,9 +40,7 @@ jQuery(function($, undefined) {
error: function(jqXHR) { error: function(jqXHR) {
nm._error(jqXHR); nm._error(jqXHR);
} }
}); }));

$.ajax(ajax);
}, },
destroy: function(nm) { destroy: function(nm) {
nm.opener.off('submit.nyroModal'); nm.opener.off('submit.nyroModal');
Expand Down
21 changes: 10 additions & 11 deletions js/jquery.nyroModal.filters.link.js
Expand Up @@ -24,17 +24,16 @@ jQuery(function($, undefined) {
}); });
}, },
load: function(nm) { load: function(nm) {
var ajax = $.extend(true, {}, nm.ajax || {}, { $.ajax($.extend(true, {}, nm.ajax || {}, {
url: nm.store.link.url, url: nm.store.link.url,
data: nm.store.link.sel ? [{name: nm.selIndicator, value: nm.store.link.sel.substring(1)}] : undefined, data: nm.store.link.sel ? [{name: nm.selIndicator, value: nm.store.link.sel.substring(1)}] : undefined,
success: function(data) { success: function(data) {
nm._setCont(data, nm.store.link.sel); nm._setCont(data, nm.store.link.sel);
}, },
error: function(jqXHR) { error: function(jqXHR) {
nm._error(jqXHR); nm._error(jqXHR);
} }
}); }));
$.ajax(ajax);
}, },
destroy: function(nm) { destroy: function(nm) {
nm.opener.off('click.nyroModal'); nm.opener.off('click.nyroModal');
Expand Down
3 changes: 3 additions & 0 deletions js/jquery.nyroModal.js
Expand Up @@ -38,6 +38,9 @@ jQuery(function($, undefined) {
// Specific confirguation for DOM filter // Specific confirguation for DOM filter
domCopy: false, // Indicates if DOM element should be copied or moved 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 // Specific confirguation for image filter
imageRegex: '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$', // Regex used to detect image link imageRegex: '[^\.]\.(jpg|jpeg|png|tiff|gif|bmp)\s*$', // Regex used to detect image link


Expand Down

0 comments on commit 1ff1040

Please sign in to comment.