/** * Created by JetBrains PhpStorm. * User: taoqili * Date: 12-2-20 * Time: 上午11:19 * To change this template use File | Settings | File Templates. */ (function () { var audio = {}, uploadaudioList = [], isModifyUploadaudio = false, uploadFile; var editorOpt = {}; window.onload = function () { editorOpt = editor.getOpt('audioConfig'); $focus($G("audioUrl")); initTabs(); initAudio(); initUpload(); }; /* 初始化tab标签 */ function initTabs() { var tabs = $G('tabHeads').children; for (var i = 0; i < tabs.length; i++) { domUtils.on(tabs[i], "click", function (e) { var j, bodyId, target = e.target || e.srcElement; for (j = 0; j < tabs.length; j++) { bodyId = tabs[j].getAttribute('data-content-id'); if (tabs[j] == target) { domUtils.addClass(tabs[j], 'focus'); domUtils.addClass($G(bodyId), 'focus'); } else { domUtils.removeClasses(tabs[j], 'focus'); domUtils.removeClasses($G(bodyId), 'focus'); } } }); } if (!editorOpt.disableUpload) { $G('tabHeads').querySelector('[data-content-id="upload"]').style.display = 'inline-block'; } if (!!editorOpt.selectCallback) { $G('audioSelect').style.display = 'inline-block'; domUtils.on($G('audioSelect'), "click", function (e) { editorOpt.selectCallback(editor, function (info) { if (info) { $G('audioUrl').value = info.path; createPreview(info.path); } }); }); } } function initAudio() { createAlignButton(["audioFloat", "upload_alignment"]); addUrlChangeListener($G("audioUrl")); addOkListener(); //编辑视频时初始化相关信息 (function () { var img = editor.selection.getRange().getClosedNode(), url; if (img && img.className) { var hasFakedClass = (img.className == "edui-faked-audio"), hasUploadClass = img.className.indexOf("edui-upload-audio") != -1; if (hasFakedClass || hasUploadClass) { $G("audioUrl").value = url = img.getAttribute("_url"); var align = domUtils.getComputedStyle(img, "float"), parentAlign = domUtils.getComputedStyle(img.parentNode, "text-align"); updateAlignButton(parentAlign === "center" ? "center" : align); } if (hasUploadClass) { isModifyUploadaudio = true; } } createPreview(url); })(); } /** * 监听确认和取消两个按钮事件,用户执行插入或者清空正在播放的视频实例操作 */ function addOkListener() { dialog.onok = function () { $G("preview").innerHTML = ""; var currentTab = findFocus("tabHeads", "tabSrc"); switch (currentTab) { case "audio": return insertSingle(); break; // case "audioSearch": // return insertSearch("searchList"); // break; case "upload": return insertUpload(); break; } }; dialog.oncancel = function () { $G("preview").innerHTML = ""; }; } /** * 依据传入的align值更新按钮信息 * @param align */ function updateAlignButton(align) { var aligns = $G("audioFloat").children; for (var i = 0, ci; ci = aligns[i++];) { if (ci.getAttribute("name") == align) { if (ci.className != "focus") { ci.className = "focus"; } } else { if (ci.className == "focus") { ci.className = ""; } } } } /** * 将单个视频信息插入编辑器中 */ function insertSingle() { var url = $G('audioUrl').value, align = findFocus("audioFloat", "name"); if (!url) return false; editor.execCommand('insertaudio', { url: url, }, isModifyUploadaudio ? 'upload' : null); } /** * 将元素id下的所有代表视频的图片插入编辑器中 * @param id */ function insertSearch(id) { var imgs = domUtils.getElementsByTagName($G(id), "img"), audioObjs = []; for (var i = 0, img; img = imgs[i++];) { if (img.getAttribute("selected")) { audioObjs.push({ url: img.getAttribute("ue_audio_url"), width: 420, height: 280, align: "none" }); } } editor.execCommand('insertaudio', audioObjs); } /** * 找到id下具有focus类的节点并返回该节点下的某个属性 * @param id * @param returnProperty */ function findFocus(id, returnProperty) { var tabs = $G(id).children, property; for (var i = 0, ci; ci = tabs[i++];) { if (ci.className == "focus") { property = ci.getAttribute(returnProperty); break; } } return property; } /** * 数字判断 * @param value */ function isNumber(value) { return /(0|^[1-9]\d*$)/.test(value); } /** * 创建图片浮动选择按钮 * @param ids */ function createAlignButton(ids) { for (var i = 0, ci; ci = ids[i++];) { var floatContainer = $G(ci), nameMaps = { "none": lang['default'], "left": lang.floatLeft, "right": lang.floatRight, "center": lang.block }; for (var j in nameMaps) { var div = document.createElement("div"); div.setAttribute("name", j); if (j == "none") div.className = "focus"; div.style.cssText = "background:url(images/" + j + "_focus.jpg);"; div.setAttribute("title", nameMaps[j]); floatContainer.appendChild(div); } switchSelect(ci); } } /** * 选择切换 * @param selectParentId */ function switchSelect(selectParentId) { var selects = $G(selectParentId).children; for (var i = 0, ci; ci = selects[i++];) { domUtils.on(ci, "click", function () { for (var j = 0, cj; cj = selects[j++];) { cj.className = ""; cj.removeAttribute && cj.removeAttribute("class"); } this.className = "focus"; }) } } /** * 监听url改变事件 * @param url */ function addUrlChangeListener(url) { if (browser.ie) { url.onpropertychange = function () { createPreview(this.value); } } else { url.addEventListener("input", function () { createPreview(this.value); }, false); } } function createAudioHtml(url, param) { param = param || {}; var str = [ "', ]; return str.join(''); } /** * 根据url生成视频预览 * @param url */ function createPreview(url) { if (!url) { return; } $G("preview").innerHTML = '
' + file.name + '
' + '' + '' + '