diff options
| author | yo mama <pepper@scannerjammer.com> | 2015-09-22 00:51:40 -0700 |
|---|---|---|
| committer | yo mama <pepper@scannerjammer.com> | 2015-09-22 00:51:40 -0700 |
| commit | d3e7b5708deffbed864c916de22663f48333c58b (patch) | |
| tree | ef76784a7827baff88c03670bf22832a3f146b17 /share/frontend/js/pbembed.js | |
| parent | 86c79f4372d7b2e7640a26473c7a4d331cdf7d16 (diff) | |
finishing server
Diffstat (limited to 'share/frontend/js/pbembed.js')
| -rw-r--r-- | share/frontend/js/pbembed.js | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/share/frontend/js/pbembed.js b/share/frontend/js/pbembed.js new file mode 100644 index 0000000..97fa667 --- /dev/null +++ b/share/frontend/js/pbembed.js @@ -0,0 +1,65 @@ +$(function(){ + +// test if Photoblaster is being loaded in an iframe (=dump.fm) or not +var isEmbed = window != window.parent; + +if(isEmbed) { + + /* + * jQuery postMessage - v0.5 - 9/11/2009 + * http://benalman.com/projects/jquery-postmessage-plugin/ + * + * Copyright (c) 2009 "Cowboy" Ben Alman + * Dual licensed under the MIT and GPL licenses. + * http://benalman.com/about/license/ + */ + (function($){var g,d,j=1,a,b=this,f=!1,h="postMessage",e="addEventListener",c,i=b[h]&&!$.browser.opera;$[h]=function(k,l,m){if(!l){return}k=typeof k==="string"?k:$.param(k);m=m||parent;if(i){m[h](k,l.replace(/([^:]+:\/\/[^\/]+).*/,"$1"))}else{if(l){m.location=l.replace(/#.*$/,"")+"#"+(+new Date)+(j++)+"&"+k}}};$.receiveMessage=c=function(l,m,k){if(i){if(l){a&&c();a=function(n){if((typeof m==="string"&&n.origin!==m)||($.isFunction(m)&&m(n.origin)===f)){return f}l(n)}}if(b[e]){b[l?e:"removeEventListener"]("message",a,f)}else{b[l?"attachEvent":"detachEvent"]("onmessage",a)}}else{g&&clearInterval(g);g=null;if(l){k=typeof m==="number"?m:typeof k==="number"?k:100;g=setInterval(function(){var o=document.location.hash,n=/^#?\d+&/;if(o!==d&&n.test(o)){d=o;l({data:o.replace(n,"")})}},k)}}}})(jQuery); + + /* end postMessage */ + + var parent_url = decodeURIComponent( document.location.hash.replace( /^#/, '' ) ); + + // add click-to-dump to output image + $('#output-img').live("click", function(){ + $.postMessage(JSON.stringify({'command':'paste_url_to_dump_msginput', 'url':$(this).attr('src')}), parent_url, parent ); + }); + + // listen for a command from the parent. + $.receiveMessage(function(e){ + try{ + var data = JSON.parse(e.data) + + if ( data.command == 'image_url' ) { + + $("#img-url").val(data.url); + + $("#img-url").prev().css('background-color', 'white'); + $("#img-background").prev().css('background-color', 'white'); + + } else if ( data.command == 'background_url' ) { + + $("#img-background").val(data.url); + + $("#img-url").prev().css('background-color', 'white'); + $("#img-background").prev().css('background-color', 'white'); + + } else if ( data.command == 'img_drag' ) { + + // highlight while dragging to show which field this drag will go to + $("#img-background").prev().css('background-color', 'white'); + $("#img-url").prev().css('background-color', 'yellow'); + + } else if ( data.command == 'background_drag' ) { + + $("#img-url").prev().css('background-color', 'white'); + $("#img-background").prev().css('background-color', 'yellow'); + + } + }catch(e){ + console.log('receiveMessage (iframe): JSON parse error'); + } + }); + +} //isEmbed +}); + |
