Quantcast
Channel: JavaScriptMVC Forum
Viewing all articles
Browse latest Browse all 3491

Re : How to determine if a file was not loaded by steal?

$
0
0
@paddybasi, 

I came across this when trying to do the same in JSMVC 3.3. The only issue I have here is that I can't see how to assign variables to the argument that is provided to the success function ... it is always undefined.

Ideally, I want to wrap this all into a Deferred so I can call it like:

  1. stealWithPromised('src')
  2.   .done(function(steal1, steal2) 
  3.   { 
  4.      // where steal1 and steal2 are javascript objects the same as if I use the standard steal function 
  5.   })
  6.   .fail(function(status) 
  7.   { 
  8.     // status will be 404, 500, etc; 
  9.   });
this is what I have so far, all working except for the having access to the stolen resource:

  1.         function stealWithPromise(src)
  2.         {
  3.           return $.Deferred(function(deferred)
  4.             {
  5.               var stel = steal.make(src);
  6.               stel.options.type = 'js';

  7.               stel.loaded.done(function( /* need js object/s here */)
  8.               {
  9.                 deferred.resolve( /* js object/s */);
  10.               });
  11.               stel.loaded.fail(function(status)
  12.               {
  13.                 deferred.reject(status);
  14.               });

  15.               if (stel.isLoaded)
  16.               {
  17.                 deferred.resolve( /* js object/s */);
  18.               }

  19.               if (stel.loading || stel.isLoaded)
  20.               {
  21.                 return;
  22.                 // what to return here is in the deferred
  23.               }

  24.               stel.loading = true;
  25.               steal.require(stel.options,
  26.                 function()
  27.                 {
  28.                   stel.loaded.resolve();
  29.                 },
  30.                 function()
  31.                 {
  32.                   stel.loaded.reject();
  33.                 });
  34.             })
  35.             .promise();
  36.         }



Viewing all articles
Browse latest Browse all 3491

Trending Articles