var Base64Binary = { _keyStr : "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=", /* will return a Uint8Array type */ decodeArrayBuffer: function(input) { var bytes = (input.length/4) * 3; var ab = new ArrayBuffer(bytes); this.decode(input, ab); return ab; }, decode: function(input, arrayBuffer) { //get last chars to see if are valid var lkey1 = this._keyStr.indexOf(input.charAt(input.length-1)); var lkey2 = this._keyStr.indexOf(input.charAt(input.length-2)); var bytes = (input.length/4) * 3; if (lkey1 == 64) bytes--; //padding chars, so skip if (lkey2 == 64) bytes--; //padding chars, so skip var uarray; var chr1, chr2, chr3; var enc1, enc2, enc3, enc4; var i = 0; var j = 0; if (arrayBuffer) uarray = new Uint8Array(arrayBuffer); else uarray = new Uint8Array(bytes); input = input.replace(/[^A-Za-z0-9\+\/\=]/g, ""); for (i=0; i> 4); chr2 = ((enc2 & 15) << 4) | (enc3 >> 2); chr3 = ((enc3 & 3) << 6) | enc4; uarray[i] = chr1; if (enc3 != 64) uarray[i+1] = chr2; if (enc4 != 64) uarray[i+2] = chr3; } return uarray; } } function get_domain() { var realRef = location.href; var now = realRef.indexOf('/view.html'); if(now > 0) { var rd = realRef.substring(0, now); } else { return false; } var ck = rd.indexOf('http://'); if(ck >= 0) { return rd; } else { return false; } } var real_xxx = 1; var bconnectURL; var reDo; var ipath; function show_sns_panel() { if(nonMail == 1) { alert("SNS공유가 제한된 책자 입니다."); return; } reDo = get_domain(); if(!reDo) { alert('SNS공유가 제한된 책자 입니다.'); return; } $("#dialog").dialog({ modal: true, resizable:false, title: "SNS 공유하기", width: 312, height: 414, zIndex: 9000, stack: true, close: function() { document.sns_form.sns_contetns.value=''; $(this).dialog('destroy'); } }); real_xxx = xxx; if(real_xxx > totalPage) real_xxx = totalPage; sns_str = booknameUTF+"\n"; bconnectURL = reDo+"/view.html?FdirectPageNum[]="+real_xxx; document.sns_form.sns_contetns.value = sns_str ; $('textarea#sns_contetns').blur(); var tp_path = "./"+PageData[real_xxx][1]+"/S_0.jpg"; ipath = reDo+"/"+PageData[real_xxx][1]+"/B_0.jpg"; $('#sns_cover').html(""); $('.ui-widget-overlay').css('z-index','9000'); $('.ui-front').css('z-index','9000'); $('.ui-dialog').css('z-index','9000'); } function send_sms() { location.href="sms://?body="+encodeURIComponent(document.sns_form.sns_contetns.value)+"\n"+bconnectURL; $('#dialog').dialog('destroy'); } function send_email() { var body = encodeURIComponent(bconnectURL+"
"+document.sns_form.sns_contetns.value); location.href="mailto:?subject="+encodeURIComponent(booknameUTF)+"&body="+body; $('#dialog').dialog('destroy'); } var sns_str; var accessToken; /* window.fbAsyncInit = function() { FB.init({ appId:fb_app_id, cookie : true, xfbml: true, version : 'v2.2' }); }; // Load the SDK asynchronously (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//connect.facebook.net/en_US/sdk.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'facebook-jssdk')); */ function print_r(array) { var str; for(var i in array) { str += i+':'+array[i]+'\n' } return str; } function send_facebook() { var surl = location.href; window.open("https://www.facebook.com/sharer/sharer.php?u="+surl); return; if(fb_app_id.length > 0) { $('#sloader').show(); FB.getLoginStatus(function(response) { if (response.status === 'connected') { if ( XMLHttpRequest.prototype.sendAsBinary === undefined ) { XMLHttpRequest.prototype.sendAsBinary = function(string) { var bytes = Array.prototype.map.call(string, function(c) { return c.charCodeAt(0) & 0xff; }); this.send(new Uint8Array(bytes).buffer); }; } accessToken = response.authResponse.accessToken; var text = encodeURIComponent(document.sns_form.sns_contetns.value) + "\n" + bconnectURL; var canv = document.createElement("canvas"); canv.setAttribute("id", "myCanvas"); document.body.appendChild(canv); $('#myCanvas').attr('width',bWidth); $('#myCanvas').attr('height',bHeight); var img = new Image(); img.width = bWidth; img.height = bHeight; img.src = ipath; img.onload = function () { try{ var context = canv.getContext("2d"); context.drawImage(img,0,0, canv.width, canv.height); var c = canv.toDataURL('image/jpeg'); var encodeIMG = c.substring(c.indexOf(',')+1, c.length); var decodeIMG = Base64Binary.decode(encodeIMG); var boundary = '----ThisIsTheBoundary1234567890'; // let's encode our image file, which is contained in the var var formData = '--' + boundary + '\r\n' formData += 'Content-Disposition: form-data; name="source"; filename="cover.jpg"\r\n'; formData += 'Content-Type: image/jpeg\r\n\r\n'; for ( var i = 0; i < decodeIMG.length; ++i ) { formData += String.fromCharCode( decodeIMG[ i ] & 0xff ); } formData += '\r\n'; formData += '--' + boundary + '--\r\n'; var xhr = new XMLHttpRequest(); xhr.open( 'POST', 'https://graph.facebook.com/me/photos?message='+text+'&access_token=' + accessToken, true ); xhr.onload = xhr.onerror = function() { console.log( xhr.responseText ); $('#dialog').dialog('destroy'); }; xhr.setRequestHeader( "Content-Type", "multipart/form-data; boundary=" + boundary ); xhr.sendAsBinary( formData ); $('#sloader').hide(); alert('facebook 전송 완료'); $('#dialog').dialog('destroy'); $('#myCanvas').remove(); } catch(e) { FB.api('/me/feed','post', { message: text , picture: ipath, source:ipath, description:'', link:bconnectURL}, function(response2) { if(!response2 || response2.error) { alert(print_r(response2.error)); } else { $('#sloader').hide(); alert('facebook 전송 완료'); $('#dialog').dialog('destroy'); } }); } }; $('#sloader').hide(); } else { alert('facebook 로그인후 이용가능합니다.\n팝업창차단시 팝업창허용후 이용가능'); $('#sloader').hide(); FB.login(function(response) { var fbname; accessToken = response.authResponse.accessToken; FB.api('/me', function(user) { fbname = user.name; alert('로그인 되었습니다.\n페이스북 버튼을 터치 하시면 전송 가능 합니다.'); }); }, {scope: 'publish_stream, user_likes'}); } }); } else { $('#sloader').hide(); alert('facebook 서비스 준비중 입니다.'); return; } } function send_twitter() { var text = document.sns_form.sns_contetns.value + "\n\n[ebook보기]\n"; window.open("https://twitter.com/intent/tweet?url="+encodeURIComponent(bconnectURL)+"&text="+encodeURIComponent(text),'twitter','width='+$(window).width()+',height='+$(window).height()); $('#dialog').dialog('destroy'); } function send_me2day() { var text = document.sns_form.sns_contetns.value + ":"+encodeURIComponent(bconnectURL); window.open("http://me2day.net/plugins/mobile_post/new?new_post[body]="+text+"&redirect_url="+ipath,'me2day','width='+$(window).width()+',height='+$(window).height()); $('#dialog').dialog('destroy'); } var kakao_init = false; var ka_app_id = "YOUR_KAKAO_KEY"; if(ka_app_id && ka_app_id != "YOUR_KAKAO_KEY") { (function(d, s, id){ var js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) {return;} js = d.createElement(s); js.id = id; js.src = "//developers.kakao.com/sdk/js/kakao.min.js"; fjs.parentNode.insertBefore(js, fjs); }(document, 'script', 'kakao-jssdk')); } function send_kakaotalk() { if(!ka_app_id || ka_app_id == 'YOUR_KAKAO_KEY') { alert('카카오톡 공유가 설정되지 않았습니다'); return; } if(!kakao_init){Kakao.init(ka_app_id); kakao_init = true;} var text = document.sns_form.sns_contetns.value + "\n" + ipath; Kakao.Link.sendTalkLink({ label: document.sns_form.sns_contetns.value, image: { src: ipath, width: '200', height: '270' }, webLink: { text : '[ 책보기 ]', url : bconnectURL } }); $('#dialog').dialog('destroy'); } function wrapWindowByMask(){ //화면의 높이와 너비를 구한다. var maskHeight = $(document).height(); var maskWidth = $(window).width(); //마스크의 높이와 너비를 화면 것으로 만들어 전체 화면을 채운다. $('#mask').css({'width':maskWidth,'height':maskHeight}); //애니메이션 효과 $('#mask').fadeIn(1000); $('#mask').fadeTo("slow",0.8); }