{I" class:ETI"BundledAsset;FI"logical_path;TI"magic_lamp/application.js;FI" pathname;TI"[/Users/Michael/Development/magic_lamp/app/assets/javascripts/magic_lamp/application.js;FI"content_type;TI"application/javascript;TI" mtime;Tl+υTI" length;Ti]I" digest;TI"%c8c1eefe1bdfa3e29b08e0d19952a1c6;FI" source;TI"]var MagicLamp = { initialize: function() { this.genie = new this.Genie(); }, fixtureNames: function() { return this.genie.fixtureNames(); }, globalize: function() { var context = this; window.load = function(path) { context.load(path); }; window.clean = function() { context.clean(); }; }, load: function() { this.genie.load.apply(this.genie, arguments); }, preload: function() { this.genie.preload.apply(this.genie, arguments); }, clean: function() { this.genie.removeFixtureContainer(); } }; // aliases MagicLamp.rub = MagicLamp.load; MagicLamp.wish = MagicLamp.load; MagicLamp.massage = MagicLamp.preload; MagicLamp.wishForMoreWishes = MagicLamp.preload; MagicLamp.polish = MagicLamp.clean; (function(global) { function Genie() { this.cache = {}; this.cacheOnly = false; this.namespace = MagicLamp; } Genie.prototype = { load: function(path) { this.removeFixtureContainer(); var fixture = this.cache[path]; this.createFixtureContainer(); if (!fixture && this.cacheOnly) { throw new Error('The fixture "' + path + '" was not preloaded. Is the fixture registered? Call `MagicLamp.fixtureNames()` to see what is registered.'); } else if (!fixture) { var xhr = this.xhrRequest(getPath() + '/' + path); this.cache[path] = fixture = xhr.responseText; } this.fixtureContainer.innerHTML = fixture; this.appendFixtureContainer(); }, preload: function() { var xhr = this.xhrRequest(getPath()); var json = JSON.parse(xhr.responseText); this.cache = json; this.cacheOnly = true; }, fixtureNames: function() { var names = []; for (fixtureName in this.cache) { if (this.cache.hasOwnProperty(fixtureName)) { names.push(fixtureName); } } var sortedNames = names.sort(); for (var i = 0; i < sortedNames.length; i++) { console.log(sortedNames[i]); }; return sortedNames; }, createFixtureContainer: function() { var div = document.createElement('div'); div.setAttribute('class', this.namespace.class || 'magic-lamp'); this.fixtureContainer = div; }, appendFixtureContainer: function() { document.body.appendChild(this.fixtureContainer); }, removeFixtureContainer: function() { if (this.fixtureContainer) { remove(this.fixtureContainer); this.fixtureContainer = undefined; } }, handleError: function(errorMessage) { throw new Error(errorMessage); }, xhrRequest: function(path) { var xhr = newXhr(); xhr.open('GET', path, false); xhr.send(); if (this.xhrStatus(xhr) === 400) { this.handleError(xhr.responseText); } else if (this.xhrStatus(xhr) === 500) { this.handleError('Something went wrong while generating the fixture, please check the server log or run `rake magic_lamp:lint` for more information'); } return xhr; }, xhrStatus: function(xhr) { return xhr.status; } }; // private function getPath() { return MagicLamp.path || '/magic_lamp'; } function remove(node) { var parentNode = node.parentNode; parentNode && parentNode.removeChild(node); } function newXhr() { var xhr; if (window.XMLHttpRequest) { // Mozilla, Safari, ... xhr = new XMLHttpRequest(); } else if (window.ActiveXObject) { // IE try { xhr = new ActiveXObject('Msxml2.XMLHTTP'); } catch (error) { try { xhr = new ActiveXObject('Microsoft.XMLHTTP'); } catch (e) { // let it go } } } if (!xhr) { throw('Unable to make request'); } return xhr; } MagicLamp.Genie = Genie; })(this); // This is a manifest file that'll be compiled into application.js, which will include all the files // listed below. // // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. // // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the // compiled file. // // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details // about supported directives. // ; ;TI"required_assets_digest;TI"%1a6fc85a1ad70c6c60b929fe2924e2f9;FI" _version;TI"%ab99cd0f5431c7de63d5e152ef71df5c;F