var InlineEditor = function () { var currentMeta = null; function handleCancelClick(event) { deactivateEditor(); } function handleSaveClick(event) { } function handleEditorKey(event) { alert("handleEditorKey"); if (event.keyCode != 27) return; var target = Dom.getTarget(event); if (!target) return; var editor = Dom.findParentWithClass(target, "Editor"); if (!editor) return; deactivateEditor(); } function handleMaskClick(event) { deactivateEditor(); } function deactivateEditor() { Dom.removeClass(document.body.parentNode, "EditorActivated"); if (currentMeta && currentMeta._editorElements && currentMeta._editorElements.editor) { currentMeta._editorElements.editor.parentNode.removeChild(currentMeta._editorElements.editor); } currentMeta = null; } function activateEditor(meta) { if (currentMeta) { deactivateEditor(); } currentMeta = meta; maskSetup(meta); window.setTimeout(function () { showEditor(meta); }, 0); } function maskSetup(meta) { Dom.addClass(document.body.parentNode, "EditorActivated"); if (!document.body._mask) { var mask = document.createElement("div"); mask.className = "EditorMask"; document.body._mask = mask; document.body.appendChild(mask); Dom.registerEvent(mask, "click", handleMaskClick, false); } //Thiet lap hien thi EditorMask IE6 //vi IE6 khong the set height bang cac position //Tuy nhien no se tao nen khong gian thua ben duoi if(getInternetExplorerVersion() == 6){ document.body._mask.style.height = (Math.max(Dom.getScrollTop() + Dom.getWindowHeight(), Dom.getOffsetWidth(document.body))) + "px"; } } function showEditor(meta) { var editor = document.createElement("div"); var editorContainer = document.body; editorContainer.appendChild(editor); editor.className = "Editor " + meta.contentType + "Editor"; var iframe = document.createElement("iframe"); iframe.src = meta.url; iframe.frameBorder = 0; editor.appendChild(iframe); meta._editorElements = { editor: editor }; } return { init: function () { Dom.registerEvent(window, "load", function (e) { Dom.registerEvent(window.document.body, "click", function (event) { var target = Dom.getTarget(event); if (!target) return; var toolbox = Dom.findParentWithClass(target, "EditLink"); if (!toolbox) return; if (!window._StaticContent) return; var container = Dom.findParentWithClass(toolbox, "NoiDung"); if (!container) return; var id = container.id; if (!id) return; var meta = window._StaticContent[id]; if (!meta) return; meta._container = container; meta._toolbox = toolbox; //Disable cancel event with IE 6 if(getInternetExplorerVersion() != 6){ Dom.cancelEvent(event); } activateEditor(meta); return; }, false); }, false) }, close: function() { deactivateEditor(); }, done: function() { deactivateEditor(); if(getInternetExplorerVersion() == 6 || getInternetExplorerVersion() == 7 || getInternetExplorerVersion() == 8){ //Neu IE 6 thi reload bang cach nay window.location.reload(); } else { window.location = window.location.href; } } }; }(); function getInternetExplorerVersion() // Returns the version of Internet Explorer or a -1 // (indicating the use of another browser). { var rv = -1; // Return value assumes failure. if (navigator.appName == 'Microsoft Internet Explorer') { var ua = navigator.userAgent; var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})"); if (re.exec(ua) != null) rv = parseFloat( RegExp.$1 ); } return rv; } InlineEditor.init();