锘?** * 姝ゆ枃浠剁殑澶撮儴娉ㄩ噴 */ /*global jQuery: false */ (function ($) { 'use strict'; pe.ui = {}; var $home = window.top.pe.home; var frameHistory = function (frameName) { this.frameName = frameName; this.records = []; }; frameHistory.prototype = { frameName: '', add: function (url) { this.records.push(url); }, back: function () { this.records.pop(); var src = this.records.pop(); window.top.$('iframe[data-historian=' + this.frameName + ']').prop('src', src); } }; var history = function () { var ele; if (window.top.pe.ui.history) { ele = window.top.pe.ui.history; } else { window.top.pe.ui.history = ele = {}; } this.records = ele; }; history.prototype = { records: null, frame: function (name) { if (name in this.records) { return this.records[name]; } else { var fh = new frameHistory(name); this.records[name] = fh; return fh; } } }; pe.ui.historian = function () { return new history(); }; function bindNewTabLink() { $('body') .on('click', 'a', function (e) { var $this = $(this), url = $this.prop('href'); if (url && ($this.is("[data-tabs-target='_blank']") || e.ctrlKey)) { $home.tabs.addTab(url); return false; } return true; }); } $(function () { $(".btn.disabled") .click(function () { return false; }); $('.history-back') .each(function (i, n) { var frame = $home.currentFrame(), self = $(this); if (pe.ui.historian().frame(frame.attr('data-historian')).records.length < 1) { self.addClass('disabled'); self.on('click', function (e) { return false; }); } else { self.on('click', function (e) { var $home = window.top.pe.home, frame = $home.currentFrame(); pe.ui.historian().frame(frame.attr('data-historian')).back(); return false; }); } }); bindNewTabLink(); }); $('.unselect').on('selectstart', function (e) { return false; }).attr('unselectable', 'on'); $.each($('a[data-confirm]'), function () { var $this = $(this); var placement = 'bottom'; if ($this.data('placement')) { placement = $this.data('placement'); } var message = $this.attr('data-confirm'); $this.confirmation({ placement: placement, title: message, btnOkLabel: '纭畾', btnCancelLabel: '鍙栨秷', popout: false, onConfirm: function (event, element) { var href = $(element).attr('href'); if (href) { window.location.href = href; } else { var confirm = $this.data("onConfirm"); if (confirm) { confirm(); } } } }); }); var videoElements = []; /* videoSrc锛氳棰戝湴鍧€ succeedFunc锛氳幏鍙栬棰戝抚鎴愬姛鍚庡洖璋 errorFunc锛氳幏鍙栬棰戝抚澶辫触鍚庡洖璋 imgWidth锛氱敓鎴愬浘鐗囧搴 imgHeight锛氱敓鎴愬浘鐗囬珮搴 */ pe.ui.VideoCover = function (videoSrc, succeedFunc, errorFunc, imgWidth, imgHeight) { if (videoSrc) { var videoElement = document.createElement("VIDEO"); videoElement.src = videoSrc; videoElement.muted = true; videoElement.autoplay = true; // 瑙嗛涓€瀹氳璁剧疆鑷姩鎾斁锛屽惁鍒欐姄鍑烘潵鐨勫皝闈笉鏄櫧鐨勫氨鏄€忔槑鐨 videoElement.setAttribute("crossOrigin", 'anonymous'); videoElement.setAttribute('playsinline', ''); videoElement.setAttribute('webkit-playsinline', ''); //杩欎釜灞炴€ф槸鍐呰仈鎾斁锛岄伩鍏嶅湪ios涓紝ios浼氬姭鎸佹挱鏀惧櫒锛岃嚜鍔ㄥ脊鍑烘挱鏀剧晫闈 videoElement.addEventListener("loadeddata", () => { try { var { videoWidth, videoHeight } = videoElement; // 鑾峰彇video鐨勫楂 // var maxLength = videoWidth > videoHeight ? videoWidth : videoHeight; // 鍥哄畾瑙嗛缂╃暐鍥剧敓鎴愭瘮渚 var imgWidth = 800; var imgHeight = 450; var x = 0, y = 0, width = 0, height = 0; // 璁$畻缂╁皬鍚庡浘鐗囩殑瀹介珮浠ュ強canvas缁樺埗鐨勪綅缃俊鎭 if (videoWidth / videoHeight >= 1.5) { width = imgWidth; height = videoHeight * (imgWidth / videoWidth); x = 0; y = (imgHeight - height) / 2; } else { height = imgHeight; width = videoWidth * (imgHeight / videoHeight); y = 0; x = (imgWidth - width) / 2; } var canvas = document.createElement("canvas"); canvas.width = imgWidth; canvas.height = imgHeight; var ctx = canvas.getContext("2d"); ctx.fillStyle = "#000"; ctx.fillRect(0, 0, imgWidth, imgHeight); ctx.drawImage(videoElement, x, y, width, height); var src = canvas.toDataURL("image/png"); // 瀹屾垚base64鍥剧墖鐨勫垱寤 if (succeedFunc) { succeedFunc(src) } // 娓呯┖video瀵硅薄 videoElements.splice($.inArray(videoElement, videoElements), 1); videoElement = null; } catch (e) { if (errorFunc) { errorFunc() } } }) videoElement.addEventListener("error", () => { if (errorFunc) { errorFunc() } }); videoElements.push(videoElement); // 瀛樺偍video瀵硅薄闃叉鍥炴敹 } } // 閽堝鍓嶅彴瑙嗛鍒楄〃椤佃棰戝皝闈㈢殑甯у垵濮嬪寲 $(function () { $(".video-showcover img").each(function () { var $imgDiv = $(this), videoSrc = $imgDiv.data('videourlforcoverimage'); pe.ui.VideoCover(videoSrc, (src) => { $imgDiv.attr('src', src); }, () => { $imgDiv.attr('src', '/content/_common/base/img/nopic.gif'); } ) }) }); /** * HTML鏍囩XSS杩囨护 * * @param {String} html * @return {String} */ pe.ui.filterXSS = function (html) { return filterXSS(html, { onIgnoreTagAttr: function (tag, name, value, isWhiteAttr) { if (name === 'class' || name === 'hidefocus' || name.substr(0, 5) === 'data-' || name.substr(0, 7) === 'action-' ) { return name + '="' + filterXSS.escapeAttrValue(value) + '"'; // 閫氳繃鍐呯疆鐨別scapeAttrValue鍑芥暟鏉ュ灞炴€у€艰繘琛岃浆涔 } } }); } /** * String瀛楃涓瞂SS杩囨护 * * @param {String} string * @return {String} */ pe.ui.filterStringXSS = function (string) { return filterXSS(string, { whiteList: {}, // 鐧藉悕鍗曚负绌猴紝琛ㄧず杩囨护鎵€鏈夋爣绛 stripIgnoreTag: true, // 杩囨护鎵€鏈夐潪鐧藉悕鍗曟爣绛剧殑HTML stripIgnoreTagBody: ['script'] // script鏍囩杈冪壒娈婏紝闇€瑕佽繃婊ゆ爣绛句腑闂寸殑鍐呭 }).replace(/'/g, "").replace(/"/g, ""); } }(jQuery));