1(function($){ 2 3 'use strict'; 4 5 window.jnews.selectShare = window.jnews.selectShare || {}; 6 7 window.jnews.selectShare = 8 { 9 init: function( $container ) 10 { 11 let base = this; 12 13 if ( $container === undefined ) 14 { 15 base.container = $('body'); 16 } else { 17 base.container = $container; 18 } 19 20 base.menu = $('#selectShareContainer'); 21 base.menuInner = base.menu.find('.selectShare-inner'); 22 base.menuButton = base.menuInner.find('button'); 23 base.selected_text = ''; 24 25 this.setEvent(); 26 }, 27 setEvent: function() { 28 let base = this; 29 30 base.container.on('mousedown vmousedown', function(e){ 31 base.handleMouseDown(e); 32 }); 33 base.container.on('mouseup vmouseup', function(){ 34 base.handleSelection(); 35 }); 36 document.addEventListener("selectionchange", function() { 37 base.hasGetSelection(); 38 }, false); 39 base.menuButton.on('click', function (e) { 40 e.preventDefault(); 41 base.buttonClick($(this)); 42 }); 43 }, 44 buttonClick: function(button){ 45 let base = this; 46 var social = button.attr('class').split(' ')[1].replace('jeg_btn-', ''); 47 var button_url = button.attr('data-url').replace('[selected_text]', base.selected_text); 48 49 50 if( jnews_select_share.is_customize_preview ) { 51 return; 52 } 53 window.open( button_url, social,"width=575,height=430,toolbar=false,menubar=false,location=false,status=false"); 54 }, 55 handleMouseDown: function(e){ 56 if ($(e.target).parents('.content-inner').length != 1 && $(e.target).parents('.entry-header').length != 1) { 57 if (window.getSelection().empty) { 58 window.getSelection().empty(); 59 } 60 if (window.getSelection().removeAllRanges) { 61 window.getSelection().removeAllRanges(); 62 } 63 } 64 }, 65 replaceData: function() { 66 let base = this; 67 base.menuButton.each(function () { 68 var post_url = ($(this).attr('data-post-url')) ? ($(this).attr('data-post-url')) : null, 69 image_url = ($(this).attr('data-image-url')) ? ($(this).attr('data-image-url')) : null, 70 title = ($(this).attr('data-title')) ? ($(this).attr('data-title')) : null, 71 button_url = $(this).attr('data-url'); 72 if(button_url.indexOf('[image_url]')) { 73 $(this).attr('data-url', button_url.replace('[image_url]', image_url)); 74 button_url = $(this).attr('data-url'); 75 } 76 if(button_url.indexOf('[url]')) { 77 $(this).attr('data-url', button_url.replace('[url]', post_url)); 78 button_url = $(this).attr('data-url'); 79 } 80 }); 81 }, 82 handleSelection: function(){ 83 let base = this; 84 var selection; 85 86 if (window.getSelection) { 87 selection = window.getSelection(); 88 } else if (document.selection) { 89 selection = document.selection.createRange(); 90 } 91 92 if (selection.rangeCount <= 0) return; 93 94 var range = selection.getRangeAt(0); 95 96 if (range && selection.toString()) { 97 base.selected_text = encodeURIComponent(selection.toString()); 98 base.replaceData(); 99 100 if ($(selection.baseNode || selection.anchorNode).parents('.content-inner').length != 1) { 101 return; 102 } 103 104 var postition = range.getBoundingClientRect(); 105 if (postition.left || postition.top) { 106 base.menuInner.css({ 107 left: postition.left + postition.width / 2 - base.menuInner.width() / 2, 108 top: postition.top + window.pageYOffset - base.menuInner.height() - 11, 109 display: 'block', 110 opacity: 0 111 }).animate({ 112 opacity: 1 113 }, 100); 114 115 setTimeout(function () { 116 base.menuInner.addClass('select_share_menu_animate'); 117 }, 10); 118 return; 119 } 120 } 121 base.menuInner.animate({ opacity: 0 }, function () { 122 base.menuInner.hide().removeClass('select_share_menu_animate'); 123 }); 124 }, 125 hasGetSelection: function(){ 126 let base = this; 127 var selection = window.getSelection(); 128 var text = selection.toString(); 129 if ( '' == text ) { 130 return; 131 } else { 132 base.selected_text = text; 133 } 134 } 135 };
136 jnews.selectShare.init(); 137 138})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.