/* ====================================================================== LDOCE 5++ ======================================================================= */ (function () { var _userAgent = navigator.userAgent.toLowerCase(); if ((/windows\snt/.test(_userAgent) && /chrome|firefox/.test(_userAgent)) || jQuery('.gdarticle').css('-webkit-column-gap') == '1px') { console.log('Windows Chrome/firefox detected.'); if (/windows\snt/.test(_userAgent) && /chrome|firefox/.test(_userAgent)) $("a.speaker").click(function () { fSound = $(this).attr('href'); fSound = fSound.replace('sound://', ''); (new Audio(fSound)).play(); }); return jQuery; } else { return jQuery.noConflict(true) } })() (function ($) { const TAGSWITCHCN = '.LDOCE_switch_lang'; const TAGSWITCHCNALL = '.LDOCE_switch_lang.switch_all'; const TAGSWITCHCNCHILDREN = '.LDOCE_switch_lang.switch_children'; const TAGSWITCHCNSIBLINGS = '.LDOCE_switch_lang.switch_siblings'; const TAGSWITCHCNTAG = '.LDOCE_switch_lang.switch_children, .LDOCE_switch_lang.switch_siblings' const TAGSENSEFOLD = '.LDOCE5pp_sensefold'; const TAGSENSEFOLDOTHER = '.LDOCE5pp_sensefold_other'; const TAGCROSSSENSE = '.cross_sense'; const TAGWORDFAMILY = '.LDOCE_word_family'; const TAGCHINESSTEXT = '.cn_txt'; var lm5pp_pagetype = 3; var lm5pp_clickDealy = 200; var prop = {}; if (/\bTrident\b/i.test(navigator.userAgent)) { $('.lm5ppbody') .before('
This Dictionary BE INCOMPATIBLE with Mdict
') .hide(); return; } (function init() { if (typeof window.lm5pp_pageCount == 'undefined') { window.lm5pp_pageCount = 0 } window.lm5pp_pageCount += 1; if (window.lm5pp_pageCount > 1) return; // remove duplicate records var _titleArray = []; $('.lm5ppbody').each(function (index) { var _tag = $(this).find('.pagetitle'); var _pagetitle = $.trim(_tag.text() + _tag.attr('pagetype')); if (_titleArray.indexOf(_pagetitle) < 0) { _titleArray.push(_pagetitle) if (!hasElement('.expBody') && (index > 0)) { $(this).addClass('notfirst'); } if ((_tag.attr('pagetype') == '2') && $(this).find('.Sense.LDOCEVERSION_new').length != 0){ var _online = $(this).find('.Sense:not(.LDOCEVERSION_new)').length == 0; if (_online){ $(this).find('.lm5ppMenu').addClass('online') .find('#lm5ppMenu_logo') .addClass('goldlogo') .removeClass('switch_version'); $(this).find('.Sense.LDOCEVERSION_new').show().removeClass('LDOCEVERSION_new') .find('.LDOCEVERSIONLOGO_new').hide(); } else { $(this).find('.lm5ppMenu').addClass('goldlogo') .find('#lm5ppMenu_logo') .addClass('halfgold goldlogo'); if (!$(this).find('.switch_online').length) $(this).find('#menu_quit').before('
LDOCE Online
\n' + '
'); } } } else { $(this).css('display', 'none'); } }) checkPlatform('.lm5ppbody'); extendJQuery(); readIni(); loadImage(); removePictureAndSound(); // ******************************************** topicSetup(); multiwordsSetup(); // ******************************************** $('h1.pagetitle').each(function () { lm5pp_pagetype = Math.min(lm5pp_pagetype, $(this).attr('pagetype') === undefined ? 0 : parseInt($(this).attr('pagetype'))); }); // hook tags for visibility of cross senses(phrase verbs) senseSetup(); $('.Sense > .foldsign_fold').toggleClass('foldsign_fold').siblings().filter(senseFilter).filter(versionFilter).lm5pp_toggle(); $('.wordfams > ' + TAGSENSEFOLD) .off().on("click", function () { $(this).toggleClass('foldsign_fold'); $(this).nextAll('.LDOCE_word_family').first().lm5pp_toggle(); }) // pagetype=3: online page if (lm5pp_pagetype != 3) { setTimeout(switchChineseSetup, 0); // lm5pp_switchChineseSetup(); } setTimeout(imageSetup, 0); // ...box show/hide, setTimeout(boxSetup, 0); // version versionSetup(); // ***************** menu ******************** menuSetup(); floatmenuSetup(); if ($('#switch_online').length > 0) { $('.lm5pp_popup').addClass('switch_version'); $('.lm5pp_popup, .lm5ppMenu, #lm5ppMenu_logo').addClass('goldlogo'); } // ***************** proncodes *************** HWDSetup(); // ***************** proncodes *************** CorpusJump(); // ***************** proncodes *************** pronCodeSetup(); // ***************** Tips window *************** // lm5pp_tipsSetup(); // ***************** East Egg *************** easteggSetup(); // ******************************************** anchorSetup(); // double click setup setTimeout(dblSetup, 0); setTimeout(bussDictLinkFix, 1400); // click event triggered by hover if (prop.ini_menuHover > 0 && !hasElement('.mobile.lm5ppbody')) { setTimeout(hoverDelaySetup, 1400); } // trigger float logo $(window).scroll(); })() function checkPlatform(rootElement) { var _class = ''; var _userAgent = navigator.userAgent.toLowerCase(); if (/windows nt/i.test(_userAgent)) { _class += ' windowsnt desktop'; if (/eudic/i.test(_userAgent)) { _class += ' eudicnt'; } } else if (/Macintosh/i.test(_userAgent)) { _class += ' macos desktop'; if (/eudic/i.test(_userAgent)) { _class += ' eudicnt' } } else if (/linux/i.test(_userAgent) && !(/android/i.test(_userAgent))) { _class += ' linux desktop'; } if (_userAgent.indexOf('chrome') >= 0) { _class += ' chrome'; } else if (/firefox/i.test(_userAgent)) { _class += ' firefox'; } if (_userAgent.indexOf('goldendict') >= 0) { _class += ' goldendict' + ((window.HTMLTrackElement === undefined) ? ' qt4' : ' qt5'); if (/qt5/.test(_class)) { $.fx.off = true; } } else { if (_userAgent.indexOf('iphone') >= 0) { _class += ' iphone ios mobile'; } else if (_userAgent.indexOf('ipad') >= 0) { _class += ' ipad ios mobile'; } else if (_userAgent.indexOf('android') >= 0) { _class += ' android mobile'; } if (hasElement('.expBody, .eudicExpDiv')) { _class += ' eudic'; } else if (hasElement('.bd_body')) { _class += ' bluedict'; } } $('.Sense.Subentry').css('-webkit-animation', ''); // Add border and shadow in the context of non-white background theme being selected. if (/goldendict/i.test(_class) && (!/rgba?\(255,\s*255,\s*255\b/i.test($('body').css('background-color')))) { _class += ' not-white' } ; // debug // _class = 'mobile bluedict android'; $(rootElement).addClass(_class); } function multiwordsSetup() { if (!isMultiwords()) { return; } // remove duplicate images var _images = new Array(); $('.ldoce-show-image[src]').each(function () { var _src = $(this).attr('src'); _src = _src.substring(_src.search('media')); if (_images.indexOf(_src) >= 0) { $(this).hide(); } else { _images.push(_src); } }); // merge menu items var _target_popup = $('.lm5ppbody').last().find('.lm5pp_popup'); _target_popup .prepend('') .children('span:first') .append( $('.lm5pp_popupitem:has(.Head)')) .append($('.lm5pp_popupitem:has(#switch_online):first')) .append($('.lm5pp_popupitem:has(#switch_cn):first')) .append($('.lm5pp_popupitem:has(#switch_syllable):first')) .append($('.lm5pp_popupitem:has(#switch_corpus):first')) .append($('.lm5pp_popupitem:has(.lm5pp_icon):first')) .append($('.lm5ppMenu_floatlogo:first')); _target_popup.children('span').last().remove(); // .find('#menu_quit:first').nextAll('.lm5pp_popupitem').remove(); // $('.lm5ppbody:lt(-1)').find('.lm5pp_popup').remove(); $('.lm5ppbody .lm5pp_popup').not(_target_popup).remove(); var _entry = $('.entry_content').not('.topic'), _target_intro = _entry.find('.dictionary_intro').first(); if (_entry.find('.dictionary_intro .lm5ppMenu').not('.online').length) { _target_intro.find('.lm5ppMenu').removeClass('online') .find('.goldlogo').removeClass('goldlogo'); } if (_entry.find('.dictionary_intro .lm5ppMenu .lm5ppMenu_title').not('.en_show').length) { _target_intro.find('.lm5ppMenu .lm5ppMenu_title').removeClass('en_show'); } _entry.find('.dictentry:not(.bussdict) .dictionary_intro').not(_target_intro).remove(); // $('.entry_content').not('.topic').filter(function (index) { // return index != 0; // }).find('.dictionary_intro').remove(); // remove duplicate records of 'word family' var _titles = []; $('.wordfams').filter(function () { var _title = $(this).find('.w').first().attr('title'); if (_titles.indexOf(_title) >= 0) { return true; } else { _titles.push(_title); return false; } }).remove(); } function isMultiwords() { return ($('.lm5ppbody > .entry_content:not(.topic)').length > 1); } function menuSetup() { // initialize checked boxes $('#switch_syllable').prop("checked", $('.HWD .HYP').is(":visible")); $('#switch_corpus').prop("checked", $('.asset.corpus:visible').is(":visible")); if (!isChineseSwitch()) { $('#switch_cn').closest('.lm5pp_popupitem').hide(); } else { $('#switch_cn').prop("checked", $('.ldoceEntry .Sense .cn_txt').is(":visible")); } if (!hasElement('.ldoceEntry .LDOCEVERSION_new')) { $('#switch_online').closest('.item').remove(); } else { $('#switch_online').prop("checked", $('.ldoceEntry .LDOCEVERSION_new').is(":visible")); $('#lm5ppMenu_logo') .addClass("switch_version") .on('click.lm5ppMenu', toggleVersion); } // prevent default event handlers $('#switch_syllable, #switch_online, #switch_cn, #switch_corpus') .off('.itemClick').on('click.itemClick', false); $('.lm5pp_popupitem a[href]').off('.itemClick').on('click.itemClick', function (event) { event.stopImmediatePropagation(); event.preventDefault(); scrollPosition($($(event.currentTarget).attr('href'))); }) $('#menu_quit').off('.itemClick').on('click.itemClick', function (event) { var _x = event.pageX - $('#icon_senseFold').offset().left if ((_x > 0) && (_x < $('#icon_senseFold').outerWidth() + 10)) { toggleAllCrossense(); return; } _x = event.pageX - $('#icon_boxFold').offset().left if ((_x > 0) && (_x < $('#icon_boxFold').outerWidth() + 10)) { toggleAllBoxes(); return; } }) $('.lm5ppbody:last .lm5pp_popup').off('.itemClick') .on('click.itemClick', '.lm5pp_popupitem', function (event) { if ($(this).has('#switch_syllable').length) { switchSyllable(); } else if ($(this).has('#switch_cn').length) { toggleChineseAll(); } else if ($(this).has('#switch_online').length) { toggleVersion(); } else if ($(this).has('#switch_corpus').length) { toggleCorpus(); } else if ($(this).has('a[href]').length) { $(this).find('a[href]').first().trigger('click'); } menuHide(); // lm5pp_menuHide(); }); } function menuHide() { if (!isMenuShow()) return; $('.lm5ppbody:last .active.lm5pp_popup').fadeTo(250, 0.1, function () { $(this).removeClass('active').css({'opacity': '', 'visibility': ''}); $(window).off('.monitorFloatMenu'); $(window).scroll(); }); } function menuShow() { if (!isMenuShow()) return; $('.lm5ppbody:last .lm5pp_popup:not(.active)') .css({'opacity': 0, 'visibility': 'visible'}) .fadeTo(250, 1, function () { $(this).addClass('active').css({'opacity': '', 'visibility': ''}); $(window).off('.monitorFloatMenu').on("click.monitorFloatMenu", function (event) { if ($(event.target).closest('.lm5pp_popup').length == 0) { menuHide(); } }); $('.desktop .lm5pp_popup').one({ 'mouseleave.monitorFloatMenu': function () { menuHide(); } }); }); } var lm5pp_scrollTimer; const lm5pp_MENUSHOWHIDE = 1000; function floatmenuSetup() { if (lm5pp_pagetype != 0) { return; } $('.lm5ppbody').first().append('') .append(''); if (!isMenuShow()) { } $('#logo_float').prepend(''); $('.entry_content:last').css('position', 'relative'); var _originalBottom = parseInt($('.entry_content:last .lm5pp_popup').css('bottom')); var _originalRight = parseInt($('.entry_content:last .lm5pp_popup').css('right')); $(window).scroll(function () { clearTimeout(lm5pp_scrollTimer); lm5pp_scrollTimer = setTimeout(function () { menuHide(); if (!isMenuShow()) { $('#logo_float.show').removeClass('show'); return; } var _entryHeight = getDictHeight(); var _top = $('.entry_content:visible').first().offset().top; var _bottomOffset = 0; var _bottom = _top + _entryHeight + _bottomOffset; var _zero_top = $('#location_zero').offset().top; var _menu = $('.entry_content:visible:last .lm5pp_popup'), _menu_height = _menu.height(); var _locate = _menu.offset().top + _menu_height; var _zero_bottom = $('#location_zero_bottom').offset().top; var _flag_show = ((_bottom - _zero_top) >= (_menu_height + 60)); if (_flag_show) { _flag_show = ((_top < _zero_top) || (_top >= _zero_top && (_zero_bottom - _top) >= (_menu_height + 60))) } if (_flag_show) { var _offset = _zero_bottom - _bottom + 20 if (isBluedict()) { _menu.css({ 'right': '', position: 'fixed', bottom: 'initial', top: _top + _menu_height + 20 }); $(window).off('scroll'); } else if (_offset < _originalBottom) { _offset = _originalBottom; if (_menu.css('position') != 'fixed') _menu.css({"right": '', "position": "", "bottom": ""}); } else { if (_menu.css('position') == 'fixed') { var _right = $('#location_zero_bottom').offset().left - ($('.entry_content:last').offset().left + $('.entry_content:last').outerWidth()); _menu.css({"right": _originalRight - _right, "bottom": '10px', "position": "absolute"}) } } // else { // _offset = _zero_bottom - _bottom - 10; // } $('#logo_float').not('.show').addClass('show'); } else { $('#logo_float.show').removeClass('show'); } $('#logo_float').off('.logo_float').on('click.logo_float', function () { ($(this).closest('.active.lm5pp_popup').length) ? menuHide() : menuShow(); return false; }); }, 300); }); } function pronCodeSetup() { // click proncodes to pronounce if (!isMDDExisting() && !isMobile() && !hasElement('.lm5ppbody.chrome.desktop')) { $('.ldoceEntry > .Head > a.PronCodes') .css('cursor', 'default').attr('href', '#') .on('click', function () { return false; }); return; } $('.ldoceEntry > .Head > a.PronCodes') .each(function () { var _selector = 'a.speaker[href!="{}"]'.replace('{}', $(this).attr('href')); if ($(this).siblings(_selector).length > 0) { $(this).attr('hrefalt', $(this).siblings(_selector).attr('href')) } }) .on('click.pronCode', function () { var _href = $(this).attr('href'); if ($(this).is('[hrefalt]')) { // var _selector = 'a.speaker[href!="{}"]'.replace('{}', $(this).attr('href')); setTimeout(function (element, href) { $(element).attr('href', href); }, 200, this, $(this).attr('hrefalt')); $(this).attr('hrefalt', _href); } if (isOnlinePron()) { var _selector = 'a.speaker[href="{}"]'.replace('{}', _href); $(this).siblings(_selector).trigger('click'); return false; } }); } function versionSetup() { // $('.ldoceEntry').find('.LDOCEVERSION_new, .LDOCEVERSIONLOGO_5, .LDOCEVERSIONLOGO_new').hide(); } function HWDSetup() { if (isMenuShow() && $('.ldoceEntry > .Head > .HWD').length > 1) { $('.ldoceEntry > .Head > .HWD').css('cursor', 'pointer') .on('click.HWD', function () { var _$HWDs = $('.ldoceEntry > .Head > .HWD:visible'); if (_$HWDs.length > 1) { var _index = _$HWDs.index(this); if (_index >= 0) { _index += 1; if (_index >= _$HWDs.length) _index = 0; scrollPosition(_$HWDs.eq(_index)); } } }) } else { $('.ldoceEntry > .Head > .HWD:has(.HYP)').css('cursor', 'pointer') .on('click.HWD', function () { switchSyllable(); }) } } function CorpusJump(){if(isMenuShow()&&$(".corpus.asset .asset_intro").length>1){$(".corpus .asset_intro").css("cursor","pointer").on("click.corpus",function(){var _$corpora=$(".corpus .asset_intro:visible");if(_$corpora.length>1){var _index=_$corpora.index(this);if(_index>=0){_index+=1;scrollPosition(_$corpora.eq(_index))}if(_index>=_$corpora.length){$("#switch_corpus").prop("checked",false);$(".corpus").lm5pp_hide();scrollPosition($(".corpusegg"))}}})}else if($(".corpus.asset .asset_intro").length=1){$(".corpus .asset_intro").css("cursor","pointer").on("click.corpus",function(){$("#switch_corpus").prop("checked",false);$(".corpus").lm5pp_hide();scrollPosition($(".corpusegg"))})}} function switchChineseSetup() { if (!isChineseSwitch()) return; // $('.lm5ppMenu_title').addClass('en_show'); if (hasElement('.ldoceEntry .cn_txt')) { $('.lm5ppMenu_title').addClass('intro_active') .add(TAGSWITCHCNALL) .off('.lm5pp_lang') .on('click.lm5pp_lang', showChineseAll); $('.ldoceEntry').addClass('langSwitch').off('.lm5pp_lang') .on('click.lm5pp_lang entry.lm5pp_lang', TAGSWITCHCNTAG , function (event) { if (hasElement('.lm5ppMenu_title.en_show')) return; event.stopImmediatePropagation(); event.preventDefault(); $.proxy(switchChinese, this)(); }); } if (hasElement('.topicCloud .cn_txt')) { $('.lm5ppTopic_title').addClass('intro_active') .off('.lm5pp_lang') .on('click.lm5pp_lang', function () { $('.entry_content.topic .cn_txt').lm5pp_toggle(); }); } } function onlinePronSetup() { if (!isOnlinePron()) return; $('a.speaker[href$=".spx"]') .closest('.EXAMPLE.speaker').removeClass('speaker').end() .remove(); $('.ldoceEntry').on('click.onlinePron', 'a.speaker[href$="mp3"][href*="media"]:not(.loading)', function () { /* by author of Bluedict */ if (isBluedict() && false) { var _src = $(this).attr('href'); _src = 'http://www.ldoceonline.com/' + _src.substring(_src.search('media')); var _audio = new Audio(); _audio.src = _src; _audio.play(); return; } /* END END END END */ var _src = $(this).addClass('loading').attr('href'); _src = 'http://www.ldoceonline.com/' + _src.substring(_src.search('media')); var _audio = new Audio(); var _timeout = setTimeout(function (audioObj, loadingTag) { $(audioObj).trigger('abort', {timeout: null, loadingTag: loadingTag}); }, 5000, _audio, this); /* networkState 0 = NETWORK_EMPTY - audio/video has not yet been initialized 1 = NETWORK_IDLE - audio/video is active and has selected a resource, but is not using the network 2 = NETWORK_LOADING - browser is downloading data 3 = NETWORK_NO_SOURCE - no audio/video source found readyState 0 = HAVE_NOTHING - no information whether or not the audio/video is ready 1 = HAVE_METADATA - metadata for the audio/video is ready 2 = HAVE_CURRENT_DATA - data for the current playback position is available, but not enough data to play next frame/millisecond 3 = HAVE_FUTURE_DATA - data for the current and at least the next frame is available 4 = HAVE_ENOUGH_DATA - enough data available to start playing */ var _event = 'play.play ended.play abort.play error.play'; $(_audio) .on(_event, {timeout: _timeout, loadingTag: this}, function (event) { // + this.networkState + " ready:" + this.readyState); clearTimeout(event.data.timeout); if (event.type == 'play') return; $(event.data.loadingTag).removeClass('loading'); $(this).off('.play').prop('autoplay', false); }) // .prop('autoplay', true) .prop('src', _src); _audio.play(); return false; }); } function isChineseSwitch() { return ($('.pagetitle').css('background-repeat') == 'repeat-y' && hasElement('.ldoceEntry .cn_txt, .cloud .cn_txt')); } function hoverDelaySetup() { var _timeout_hover, _timeout_lock = false , _timeout_duration = prop['ini_menuHover_delay']; $('.lm5pp_popup, .lm5ppMenu').on('click.hover', function () { clearTimeout(_timeout_hover); }); var _items = $('.lm5pp_popupitem').has('.HWD, .switch'); _items.add('.lm5pp_icon') .add('.lm5pp_popupitem .Head').has(':not(.HWD)') .hover(function (event) { var _self = $(this); clearTimeout(_timeout_hover); _timeout_hover = setTimeout(function () { var _event = $.Event('click'); _event.pageX = event.pageX; if (_self.is('.lm5pp_icon')) { $('#menu_quit').trigger(_event); } else { _self.trigger(_event); } }, _timeout_duration) }, function () { clearTimeout(_timeout_hover); }) $('#logo_float').on('mouseenter mouseleave click', function (event) { if (event.type == 'mouseenter') { clearTimeout(_timeout_hover); if (!$(this).closest('.active.lm5pp_popup').length) { _timeout_hover = setTimeout(function () { $('#logo_float').trigger('click'); }, _timeout_duration) } } else if (event.type == 'mouseleave' || event.type == 'click') { clearTimeout(_timeout_hover); } } ); // title bar $('.lm5ppMenu').on('mouseenter mouseleave' , '.switch_version, .asset_intro, .intro_active' , _processHover); function _processHover(event) { if (event.type == 'mouseenter') { clearTimeout(_timeout_hover); var _self = $(event.target); if (_self.is('.switch_version') && _timeout_lock) { return; } _timeout_hover = setTimeout(function () { _self.trigger('click'); _timeout_lock = true; setTimeout(function () { _timeout_lock = false; }, 5000); }, _timeout_duration) return false; } else if (event.type == 'mouseleave') { clearTimeout(_timeout_hover); } else if (event.type == 'click') { clearTimeout(_timeout_hover); } } } var lm5pp_lastdblSetupClick = null; function dblSetup() { // return; $('.lm5ppbody').off('.lm5ppbody').on('click.lm5ppbody', function (event) { if (lm5pp_lastdblSetupClick === event.target) return; lm5pp_lastdblSetupClick = event.target; setTimeout(function () { lm5pp_lastdblSetupClick = null; }, 500) if ($(event.target).closest('.ldoce-show-image').length) return false; $('.lm5ppBox, .Sense, .Subsense') .each(function () { if (($(this).offset().top < event.pageY) && (($(this).offset().top + $(this).outerHeight()) > event.pageY)) { var _element = $(this); if (_element.is('.lm5ppBox')) { if ($(event.target).filter('.EXAMPLE, .Exponent, .Collocate') .first() .children(TAGSWITCHCNTAG) .first().trigger('entry').length > 0) return false; _element.children('.LDOCE5pp_sensefold') .each(function () { if ($(this).offset().top < event.pageY && $(this).offset().top + $(this).outerHeight() >= event.pageY) { $(this).trigger('entry'); return false; } }); } else if (_element.is('.Sense, .Subsense')) { if ($(event.target) .filter('.EXAMPLE, .ErrorBox, .ColloExa, .GramExa, .Sense, .Subsense') .first() .children(TAGSWITCHCNTAG) .first() .trigger('entry').length > 0 ) return false; if ($(event.target) .filter('.Sense, .Subsense') .first() .children(TAGSENSEFOLD) .first() .trigger('entry').length > 0 ) return false; _element.children(TAGSENSEFOLD).each(function () { if ($(this).offset().left > event.pageX && $(this).offset().top < event.pageY && $(this).offset().top + $(this).outerHeight() >= event.pageY) { $(this).trigger('entry'); return false; } }) // lm5pp_toggleAllCrossense(_element); } // return false; } }); }); } function switchSyllable() { $('.HWD .HYP').lm5pp_toggle(); $('#switch_syllable').prop('checked', function (index, val) { return !val; }); } var lm5pp_lastClick; var imageShowHTML = '' + '
' + '
' + '' + '2X' // '' + '' + '' + '' + '' + '' + '' + '' + '
' + '
' + '
'; function imageSetup() { $('.ldoce-show-image').on('click.dictimage', function (event) { event.stopPropagation(); event.preventDefault(); showImage(this); }) .filter(function () { return hasElement('.desktop') }) .hover(function () { $(this).siblings().css('pointer-events', 'none'); }, function () { $(this).siblings().css('pointer-events', ''); }); } function showImage(target) { var _bluedict = isBluedict(); var _img = $(target); var _viewport = getViewport(); if (!_bluedict) { if (_img.length != 0) { _start = { top: _img.offset().top - _viewport.top, left: _img.offset().left, bottom: _viewport.bottom - (_img.offset().top + _img.height()), right: _viewport.width - (_img.offset().left + _img.width()), opacity: 0 } } else { _start = { top: _viewport.height / 2, left: _viewport.width / 2, bottom: _viewport.height / 2, right: _viewport.width / 2, opacity: 0 } } _end = {top: 0, left: 0, bottom: 0, right: 0, opacity: 1}; } else { _end = {top: 0, left: 0, width: _viewport.width, height: _viewport.height, opacity: 1}; if (_img.length != 0) { _end.top = _img.offset().top - 40; } _start = _end; } var _$view = $('.ldoce5pp-image-show').removeClass('zoom'); var _src = _img.attr('src') || _img.find('[src]').attr('src'); var clicked = false, clickX, clickY; if (!_$view.length) { // $('.lm5ppbody').last().append('
'); $('body').append(imageShowHTML); _$view = $('.ldoce5pp-image-show'); } _$view.find('.svgzoomclose').off('.imgShow') .on('click.imgShow', function () { // $('.ldoce5pp-image-show').trigger('click'); imgZoom_quit(); return false; }).end() .find('.svgzoomout,.svgzoomin').off('.imgShow') .on('click.imgShow', function () { imgZoom_zoom(hasElement('.ldoce5pp-image-show.zoom') ? 1 : 2); return false; }); var dragFlag = false; _$view .off('click.imgShow').on('click.imgShow', function (e) { if (/^http.*?wallhaven\.cc/i.test(_src) && (e.pageX > _$view.width() - 50 && (e.pageY - _$view.offset().top) > _$view.height() - 100)) { copyToClipboard(_src); } if (isBluedict()) { imgZoom_quit(); } else if (hasElement('.lm5ppbody.desktop')) { if (dragFlag) return; imgZoom_zoom(); } else if (hasElement('.lm5ppbody.mobile.eudic')) { if (e.pageX < _$view.width() / 2) { _$view.scrollLeft(_$view.scrollLeft() - 120); } else { return true; } } else { return true; } e.stopImmediatePropagation(); e.preventDefault(); }) .toggleClass('mobile', hasElement('.lm5ppbody.mobile')) .toggleClass('bluedict', hasElement('.lm5ppbody.bluedict')) .toggleClass('desktop', hasElement('.lm5ppbody.desktop')) .filter('.desktop').find('.ldoce5pp-image-container').off('.imgShow').on({ 'mousemove.imgShow': function (e) { if (!clicked) return; e.preventDefault(); e.stopImmediatePropagation(); dragFlag = true; _$view.scrollTop(_$view.scrollTop() + (clickY - e.pageY)) .scrollLeft(_$view.scrollLeft() + (clickX - e.pageX)); clickY = e.pageY; clickX = e.pageX; return false; }, 'mousedown.imgShow': function (e) { // console.log(e); if (hasElement('.ldoce5pp-image-show.zoom')) { dragFlag = false; e.preventDefault(); e.stopImmediatePropagation(); clicked = true; clickX = e.pageX; clickY = e.pageY; _$view.add(this).css('cursor', 'all-scroll'); return false; } }, 'mouseup.imgShow mouseleave.imgShow': function (e) { if (hasElement('.ldoce5pp-image-show.zoom')) { e.preventDefault(); e.stopImmediatePropagation(); clicked = false; _$view.add(this).css('cursor', ''); return false; } } }); var _animTime = 500; if (/^ldoce4/.test(_src)) { _src = $('#' + _src).attr('src'); } $('#lm5pp_wallpaper_copy').hide(); _$view.find('.ldoce5pp-image-container').css('background-image', 'url(' + _src + ')'); var _src_anim = !_bluedict && _img.is('img'); if (_src_anim) { _img.css('opacity', 0) } _$view.filter(':hidden') .css(_start) .show(0); if (!_bluedict) { _$view.animate(_end, _animTime); } return false; function imgZoom_zoom(magnification) { var _magification = 1; if (hasElement('.ldoce5pp-image-show.x8')) _magification = 1 else if (hasElement('.ldoce5pp-image-show.x4')) _magification = 8 else if (hasElement('.ldoce5pp-image-show.zoom')) _magification = 4 else _magification = 2; if (_magification != 1) { $('.ldoce5pp-image-show .svgzoomin svg text').text('' + _magification + 'X'); } $('.ldoce5pp-image-show').removeClass('x2 x4 x8').toggleClass('zoom', _magification != 1) .filter('.zoom').each(function () { var _container = $(this), _img = $('.ldoce5pp-image-container'); _container.addClass('x' + _magification); setTimeout(function () { _container.scrollTop((_img.height() - _container.height()) / 2); _container.scrollLeft((_img.width() - _container.width()) / 2); _container.focus(); }); // $('.ldoce5pp-image-show .ldoce5pp-image-container').focus(); }); } function imgZoom_quit() { event.stopPropagation(); event.preventDefault(); var _splitTime = 0.8; if (isBluedict()) { _$view.hide(); return; } _$view.animate(_start, {duration: _animTime, queue: false}) .delay(_animTime * _splitTime) .animate({opacity: 0}, _animTime * (1 - _splitTime)) .promise().done(function () { _$view.hide(); }); if (_src_anim) _img.delay(_animTime * _splitTime) .animate({'opacity': 1}, _animTime * (1 - _splitTime)); } function copyToClipboard(str) { if (document.queryCommandSupported('copy')) { var el = $('') .appendTo('body').val(str); if (hasElement('.lm5ppbody.ios')) { el[0].setSelectionRange(0, 9999); } else { el[0].select(); } var s = document.execCommand('copy'); el.remove(); } else { var el = $('#lm5pp_wallpaper_copy'); if (!el.length) { el = $('') .appendTo(_$view); } el.val(str).show(); el[0].focus(); el[0].setSelectionRange(0, 9999); } }; } var lm5pp_clickTimer; function boxSetup() { $('.ldoceEntry').off('.boxControl') .on("click.boxControl entry.boxControl", '.lm5ppBox .lm5ppBoxHead' , function (event) { event.stopImmediatePropagation(); toggleBox($(this)); return false; }); } var lm5pp_switchBox; function toggleBox($obj, actionUnfold) { var $box = $obj.closest('.lm5ppBox'); if ($box.length) { if ($box.length == 1) { var _box = $box.get(0); if (lm5pp_switchBox === _box) { return; } else { lm5pp_switchBox = _box; } } if (actionUnfold === undefined) actionUnfold = $box.hasClass('BoxHide'); var _duration = ($box.length > 5) || (!isApplyEffect()) ? 0 : lm5pp_slideDuration; $box .filter(function () { return actionUnfold == $(this).hasClass('BoxHide') }) .toggleClass('BoxHide', !actionUnfold).children('.BoxPanel') .each(function () { $(this).animate({height: 'toggle', opacity: 'toggle'}, _duration, function () { }); }).end() .find('.LDOCE5pp_sensefold').toggleClass('foldsign_fold'); setTimeout(function () { lm5pp_switchBox = null; }, 300); $(window).scroll(); } } var lm5pp_boxes; function toggleAllBoxes($obj) { if (lm5pp_boxes === undefined) lm5pp_boxes = $('.ldoceEntry .lm5ppBox'); var _$target = lm5pp_boxes; var _actionUnfold; if (lm5pp_boxes.length == 0) return; if ($obj === undefined || !($obj instanceof jQuery)) { _actionUnfold = lm5pp_boxes.filter('.BoxHide').length / lm5pp_boxes.length >= 0.5; } else { _actionUnfold = !$obj.hasClass('BoxHide'); if ($obj.get(0) === lm5pp_switchBox) { _$target = _$target.not($obj); _actionUnfold = !_actionUnfold; } } savePosition(); toggleBox(_$target, _actionUnfold); } function toggleVersion() { $('#switch_online').prop('checked', function (index, val) { $('#lm5ppMenu_logo, .lm5pp_popup, .lm5ppMenu_title,.lm5ppMenu') .toggleClass('goldlogo', !val); $('.dictentry.LDOCEVERSION_new').lm5pp_toggle(!val); $('.ldoceEntry.LDOCEVERSION_new, .ldoceEntry .LDOCEVERSION_new').filter(controlFilter) .add('.ldoceEntry [class*=LDOCEVERSIONLOGO_]') .lm5pp_toggle(!val); $('.lm5pp_popup').toggleClass('switch_version'); $(window).scroll(); return !val; }); } function toggleCorpus() { $('#switch_corpus').prop('checked', function (index, val) { $('.lm5ppMenu .corpusegg').toggle(val); $('.corpus').lm5pp_slideToggle(!val).promise().done(function () { isInView($('.corpus'), true); $(window).scroll(); }); return !val; }); } function topicSetup() { if (hasElement('.entry_content.topic')) { $('a.topic_other').attr('href', '').off('.topic').on('click.topic', function () { var _self = $(this); $('.cloud').slideToggle().promise().done(function () { _self.toggleClass('full'); scrollPosition($('.lm5ppbody .topicCloud')); }); return false; }); } } function senseFilter(index) { return !$(this).is('.merge_sense') && $(this).is('.EXAMPLE, .GramExa, .ColloExa, ' + '.Crossref, .F2NBox, .Thesref, .GramBox, .Subsense, .Hint, .UsageBox, .Sense, .ErrorBox'); } var lm5pp_senseTimer; var lm5pp_senseTimerFlag = false; function senseSetup() { $('.ldoceEntry') .off('.senseFold') .on("click.senseFold entry.senseFold" , TAGSENSEFOLD + ':not(.fixed), ' + TAGSENSEFOLDOTHER, function (event) { if ($(this).parent().hasClass('lm5ppBox')) { return; } event.stopImmediatePropagation(); event.preventDefault(); if ($(this).parent().hasClass('SpokenSect')) { $(this).toggleClass('foldsign_fold'); $(this).siblings('.Sense').lm5pp_toggle(); return false; } toggleCrosssense(this); return false; }) } var lm5pp_switchSense; function toggleCrosssense(obj) { if ($(obj).is(TAGSENSEFOLDOTHER)) { obj = $(obj).siblings(TAGSENSEFOLD) } var _sense = $(obj).closest('.Sense').get(0); if (lm5pp_switchSense === _sense) { return; } else { lm5pp_switchSense = _sense; } $(obj).siblings().filter(senseFilter).filter(versionFilter).lm5pp_toggle(); $(obj).filter(versionFilter).toggleClass('foldsign_fold'); setTimeout(function () { lm5pp_switchSense = null; }, 200); } var lm5pp_allSenses; function toggleAllCrossense(obj) { if (lm5pp_allSenses === undefined) lm5pp_allSenses = $('.ldoceEntry .Sense > ' + TAGSENSEFOLD); var _actionUnfold; var _sense; var _$target = lm5pp_allSenses; if (obj === undefined || !(obj instanceof jQuery)) { _actionUnfold = (_$target.filter('.foldsign_fold').length / _$target.length >= 0.5); } else { _actionUnfold = obj.is('.foldsign_fold'); _sense = obj.closest('.Sense').get(0); if (_sense === lm5pp_switchSense) { _$target = _$target.not($(obj)); lm5pp_switchSense = null; _actionUnfold = !_actionUnfold; } } if (_actionUnfold) { _$target = _$target.filter('.foldsign_fold'); } else { _$target = _$target.not('.foldsign_fold'); } var _collection = _$target.siblings().filter(senseFilter) .filter(versionFilter); savePosition(); var _promise = ((_collection.length > 30) || !isApplyEffect()) ? _collection.toggle(_actionUnfold).promise() : _collection.lm5pp_toggle(_actionUnfold).promise(); _promise.done(function () { _$target .filter(versionFilter).toggleClass('foldsign_fold', !_actionUnfold); restorePosition(); }) } var _middleElement; function savePosition() { if (isBluedict()) return; _middleElement = undefined; var _viewport = getViewport() , _scrollTop = $('body').scrollTop() + _viewport.height / 2; var _element; $('.ldoceEntry').children(':visible').each(function () { if ($(this).offset().top > _scrollTop) { return false; } _element = this; }); $(_element).children('.Subsense, .Sense').each(function () { if ($(this).offset().top > _scrollTop) { return false; } _element = this; }); _middleElement = _element; } function restorePosition() { if (!_middleElement || $(_middleElement).is(':hidden')) return; var _viewport = getViewport() , _centerLine = $('body').scrollTop() + _viewport.height / 2 , _top = $(_middleElement).offset().top , _position = Math.max(_top - _viewport.height / 2, 0); if ((_position >= 0) && (Math.abs(_top - _centerLine) > _viewport.height / 4)) { $('html,body').animate({scrollTop: _position}, 500); } } function versionFilter(index) { return !($(this).is('.LDOCEVERSION_new') && !$('#switch_online').is(':checked')); } function controlFilter(index) { if ($(this).parent().is('.Sense, .Subsense')) { return $(this).siblings('.foldsign_fold').length == 0; } return true; } var lm5pp_lastSwitchElement; function switchChinese(event) { if (this === lm5pp_lastSwitchElement) return; if ($(this).is(TAGSWITCHCNSIBLINGS)) { $(this).siblings().children(TAGCHINESSTEXT).lm5pp_toggle(); $(this).children(TAGCHINESSTEXT).lm5pp_toggle(); } else { $(this).children(TAGCHINESSTEXT).lm5pp_toggle(); $(this).find('.en_txt > .cn_txt').lm5pp_toggle(); } if ($('.ldoceEntry .cn_txt:hidden').length == 0) showChineseAll(); $(window).scroll(); setTimeout(function () { lm5pp_lastSwitchElement = null; }, 200); } function showChineseAll() { toggleChineseAll(true); } function toggleChineseAll(option) { // option: true/false - show/hide $('#switch_cn').prop('checked', function (index, val) { if (option !== undefined && typeof option == 'boolean') val = !option; var _target = $(TAGCHINESSTEXT); savePosition(); var _promise = (_target.length > 100) ? _target.toggle(!val).promise() : _target.lm5pp_toggle(!val).promise(); _promise.done(function () { $('.lm5ppbody').toggleClass('langSwitch', val) $('.lm5ppMenu_title').toggleClass('en_show', !val) .add('.lm5ppTopic_title') .toggleClass('intro_active', val) .not('.intro_active') .off('.lm5pp_lang'); if (val) { switchChineseSetup(); } else { $(TAGSWITCHCNALL).add(TAGSWITCHCNTAG) .off('.lm5pp_lang') .css('cursor', 'auto'); } restorePosition(); }); $(window).scroll(); return !val; }); } function anchorSetup() { if (isGoldendict()) { _match = document.location.href.match(/gdanchor=.*?_.*?_(.*?)__a/) if (_match) { $('#' + _match[1]).each(function () { if ($(this).closest('.lm5ppbody .SpokenSect').children('.foldsign_fold') .toggleClass('foldsign_fold') .siblings('.Sense').show().length) { scrollPosition($(this)); } }); } } } var lm5pp_tipsTimer; function lm5pp_tipsSetup($element, func) { return; } function easteggSetup() { //setTimeout(function () { if (hasElement('.corpus')) { $('.lm5ppMenu .corpusegg').on('click', toggleCorpus); } else { $('.lm5ppMenu .corpusegg').hide(); } if (hasElement('.bussdict')) { $('.lm5ppMenu .bussdictegg').on('click', function () { //$(this).hide(); $('.bussdict').lm5pp_slideToggle().promise().done(function () { isInView($('.bussdict'), true); $(window).scroll(); }); }); } else { $('.lm5ppMenu .bussdictegg').hide(); } $('.bussdict .dictionary_intro').css('cursor', 'pointer') .on('click', function () { $('.bussdict').lm5pp_hide(); scrollPosition($('.bussdictegg')); }) //}, 3000); } function isMenuShow() { var _height = getDictHeight(); return ($('.lm5ppBox').length != 0) || isBluedict() || _height > $('.lm5pp_popup').outerHeight() * 1.8; } function getDictHeight() { var _height = 0; $('.entry_content:visible').each(function () { _height += $(this).outerHeight(); }); return _height; } function isMobile() { return $('.lm5ppbody').is('.iphone, .android, .ipad') || isBluedict(); } function isMDDExisting() { var _flag = $('.pagetitle').css('border-top-style'); return _flag ? _flag.toLowerCase() === 'double' : false; } function isOnlinePron() { if (isBluedict()) return !hasElement('.MddExist'); return (hasElement('.lm5ppbody.chrome.desktop') || (!isMDDExisting() && isMobile())); } function isGoldendict() { return hasElement('.goldendict'); } function isBluedict() { return hasElement('.bd_body, .lm5ppbody.bluedict'); } function isEudic() { // search for eudic(欧陆) var _ss = document.styleSheets; for (var i = 0, max = _ss.length; i < max; i++) { if (_ss[i].href && (_ss[i].href.toLowerCase().indexOf('main.css') >= 0)) { return true; } } return (document.getElementsByClassName('expBody').length != 0); } function toggleWordFamily() { $(TAGWORDFAMILY).lm5pp_toggle(); } function removePictureAndSound() { if (!isMDDExisting()) { if (!isMobile()) { $('a.speaker, .fa-volume-up').remove(); $('.EXAMPLE.speaker').removeClass('speaker'); } $('.Crossref.ldoce4img.mdd').remove(); } } function bussDictLinkFix() { $('.bussdictEntry.Entry a.crossRef').each(function (index) { $(this).attr('href', $(this).attr('href').replace('-', ' ')); }) } var imgBuffer = []; var imgTimer; function wallpaperSetup() { if (imgBuffer.length == 0) { var imgQueue = []; for (var i = 0; i < 20; i++) { var _name = 'https://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-' + Math.floor(Math.random() * 1000000); var _img = new Image(); _img.src = _name + '.jpg'; _img.onload = onloadimg; imgQueue.push(_img); } } else { layupImage(); } function onloadimg() { imgBuffer.push(this); this.onload = null; clearTimeout(imgTimer); imgTimer = setTimeout(layupImage, 1000); } function layupImage() { $.each(imgQueue, function () { if (imgBuffer.indexOf(this) < 0) this.src = ''; }); var _img = imgBuffer.shift(); if (!hasElement('.wallpaperPanel')) { var _entry = $('.entry_content:has(.lm5ppMenu:visible)').css('position', 'relative'); var _top = _entry.find('.lm5ppMenu').offset().top - _entry.offset().top + _entry.find('.lm5ppMenu').height() + 10; $('
').append(_img) .css('top', _top) .appendTo(_entry) .on('click', function () { showImage($(this)); }); } else { _img.onload = null; $('.wallpaperPanel img').attr('src', _img.src); } if (prop.ini_wallpaper_interval > 0) { setTimeout(wallpaperSetup, Math.max(30, prop.ini_wallpaper_interval) * 1000); } } function onerrorimg() { } } function scrollPosition(target, offset) { if ($(target).length == 0) return; if (isBluedict()) { var _id = $(target).attr('id'); if (!_id) { _id = 'random' + Math.round(Math.random() * 100000); $(target).attr('id', _id); } if (_id !== undefined) { window.location.href = 'entry://#' + _id; } return; } if (typeof offset == "undefined") { offset = 160; } else if (offset < 1) { var _view = getViewport(); offset = _view.height * offset; } var _top = target.offset().top - offset, _time = 1000; if (!hasElement('.qt5')) { $('html,body').animate({scrollTop: _top}, _time, function () { }); } else { window.scrollTo(0, _top); } } var lm5pp_slideDuration = 300; var lm5pp_effect = true; function isApplyEffect() { return lm5pp_effect && !isBluedict() && (typeof ($.fn.fadeIn) == "function"); } function extendJQuery() { $.fn.extend({ lm5pp_show: function () { var _duration = (arguments.length > 0) && (typeof arguments[0] === 'number') ? arguments[0] : lm5pp_slideDuration; return this.each(function () { if (!isApplyEffect() || _duration <= 0) { $(this).show(); } else { if ($(this).css('display') == 'block') { $(this) .fadeIn({duration: _duration, queue: false}) .slideDown(_duration); } else { $(this) .fadeIn({duration: _duration}); } } }); }, lm5pp_hide: function () { var _duration = (arguments.length > 0) && (typeof arguments[0] === 'number') ? arguments[0] : lm5pp_slideDuration; return this.each(function () { if (!isApplyEffect() || _duration <= 0) { $(this).hide(); } else { if ($(this).css('display') == 'block') { $(this) .fadeOut({duration: _duration, queue: false}) .slideUp(_duration); } else { $(this) .fadeOut({duration: _duration}); } } }); }, lm5pp_toggle: function (option) { return this.each(function (index, element) { if ((typeof (option) != 'undefined') ? option : !$(this).is(":visible")) { $(this).lm5pp_show(); } else { $(this).lm5pp_hide(); } }); }, lm5pp_slideToggle: function (option) { return this.each(function (index, element) { if (typeof ($.fn.slideToggle) == "undefined") { $(this).toggle(option); } else { $(this).slideToggle(option); } }); }, }); } function hasElement(selector) { return !!document.querySelector(selector); } function getViewport() { var e = window, a = 'inner'; if (!('innerWidth' in window)) { a = 'client'; e = document.documentElement || document.body; } var _top = $(window).scrollTop(), _height = e[a + 'Height']; return { top: _top, bottom: _top + _height, width: e[a + 'Width'], height: isBluedict() ? e[a + 'Width'] * 1.6 : _height } } function isInView(element, scrollTo) { var _visible = $(element).filter(':visible').first(); if (!_visible.length ) { return false; } var _view = getViewport(), _offset = _visible.offset() , _result = _offset.top > _view.top && _offset.top < _view.bottom; if (!_result && scrollTo) { scrollPosition(_visible, 0.20); } return _result; } function readIni() { prop = { ini_menuHover: 1, ini_menuHover_delay: 1500, ini_colorExample: 0, ini_etymology_hide: 0, ini_wordfamily_hide: 0, ini_wallpaper: 0, ini_wallpaper_interval: 60 } ; for (var _propName in prop) { if (typeof window[_propName] == typeof prop[_propName]) { prop[_propName] = window[_propName]; } } var _add_class = ''; if (prop.ini_colorExample == 1) { _add_class += 'Example_blue' + ' '; } if (prop.ini_etymology_hide == 1) { _add_class += 'Etym_disable' + ' '; } if (prop.ini_wallpaper == 1429748708) { setTimeout(wallpaperSetup, 1000); } if (prop.ini_wordfamily_hide == 1) { _add_class += 'Wordfamily_disable' + ' '; } $('.lm5ppbody').addClass(_add_class); } function loadImage() { var svg_logo = ''; var _icon_sense = ''; var _icon_close = ''; var _icon_box = ''; function _loadSVG(element, svgString) { if ($(element).find("svg").length != 0) { $(element).find("svg").remove(); } else { $(element).text(''); $(element).append(svgString); } return } if (hasElement('#lm5ppMenu_logo.halfgold')) { svg_logo += svg_logo; } _loadSVG('#lm5ppMenu_logo', svg_logo); _loadSVG('#logo_float', svg_logo); $('#logo_float svg').attr('preserveAspectRatio', 'xMinYMin slice'); _loadSVG('#icon_senseFold', _icon_sense); _loadSVG('#icon_quit', _icon_close); _loadSVG('#icon_boxFold', _icon_box); } function log5p(info) { if ($('#loginfo5p').length == 0) { $('.entry_content:last').after('

'); $('#loginfo5p').show(); } var _old = $('#loginfo5p').text(); $('#loginfo5p').text(_old + '\n' + info); } })