(function() { var data; data = { fabric: { type: 'shop', name: 'XCATS', stuff: 'Cool cats', staff: { boss: 'Lionel King', accountant: 'Marry A. Bobcat', sales: ['Katie Cat', 'ms. Ocelot', 'Snow, Leopold'] } } }; jQuery(function($) { var host; if (window.top === window) { return $('body').html("

This application is supposed to be running in a frame

"); } host = window.top; host.postMessage({ type: 'hello' }, '*'); return window.addEventListener('message', function(message) { var body, canvas, image, type, _ref; if (message.origin !== 'https://xgsm.pl') { console.error('This PostMessage event should be ignored. For test purposes it is not.'); } _ref = message.data, type = _ref.type, body = _ref.body; switch (type) { case 'init': canvas = document.createElement('canvas'); image = document.createElement('img'); $(image).one('load', function() { canvas.id = 'overlay'; canvas.height = image.height; canvas.width = image.width; canvas.getContext('2d').drawImage(image, 0, 0); return document.body.appendChild(canvas); }); image.src = body.overlay; if (image.complete || image.width) { return $(image).load(); } break; case 'get data': canvas = document.getElementById('overlay'); data.preview = canvas.toDataURL('image/png'); return message.source.postMessage({ type: 'data', body: data }, '*'); } }); }); }).call(this);