// TODO - get these from somewhere
var cardManifests = {
  'card1_id': {'assets': {'card1.css': 'http://full-path-to/card1-fingerprint.css'}}
};

// Lookup a url in the manifest for this card
var cardManifestUrl = function(cardId, url) {
  var manifest = cardManifests[cardId];
  if (manifest && manifest.assets && manifest.assets[url]) {
    return manifest.assets[url];
  }
};

// Lookup a url in the manifest available to all cards
var glazierUrl = function(url) {
  if (Glazier.manifest) {
    var translatedUrl = Glazier.manifest[url];
    if (translatedUrl) {
      return Glazier.assetHost + translatedUrl;
    }
  }
  return null;
};

var ManifestXHRService = Conductor.XHRService.extend({
  requests: {
    /*
      @public

      Extend Conductor's XHRService to allow checking urls against a manifest so that cards
      can map non-fingerprinted urls to fingerprinted urls.

      Also alow glazier to provide fingerprinted urls for vendored assets that it uses to cards.

      By setting `Conductor.services['xhr'] = ManifestXHRService` this will take the place of the original XHRService.

      @method get
      @param promise {Conductor.Oasis.RSVP.Promise}
      @param url {String}
    */
    get: function(promise, url) {
      var processedUrl = cardManifestUrl(this.sandbox.card.id, url) || glazierUrl(url) || url;

      if (url !== processedUrl) {
        console.log("ManifestXHRService get ", url,  " -> ", processedUrl);
      }

      var xhrServiceGet = Conductor.XHRService.prototype.requests.get;
      return xhrServiceGet.apply(this, [promise, processedUrl]);
    }
  }
});

export = ManifestXHRService;

@@ -1,281 +1,236 @@
 // 
-TODO - get these from somewhere%0Avar cardManifests = %7B%0A  'card1_id': %7B'assets': %7B'card1.css': 'http://full-path-to/card1-fingerprint.css'%7D%7D%0A%7D;%0A%0A// Lookup a url in the manifest for this card%0Avar cardManifestUrl = function(cardId, url) %7B%0A  var manifest = cardManifests%5BcardId%5D;
+Lookup a url in the manifest for this card%0Avar cardManifestUrl = function(cardId, url) %7B%0A  // assume the manifest is already loaded, this is likely brittle%0A  var manifest = Glazier.Pane.find(cardId).get('cardManifest.manifest');%0A
 %0A  i
@@ -1367,17 +1367,16 @@
  get
- 
 %22, url, 
  %22 -
@@ -1375,14 +1375,11 @@
 rl, 
- %22 
+%22
 -%3E
- 
 %22, p

use live manifests