Skip to content
This repository has been archived by the owner on Jun 14, 2020. It is now read-only.

Commit

Permalink
Implement ajax.once compatibility in new Deferred casting. Remove AJA…
Browse files Browse the repository at this point in the history
…X plugin from Gruntfile
  • Loading branch information
Craga89 committed Apr 3, 2013
1 parent ce86648 commit e9026a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
1 change: 0 additions & 1 deletion Gruntfile.js
Expand Up @@ -44,7 +44,6 @@ module.exports = function(grunt) {
css3: '<%=dirs.src%>/css3.css'
},
plugins: {
ajax: { js: '<%=dirs.src%>/ajax/ajax.js' },
tips: { js: '<%=dirs.src%>/tips/tips.js', css: '<%=dirs.src%>/tips/tips.css' },
modal: { js: '<%=dirs.src%>/modal/modal.js', css: '<%=dirs.src%>/modal/modal.css' },
viewport: { js: '<%=dirs.src%>/position/viewport.js' },
Expand Down
13 changes: 9 additions & 4 deletions src/core.js
Expand Up @@ -2,7 +2,8 @@
function sanitizeOptions(opts)
{
var invalid = function(a) { return a === NULL || !$.isPlainObject(a); },
invalidContent = function(c) { return !$.isFunction(c) && ((!c && !c.attr) || c.length < 1 || ('object' === typeof c && !c.jquery && !c.then)); };
invalidContent = function(c) { return !$.isFunction(c) && ((!c && !c.attr) || c.length < 1 || ('object' === typeof c && !c.jquery && !c.then)); },
once;

if(!opts || 'object' !== typeof opts) { return FALSE; }

Expand All @@ -19,18 +20,22 @@ function sanitizeOptions(opts)
opts.content.text = FALSE;
}

// DEPRECATED - Old content.ajax plugin functionality
// Converts it into the proper Deferred syntax
if('ajax' in opts.content) {
once = opts.content.ajax.once !== FALSE;
opts.content.text = function(event, api) {
$.ajax(opts.content.ajax)
var deferred = $.ajax(opts.content.ajax)
.then(function(content) {
api.set('content.text', content);
if(once) { api.set('content.text', content); }
return content;
},
function(xhr, status, error) {
if(api.destroyed || xhr.status === 0) { return; }
api.set('content.text', status + ': ' + error);
});

return 'Loading...';
return !once ? deferred : 'Loading...';
};
}

Expand Down

0 comments on commit e9026a0

Please sign in to comment.