define(["jquery","./helpers"],function(e,t){function n(){var e="",n="",i="";window.getSelection?(n=window.getSelection())&&n.rangeCount>0&&(i=n.getRangeAt(0),e=n.toString()):document.selection&&"Control"!==document.selection.type&&(n=document.selection.createRange())&&n.rangeCount>0&&(i=n.getRangeAt(0),e=n.text);var a=o(e);c={text:e,twitterText:a,selection:n,range:i},t.pubsub.publish("text/selectedTextUpdated",[c])}function o(t){var n='"'+t+'" ',o=e('.social--large[data-social="twitter"]').attr("data-via"),i=" via @"+o,a=n.length+22+i.length+'..." '.length;return n=a>140?n.substring(0,140-(a-n.length))+'..." '+encodeURIComponent(r)+i:n+" "+encodeURIComponent(r)+" "+i}function i(o){n();var i=c.range.startOffset;if(c.text){var r=c.range.startContainer.nodeValue;if(e('[data-mht-block="article-detail__article-main"] *:contains("'+r+'")').last()[0]&&"undefined"!==i){var s=l();o.style.left=parseInt(s.left,10)-e(o).outerWidth()/2+"px",o.style.top=parseInt(s.top,10)-e(o).outerHeight()+"px",t.addClass("selection-share-popup--visible",o)}}else a(o)}function a(e){t.removeClass("selection-share-popup--visible",e)}function l(){var t,n,o=document.selection,i=0,a=0;if(o)"Control"!==o.type&&(t=o.createRange(),t.collapse(!0),i=t.boundingLeft,a=t.boundingTop);else if(window.getSelection&&(o=window.getSelection(),o.rangeCount&&(t=o.getRangeAt(0).cloneRange(),t.getClientRects&&(t.collapse(!0),t.getClientRects().length>0&&(n=t.getClientRects()[0],i=n.left,a=n.top)),0===i&&0===a))){var l=document.createElement("span");if(l.getClientRects){l.appendChild(document.createTextNode("​")),t.insertNode(l),n=l.getClientRects()[0],i=n.left,a=n.top;var r=l.parentNode;r.removeChild(l),r.normalize()}}return a+=e(document).scrollTop(),{left:i,top:a}}var r=window.location.href,c={};t.pubsub.subscribe("text/checkSelected",i),t.pubsub.subscribe("text/deselected",a)});