1/** 2 * @description å®ç½é¡¶é¨å·¥å ·æ 3 * @time 2021-12-17 10:34:57 4 * è°ç¨æ¹å¼ï¼ä¸ä¼ åæ°ï¼åç¨é»è®¤é ç½®ï¼ï¼ 5 1ã页é¢å¼å ¥toolbar.jsãtoolbar.css 6 2ã$('body').toolbar({ 7 zoomDom: '.zoomElement', // æ¾å¤§ç容å¨å ç´ 8 zoomMax: 2, // ç¼©æ¾æå¤§æ¯ä¾ 9 zoomMin: 1, // ç¼©æ¾æå°æ¯ä¾ 10 zoomStep: 0.1, // ç¹å»ç¼©æ¾ 11 switchBtn: true, // å·¥å ·æ å¼å ³ 12 switchBtnPosTop: '50%', // ä¾§è¾¹æ å¼å ³å®ä½topå¼ 13 domain: '.cpic.com.cn', // 设置cookie 14 callback: function(barFnNameï¼ number){}, // å·¥å ·æ æä½è§¦ååè° number:缩æ¾åæ°ï¼ eventType:å·¥å ·æ æé®å¯¹åºäºä»¶åç§° 15 fixedDomArr: [], // dom arr é坹忥fixedå®ä½å ç´ å¤çï¼ä»¥å ¼å®¹IEåIEå ¼å®¹æ¨¡å¼æµè§å¨ 16}) 17 */ 18(function ($) { 19// ç§ææ¹æ³ 20 var privateFun = function () { 21 }; 22 var getCookie = function (c_name) { 23 if (document.cookie.length > 0) { 24 c_start = document.cookie.indexOf(c_name + '='); 25 if (c_start !== -1) { 26 c_start = c_start + c_name.length + 1; 27 c_end = document.cookie.indexOf(';', c_start); 28 if (c_end === -1) { 29 c_end = document.cookie.length; 30 } 31 return unescape(document.cookie.substring(c_start, c_end)); 32 } 33 } 34 return null; 35 } 36 var setCookie = function (name, value, days, path, domain) { 37 var Days = days || 0; 38 var path = path || ''; 39 var domain = domain || ''; 40 var expires = ''; 41 if (Days !== 0) { 42 var date = new Date(); 43 date.setTime(date.getTime() + Days * 24 * 60 * 60 * 1000); 44 expires = '; expires=' + date.toGMTString(); 45 } 46 if (path !== '') { 47 path = ';path=' + path; 48 } 49 if (domain !== '') { 50 domain = ';domain=' + domain; 51 } 52 document.cookie = name + '=' + escape(value) + expires + path + domain + ''; 53 } 54 function debounce(fn, interval) { 55 let timeout = null; 56 return function () { 57 clearTimeout(timeout); 58 timeout = setTimeout(function() { 59 fn.apply(this, arguments); 60 }, interval || 300); 61 }; 62 } 63 var urlKey = location.origin.indexOf('sit') !== -1 ? 'sit' : 'prod'; 64 var urlObj = { 65 sit: { 66 websitUrl: 'https://www.cpic.com.cn/' 67 }, 68 prod: { 69 websitUrl: 'https://www.cpic.com.cn/' 70 } 71 } 72// å并对象ç 73 var toolbar = (function () { 74 function toolbar(element, options) { 75 // 设置为trueæ·±æ·è´,å并对象 76 var initDefault = $.extend(true, {}, $.fn.toolbar.options) 77 this.settings = $.extend(true, initDefault, options || {}); 78 this.element = element || $(document.body); 79 this.zoomElement = $(this.settings.zoomDom); 80 this.fnName = { 81 hideToolbar: 'hideToolbar', 82 showToolbar: 'showToolbar', 83 initZoom: 'initZoom', 84 changeZoom: 'changeZoom' 85 } 86 this.show = false; 87 88 // åå§åæä»¶ 89 this.init() 90 } 91 92 // å¨toolbarååä¸å®ä¹æ¹æ³,让å®ä¾å¯ä»¥è°ç¨è¿äºæ¹æ³ 93 toolbar.prototype = { 94 // åè½æ¹æ³ 95 init: function () { 96 this.creatHtml() 97 this.initZoom() 98 }, 99 creatHtml: function () { 100 // bar 101 var toolbarHtml = ''; 102 toolbarHtml += '<div class="toolbar">' 103 toolbarHtml += '<ul class="toolbar-div">' 104 toolbarHtml += '<li class="bar-item">' 105 toolbarHtml += '<span class="bar-img toolbar_reset"><img src="' + urlObj[urlKey].websitUrl + '/toolbar/images/reflash1.png" alt=""></span>' 106 toolbarHtml += '<span class="bar-text" title="éç½®">éç½®</span>' 107 toolbarHtml += '</li>' 108 toolbarHtml += '<li class="bar-item">' 109 toolbarHtml += '<span class="bar-img toolbar_amplification"><img src="' + urlObj[urlKey].websitUrl + '/toolbar/images/enlarge1.png" alt=""></span>' 110 toolbarHtml += '<span class="bar-text" title="æ¾å¤§">æ¾å¤§</span>' 111 toolbarHtml += '</li>' 112 toolbarHtml += '<li class="bar-item">' 113 toolbarHtml += '<span class="bar-img toolbar_narrow"><img src="' + urlObj[urlKey].websitUrl + '/toolbar/images/small1.png" alt=""></span>' 114 toolbarHtml += '<span class="bar-text" title="缩å°">缩å°</span>' 115 toolbarHtml += '</li>' 116 toolbarHtml += '<li class="bar-item">' 117 toolbarHtml += '<span class="bar-img toolbar_exit"><img src="' + urlObj[urlKey].websitUrl + '/toolbar/images/exit1.png" alt=""></span>' 118 toolbarHtml += '<span class="bar-text" title="éåº">éåº</span>' 119 toolbarHtml += '</li>' 120 toolbarHtml += ' </ul>' 121 toolbarHtml += '</div>'; 122 123 this.element.append(toolbarHtml) 124 if (this.settings.switchBtn) { 125 this.loadSwithBtn() 126 } 127 this.events(); 128 }, 129 loadSwithBtn: function () { 130 // å¼å ³ 131 var btnHtml = '<div class="bar-switch-button" style="top: ' + this.settings.switchBtnPosTop + '">ç±å¿æ¨¡å¼</div>'; 132 this.element.append(btnHtml) 133 }, 134 // ç¼©æ¾ 135 changeZoom: function (type) { 136 var number = this.zoomElement.css("transform") ? 137 Number(this.zoomElement 138 .css("transform") 139 .replace(/[^0-9\-\.,]/g, '') 140 .split(',')[0]) : 1; 141 // æ¾å¤§åæ° 142 if (type === '+' && number < this.settings.zoomMax) { 143 number += this.settings.zoomStep 144 } 145 // 缩å°åæ° 146 if (type === '-' && number > this.settings.zoomMin) { 147 number -= this.settings.zoomStep 148 } 149 // æå®åæ° 150 if (typeof type === 'number') { 151 number = type; 152 } 153 // css3ç¼©æ¾ 154 this.zoomElement.css({ 155 'transform': "scale(" + number + ")", 156 'transform-origin': '0px 0px' 157 }) 158 // æ»å¨æ¡å± ä¸ 159 window.scrollTo((document.body.scrollWidth - window.innerWidth) / 2, 0) 160 // ä¿åå¨cookieä¸ï¼é¡µé¢å ¬ç¨
161 setCookie('readZoom', number, '', '/', this.settings.domain) 162 this.callBack(this.fnName.changeZoom, number) 163 }, 164 // åå§åç¼©æ¾ 165 initZoom: function () { 166 var number = Number(getCookie('readZoom')); 167 if (number) { 168 // åå§åzoomç³»æ° 169 this.changeZoom(number) 170 setTimeout(function () { 171 window.scrollTo((document.body.scrollWidth - window.innerWidth) / 2, 0) 172 }, 300) 173 } 174 // baræ¾ç¤ºä¸å¦ 175 176 if (Number(getCookie('toolbarVisible'))) { 177 this.showToolbar(); 178 } 179 if ((number === 1 || !number) && $('.toolbar').css('display') === 'none') { 180 this.zoomElement.css({ 181 'transform': "none", 182 'transform-origin': '0px 0px' 183 }) 184 } 185 this.fixedElementCompatibleIE(this.fnName.initZoom, number, this.settings.fixedDomArr) 186 this.callBack(this.fnName.initZoom, number) 187 }, 188 // æ¾ç¤ºbar 189 showToolbar: function () { 190 $('.zoomElement').addClass('zoomElement-zoomed'); 191 var number = Number(getCookie('readZoom')) || 1 192 this.changeZoom(number) 193 $(".toolbar").slideDown(0); 194 this.show = true; 195 $("body").animate({paddingTop: '98px'}, 0); 196 this.fixedElementCompatibleIE(this.fnName.showToolbar, number, this.settings.fixedDomArr) 197 setCookie('toolbarVisible', 1, '', '/', this.settings.domain); 198 this.callBack(this.fnName.showToolbar, number) 199 }, 200 // éèbar 201 hideToolbar: function () { 202 var that = this; 203 $(".toolbar").slideUp(0); 204 var number = Number(getCookie('readZoom')) || 1 205 this.show = false; 206 this.changeZoom(1) 207 $("body").animate({paddingTop: '0px'}, 0); 208 setTimeout(function () { 209 that.resetTransform() 210 }, 350) 211 this.fixedElementCompatibleIE(this.fnName.hideToolbar, number, this.settings.fixedDomArr) 212 setCookie('toolbarVisible', 0, '', '/', this.settings.domain); 213 this.callBack(this.fnName.hideToolbar, number) 214 setTimeout(function(){ 215 $('.zoomElement').removeClass('zoomElement-zoomed'); 216 },350) 217 }, 218 // 忢barå¯è§æ§ 219 toggleToolbar: function () { 220 if ($('.toolbar').css('display') === 'block') { 221 this.hideToolbar() 222 } else { 223 this.showToolbar(); 224 } 225 }, 226 // æ¸ é¤transform 227 resetTransform: function () { 228 var number = this.zoomElement.css("transform") ? 229 Number(this.zoomElement 230 .css("transform") 231 .replace(/[^0-9\-\.,]/g, '') 232 .split(',')[0]) : 1; 233 if ((number === 1 || !number) && $('.toolbar').css('display') === 'none') { 234 this.zoomElement.css({ 235 'transform': "none", 236 'transform-origin': '0px 0px' 237 }) 238 } 239 }, 240 // 缩æ¾åï¼ieè·åieå ¼å®¹æ¨¡å¼å¯¹åºå®å®ä½å ç´ å¤ç 241 fixedElementCompatibleIE: function (fn, number, arr) { 242 var timer = {}; 243 for (var j = 0; j < arr.length; j++) { 244 if (fn === this.fnName.showToolbar || 245 (fn === this.fnName.initZoom && number !== 1)) { // å·¥å ·æ æ¾ç¤ºæè åå§å 246 if (navigator.userAgent.indexOf('Trident') !== -1) { // ieæµè§å¨ æè IEå ¼å®¹æ¨¡å¼å¤çfixedå®ä½å ç´ 247 if (arr[j].sync) { 248 (function (i) { 249 timer[i + 'xxx'] = setInterval(function () { 250 if ($(arr[i].name).length > 0) { 251 clearInterval(timer[i + 'xxx'])
252 $(arr[i].name).css({ 253 position: 'absolute' 254 }) 255 } 256 }, 0) 257 })(j); 258 } else { 259 $(arr[j].name).css({ 260 position: 'absolute' 261 }) 262 } 263 } 264 } 265 if ((fn === this.fnName.hideToolbar || fn === this.fnName.initZoom) 266 && number === 1 && !this.show) { // å·¥å ·æ åå§åæè éè 267 (function (i) { 268 setTimeout(function timer() { 269 if (navigator.userAgent.indexOf('Trident') !== -1) { // ieæµè§å¨ æè IEå ¼å®¹æ¨¡å¼å¤çfixedå®ä½å ç´ 270 if (arr[i].sync) { 271 (function (k) { 272 timer[k + 'xxx'] = setInterval(function () { 273 if ($(arr[k].name).length > 0) { 274 clearInterval(timer[k + 'xxx']) 275 $(arr[k].name).css({ 276 position: 'fixed' 277 }) 278 } 279 }, 0) 280 })(i); 281 } else { 282 $(arr[i].name).css({ 283 position: 'fixed' 284 }) 285 } 286 } 287 }, 310); 288 })(j); 289 } 290 } 291 }, 292 // æ·»å äºä»¶ 293 events: function () { 294 var that = this 295 // éç½® 296 this.element.find(".toolbar .toolbar_reset").click(function () { 297 that.changeZoom(1); 298 }); 299 // æ¾å¤§ 300 this.element.find(".toolbar .toolbar_amplification").click(function () { 301 that.changeZoom('+'); 302 }); 303 // ç¼©å° 304 this.element.find(".toolbar .toolbar_narrow").click(function () { 305 that.changeZoom('-'); 306 }); 307 // éåº 308 this.element.find(".toolbar .toolbar_exit").click(function () { 309 that.changeZoom(1); 310 that.hideToolbar(); 311 }); 312 // å¼å ³ 313 this.element.find(".bar-switch-button").click(function () { 314 that.toggleToolbar() 315 }); 316 }, 317 // åè°å½æ° 318 callBack: function (fn, number) { 319 if (this.settings.callback && typeof this.settings.callback == "function") { 320 this.settings.callback(fn, number) 321 } 322 } 323 }; 324 return toolbar; 325 })(); 326// å建对象å®ä¾ 327 $.fn.toolbar = function (options, param) { 328 // å®ç°é¾å¼è°ç¨ 329 return this.each(function () { 330 var me = $(this), 331 instance = me.data("toolbar"); 332 // 夿å®ä¾æ¯å¦åå¨ï¼ä¸åå¨åå建对象ï¼å¹¶å°è¯¥å¯¹è±¡åé ç½®é¡¹ä¼ å ¥ 333 if (!instance) { 334 instance = new toolbar(me, options); 335 // åæ¾å®ä¾ 336 me.data("toolbar", instance); 337 } 338 // å¨å¤é¨å¯ä»¥éè¿$(selection).toolbar("init") 339 if ($.type(options) === "String" || $.type(options) === "string") { 340 return instance[options](param); 341 } 342 }); 343 }; 344// é ç½®åæ° 345 $.fn.toolbar.options = { 346 zoomDom: '.zoomElement', // æ¾å¤§ç容å¨å ç´ 347 zoomMax: 2, // ç¼©æ¾æå¤§æ¯ä¾ 348 zoomMin: 1, // ç¼©æ¾æå°æ¯ä¾ 349 zoomStep: 0.1, // ç¹å»ç¼©æ¾ 350 switchBtn: true, // å·¥å ·æ å¼å ³ 351 switchBtnPosTop: '50%', // ä¾§è¾¹æ å¼å ³å®ä½topå¼ 352 domain: '.cpic.com.cn', // 设置cookie 353 callback: '', // å·¥å ·æ æä½è§¦ååè° 354 fixedDomArr: [], // é坹忥fixedå®ä½å ç´ å¤çï¼ä»¥å ¼å®¹IEåIEå ¼å®¹æ¨¡å¼æµè§å¨ 355 }; 356})(jQuery, window, document)
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.