'; this.$footToolbar.append(btn); }, opened: function(el){ var color = $(el).data('color'); if (color) { $('.magnify-modal').css('background-color', color); } }, changed: function(index){ var color = $('[data-magnify]').eq(index).data('color'); if (color) { $('.magnify-modal').css('background-color', color); $('.header-brand').css('color', color); } var slug = $('[data-magnify]').eq(index).data('slug'); if (!slug) return; this.$footToolbar.find('.magnify-button-slug').attr('href',slug); }, beforeClose: function(el){ var path = this.$image[0].getAttribute('src'); $link = $('a[href$="'+ path+'"]'); $('html,body').stop().animate({scrollTop:$link.offset().top - 100}, 800); } }, footToolbar: [ 'zoomIn', 'zoomOut', 'prev', 'fullscreen', 'next', 'actualSize', 'rotateRight', 'rotateLeft' ], i18n: { minimize: '最小化', maximize: '最大化', close: '关闭', zoomIn: '放大', zoomOut: '缩小', prev: '上一张', next: '下一张', fullscreen: '全屏', actualSize: '实际尺寸', rotateLeft: '向左旋转', rotateRight: '向右旋转' } }; if ($('[data-magnify=gallery]').length == 1) { mgopts.footToolbar.splice(2,1); mgopts.footToolbar.splice(3,1); } $('[data-magnify=gallery]').magnify(mgopts); }); _gaq=[['_setAccount', 'UA-104671304-1'], ['_trackPageview'],['_trackPageLoadTime']]; var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); var _hmt = _hmt || []; var bdhm = document.createElement('script'); bdhm.type = 'text/javascript'; bdhm.async = true; bdhm.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'hm.baidu.com/h.js?a78d457d485651de49e7850e45aa9145'; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(bdhm, s); (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); if ($('.form-search').length) { loadjs('https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/tom-select/2.2.2/js/tom-select.complete.min.js', function(){ $('.form-search input[name="tag"]').each(function(idx,frm){ new TomSelect(frm, { maxItems: 1, create: true, persist: false, onItemAdd: function(value, item){ $(frm).val(value); $(frm).parents('form').submit(); }, render:{ option_create: function( data, escape ){ return '
搜索 ' + escape(data.input) + '…
'; }, no_results: function( data, escape ){ return ''; } }, load: function(query, callback) { if (!query.length) return callback(); $.ajax({ url: 'https://colorhub.me/search/suggest', dataType: 'json', data: { q: query }, success: function(res) { callback(res); } }); } }); }); }); } $('.icon-droplet,.ad-link').css('color', '#f07b7d'); var photo_div = $('a[data-magnify=gallery]'); $('.photo-color').hover(function(){ hex = $(this).find('span').attr('data-hex'); photo_div.parent().css('background-color', hex); photo_div.data('color', hex); $('.icon-droplet,.ad-link').css('color', hex); },function(){ }); var $dw = $('input[name="width"]'), $dh = $('input[name="height"]'), $c = $('#custom'), $cw = $('input[name="cwidth"]'), $ch = $('input[name="cheight"]'); $('input[name="size"]').on('click', function(){ if ($(this).is(':checked')) { var $value = $(this).val().split('x'); $dw.val(parseInt($value[0]) || 0); $dh.val(parseInt($value[1]) || 0); } }); $cw.keyup(function(){ $c.val(parseInt($(this).val())+'x'+parseInt($ch.val())); $c.click(); }); $ch.keyup(function(){ $c.val(parseInt($cw.val())+'x'+parseInt($(this).val())); $c.click(); }); loadjs('/js/readmore.min.js', function (){ $('.tags').readmore({ collapsedHeight: 90, moreLink: ' 更多', lessLink: ' 收起', }); }); loadjs(['https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/social-share.js/1.0.16/css/share.min.css','https://mirrors.sustech.edu.cn/cdnjs/ajax/libs/social-share.js/1.0.16/js/jquery.share.min.js'], function(){ var $config = { image: "//cdn.colorhub.me/64ilh6vc2tw/rs:auto:0:500:0/g:ce/fn:colorhub/bG9jYWw6Ly8vOWYvODgvNmZiZmM3YWU5OWIwYmQyNzZmMWM5MWMwMWRiODAxNzU3YzkxOWY4OC5qcGc.webp", disabled: "tencent,diandian,linkedin" }; $('.social-share-cs').share($config); }); $('.hide-theme-dark').click(function(){ document.body.classList.remove('theme-light'); document.body.classList.add("theme-dark"); localStorage.setItem(themeKey, 'dark'); }); $('.hide-theme-light').click(function(){ document.body.classList.remove('theme-dark'); document.body.classList.add("theme-light"); localStorage.setItem(themeKey, 'light'); }); function lazyEnter(el) { var flag = el.getAttribute("data-lazy-enter"); var hash = el.getAttribute("data-hash"); if (!flag || !hash) return; var hashArr = str2char(atob(hash)); el.style.backgroundImage = 'url("'+thumbHashToDataURL(hashArr)+'")'; }; window.lazyLoadedFn = { photos: function (el) { $(el).removeClass('invisible'); if ($(el).prev().hasClass('loader')) { $(el).prev().remove(); } else { $(el).parent().removeClass('loader').addClass('w-100'); } $(el).parents('a').css('min-height', 'auto'); var $fp = $(el).parents('.focuspoint'); if($fp.length) { $fp.attr({'data-image-w':el.naturalWidth,'data-image-h':el.naturalHeight}); $fp.focusPoint(); } if(typeof $masonry !== 'undefined') { $masonry.masonry('layout'); } }, photo: function (el) { $(el).removeClass('invisible'); $(el).parents('.photo-div').css('background-image', ''); }, fp: function (el) { $(el).removeClass('invisible'); if ($(el).prev().hasClass('loader')) { $(el).prev().remove(); } var $fp = $(el).parents('.focuspoint'); if($fp.length) { $fp.attr({'data-image-w':el.naturalWidth,'data-image-h':el.naturalHeight}); loadjs(['/js/jquery.focuspoint.min.js?2412'], function(){ $fp.focusPoint(); }); } } }; function execLazyLoadedFn(el) { var lazyFnName = el.getAttribute("data-lazy-loaded"); var lazyFn = window.lazyLoadedFn[lazyFnName]; if (!lazyFn) return; lazyFn(el); } var pageLazyLoad = new LazyLoad({ elements_selector: ".lazy", unobserve_entered: true, callback_enter: lazyEnter, callback_loaded: execLazyLoadedFn }); $('.favorite,.similar,.recommend,.collect,.color-icon').tooltip({container:'body',placement:'bottom'}); $('.favorite,.similar,.recommend,.collect,.color-icon,.link').hover(function(){ $(this).css('transform','scale(1.25)'); $(this).find('.icon').addClass('icon-pulse'); },function(){ $(this).css('transform','scale(1)'); $(this).find('.icon').removeClass('icon-pulse'); }); var spinner = $('#spinner').clone(); $('.ajax-modal').click(function(e){ e.preventDefault(); var that = $(this); $('#modaljx').modal('show'); $('#modaljx').find('.modal-dialog').html(spinner.html()).load(that.attr("data-href")); }); $('.favorite').on('ajax:success', function(event, data, status, xhr) { var that = $(this); if(data.code == 200){ that.find('.icon').toggleClass('text-red'); var msg = data.increment > 0 ? '已喜欢' : '加入喜欢'; $('.tooltip-inner').text(msg); that.attr('title', msg).attr('data-bs-original-title', msg); }else if(data.code == 401){ if(!confirm(data.message)){ return false; } location.href=data.url; }else{ alert(data.message); } }).on('ajax:error',function(event, xhr, status, error){ if(xhr.status == 401){ $('#modaljx').find('.modal-dialog').html(spinner).load('https://colorhub.me/auth/login'); $('#modaljx').modal('show'); }else{ alert('服务器错误,请稍后重试'); } }); if (typeof pageLazyLoad !== 'undefined'){ pageLazyLoad.update(); } }); });