lib/shutterbug/shutterbug.js in shutterbug-0.0.8 vs lib/shutterbug/shutterbug.js in shutterbug-0.0.9

- old
+ new

@@ -90,20 +90,22 @@ }; var requestHtmlFrag = function() { var destination = $(this.element)[0].contentWindow; var message = { - type: 'htmlFragRequest' + type: 'htmlFragRequest', + id: this.id }; destination.postMessage(JSON.stringify(message),"*"); }; - window.Shutterbug = function(selector,imgDst,callback) { + window.Shutterbug = function(selector,imgDst,callback,id) { var shutterbugInstance = { element: selector, imgDst: imgDst, callback: callback, + id: id, getDomSnapshot: getPng, getPng: getPng, getHtmlFragment: getHtmlFragment, requestHtmlFrag: requestHtmlFrag }; @@ -114,11 +116,12 @@ data = JSON.parse(data); } if(data.type === 'htmlFragRequest') { var response = { type: 'htmlFragResponse', - value: shutterbugInstance.getHtmlFragment() + value: shutterbugInstance.getHtmlFragment(), + id: data.id // return to sender only... }; message.source.postMessage(JSON.stringify(response),"*"); } }; @@ -127,11 +130,13 @@ if (typeof data === 'string') { data = JSON.parse(data); } var html = null; if(data.type === 'htmlFragResponse') { - html = data.value; - shutterbugInstance.getPng(html); + if(data.id == shutterbugInstance.id) { + html = data.value; + shutterbugInstance.getPng(html); + } } }; window.addEventListener('message', htmlFragRequestListen, false); window.addEventListener('message', htmlFragResponseListen, false); return shutterbugInstance; \ No newline at end of file