Guest User

start.js

a guest
Sep 3rd, 2012
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if (typeof js_callback == 'undefined') {
  2.     var js_callback = false;
  3. }
  4.  
  5. var XD=function(){var e,g,h=1,f,d=this;return{postMessage:function(c,b,a){b&&(a=a||parent,d.postMessage?a.postMessage(c,b.replace(/([^:]+:\/\/[^\/]+).*/,"$1")):b&&(a.location=b.replace(/#.*$/,"")+"#"+ +new Date+h++ +"&"+c))},receiveMessage:function(c,b){if(d.postMessage)if(c&&(f=function(a){if("string"===typeof b&&a.origin!==b||"[object Function]"===Object.prototype.toString.call(b)&&!1===b(a.origin))return!1;c(a)}),d.addEventListener)d[c?"addEventListener":"removeEventListener"]("message",f,!1);
  6. else d[c?"attachEvent":"detachEvent"]("onmessage",f);else e&&clearInterval(e),e=null,c&&(e=setInterval(function(){var a=document.location.hash,b=/^#?\d+&/;a!==g&&b.test(a)&&(g=a,c({data:a.replace(b,"")}))},100))}}}();
  7.  
  8. var src = 'http://b.jobaudience.com/tpl/v1/ja.html#' + encodeURIComponent(document.location.href);
  9.  
  10. var div = document.createElement('div');
  11. div.setAttribute('style', 'visibility:hidden;position:absolute');
  12.  
  13. var iframe = document.createElement('iframe');
  14. iframe.setAttribute('src', src);
  15. iframe.setAttribute('width', 1);
  16. iframe.setAttribute('height', 1);
  17. iframe.setAttribute('marginwidth', 0);
  18. iframe.setAttribute('marginheight', 0);
  19. iframe.setAttribute('scrolling', 0);
  20. iframe.setAttribute('frameborder', 0);
  21.  
  22. div.appendChild(iframe);
  23. document.getElementsByTagName('body')[0].appendChild(div);
  24.  
  25. var _is_good = false;
  26.  
  27. XD.receiveMessage(function(message){
  28.     if (message.data.act == 'status') {
  29.         _is_good = true;
  30.     } else if (message.data.act == 'uid') {
  31.         if (message.data.uid) {
  32.             uidIsGet(message.data.uid);
  33.         } else {
  34.             setJsUid(js_uid);
  35.         }
  36.     }
  37. }, 'http://b.jobaudience.com');
  38.  
  39. var _check_ready = function() {
  40.     if (!_is_good) {
  41.         XD.postMessage({act : 'status'}, src, iframe.contentWindow);
  42.         setTimeout(_check_ready, 100);
  43.     } else {
  44.         XD.postMessage({act : 'get', key : 'js_uid'}, src, iframe.contentWindow);
  45.     }
  46. };
  47.  
  48. setTimeout(_check_ready, 100);
  49.  
  50. function setJsUid(uid) {
  51.     window && window.localStorage && window.localStorage.setItem('js_uid', js_uid);
  52.     XD.postMessage({act : 'set', key : 'js_uid', value : js_uid}, src, iframe.contentWindow);
  53.  
  54.     js_callback && js_callback(uid)
  55. }
  56.  
  57. function uidIsGet(uid) {
  58.     js_uid = uid;
  59.     window && window.localStorage && window.localStorage.setItem('js_uid', uid);
  60.  
  61.     js_callback && js_callback(uid)
  62. }
Advertisement
Add Comment
Please, Sign In to add comment