diff --git a/controllers/base.go b/controllers/base.go index 83ca0ec8..17ca1cdc 100644 --- a/controllers/base.go +++ b/controllers/base.go @@ -110,3 +110,11 @@ func (c *BaseController) ExecuteViewPathTemplate(tplName string,data interface{} func (c *BaseController) BaseUrl() string { return c.Ctx.Input.Scheme() + "://" + c.Ctx.Request.Host } + +//显示错误信息页面. +func (c *BaseController) ShowErrorPage(errCode int,errMsg string) { + c.TplName = "errors/error.tpl" + c.Data["ErrorMessage"] = errMsg + c.Data["ErrorCode"] = errCode + c.StopRun() +} \ No newline at end of file diff --git a/controllers/document.go b/controllers/document.go index bfb6f07f..4c178b7a 100644 --- a/controllers/document.go +++ b/controllers/document.go @@ -1081,6 +1081,60 @@ func (c *DocumentController) RestoreHistory() { func (c *DocumentController) Compare() { c.Prepare() c.TplName = "document/compare.tpl" + history_id ,_ := strconv.Atoi(c.Ctx.Input.Param(":id")) + identify := c.Ctx.Input.Param(":key") + + book_id := 0 + editor := "markdown" + + //如果是超级管理员则忽略权限判断 + if c.Member.IsAdministrator() { + book, err := models.NewBook().FindByFieldFirst("identify", identify) + if err != nil { + beego.Error("DocumentController.Compare => ", err) + c.Abort("403") + return + } + book_id = book.BookId + c.Data["Model"] = book + editor = book.Editor + } else { + bookResult, err := models.NewBookResult().FindByIdentify(identify, c.Member.MemberId) + + if err != nil || bookResult.RoleId == conf.BookObserver { + beego.Error("FindByIdentify => ", err) + c.Abort("403") + return + } + book_id = bookResult.BookId + c.Data["Model"] = bookResult + editor = bookResult.Editor + } + + if history_id <= 0 { + c.ShowErrorPage(60002,"参数错误") + } + + history,err := models.NewDocumentHistory().Find(history_id) + if err != nil { + beego.Error("DocumentController.Compare => ",err) + c.ShowErrorPage(60003,err.Error()) + } + doc,err := models.NewDocument().Find(history.DocumentId) + + if doc.BookId != book_id { + c.ShowErrorPage(60002,"参数错误") + } + c.Data["HistoryId"] = history_id + c.Data["DocumentId"] = doc.DocumentId + + if editor == "markdown" { + c.Data["HistoryContent"] = history.Markdown + c.Data["Content"] = doc.Markdown + }else{ + c.Data["HistoryContent"] = template.HTML(history.Content) + c.Data["Content"] = template.HTML(doc.Content) + } } //递归生成文档序列数组. diff --git a/models/document_history.go b/models/document_history.go index 6a191a64..edadf943 100644 --- a/models/document_history.go +++ b/models/document_history.go @@ -50,8 +50,11 @@ func (m *DocumentHistory) TableNameWithPrefix() string { func NewDocumentHistory() *DocumentHistory { return &DocumentHistory{} } -func (m *DocumentHistory) Find() { +func (m *DocumentHistory) Find(id int) (*DocumentHistory,error) { + o := orm.NewOrm() + err := o.QueryTable(m.TableNameWithPrefix()).Filter("history_id",id).One(m) + return m,err } //清空指定文档的历史. func (m *DocumentHistory) Clear(doc_id int) error { diff --git a/static/fonts/notosans.css b/static/fonts/notosans.css new file mode 100644 index 00000000..915c9442 --- /dev/null +++ b/static/fonts/notosans.css @@ -0,0 +1,128 @@ +/* cyrillic-ext */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 400; + src: local('Noto Sans'), local('NotoSans'), url(notosans/v6/C7bP6N8yXZ-PGLzbFLtQKRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2'); + unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F; +} +/* cyrillic */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 400; + src: local('Noto Sans'), local('NotoSans'), url(notosans/v6/iLJc6PpCnnbQjYc1Jq4v0xJtnKITppOI_IvcXXDNrsc.woff2) format('woff2'); + unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; +} +/* devanagari */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 400; + src: local('Noto Sans'), local('NotoSans'), url(notosans/v6/5pCv5Yz4eMu9gmvX8nNhfRJtnKITppOI_IvcXXDNrsc.woff2) format('woff2'); + unicode-range: U+02BC, U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200B-200D, U+20A8, U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB; +} +/* greek-ext */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 400; + src: local('Noto Sans'), local('NotoSans'), url(notosans/v6/gEkd0pn-sMtQ_P4HUpi6WBJtnKITppOI_IvcXXDNrsc.woff2) format('woff2'); + unicode-range: U+1F00-1FFF; +} +/* greek */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 400; + src: local('Noto Sans'), local('NotoSans'), url(notosans/v6/iPF-u8L1qkTPHaKjvXERnxJtnKITppOI_IvcXXDNrsc.woff2) format('woff2'); + unicode-range: U+0370-03FF; +} +/* vietnamese */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 400; + src: local('Noto Sans'), local('NotoSans'), url(notosans/v6/mTzVK0-EJOCaJiOPeaz-hxJtnKITppOI_IvcXXDNrsc.woff2) format('woff2'); + unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB; +} +/* latin-ext */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 400; + src: local('Noto Sans'), local('NotoSans'), url(notosans/v6/erE3KsIWUumgD1j_Ca-V-xJtnKITppOI_IvcXXDNrsc.woff2) format('woff2'); + unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF; +} +/* latin */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 400; + src: local('Noto Sans'), local('NotoSans'), url(notosans/v6/LeFlHvsZjXu2c3ZRgBq9nFtXRa8TVwTICgirnJhmVJw.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; +} +/* cyrillic-ext */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 700; + src: local('Noto Sans Bold'), local('NotoSans-Bold'), url(notosans/v6/PIbvSEyHEdL91QLOQRnZ16-j2U0lmluP9RWlSytm3ho.woff2) format('woff2'); + unicode-range: U+0460-052F, U+20B4, U+2DE0-2DFF, U+A640-A69F; +} +/* cyrillic */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 700; + src: local('Noto Sans Bold'), local('NotoSans-Bold'), url(notosans/v6/PIbvSEyHEdL91QLOQRnZ15X5f-9o1vgP2EXwfjgl7AY.woff2) format('woff2'); + unicode-range: U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; +} +/* devanagari */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 700; + src: local('Noto Sans Bold'), local('NotoSans-Bold'), url(notosans/v6/PIbvSEyHEdL91QLOQRnZ10Tj6bCwSDA5u__Fbjwz3f0.woff2) format('woff2'); + unicode-range: U+02BC, U+0900-097F, U+1CD0-1CF6, U+1CF8-1CF9, U+200B-200D, U+20A8, U+20B9, U+25CC, U+A830-A839, U+A8E0-A8FB; +} +/* greek-ext */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 700; + src: local('Noto Sans Bold'), local('NotoSans-Bold'), url(notosans/v6/PIbvSEyHEdL91QLOQRnZ1xWV49_lSm1NYrwo-zkhivY.woff2) format('woff2'); + unicode-range: U+1F00-1FFF; +} +/* greek */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 700; + src: local('Noto Sans Bold'), local('NotoSans-Bold'), url(notosans/v6/PIbvSEyHEdL91QLOQRnZ16aRobkAwv3vxw3jMhVENGA.woff2) format('woff2'); + unicode-range: U+0370-03FF; +} +/* vietnamese */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 700; + src: local('Noto Sans Bold'), local('NotoSans-Bold'), url(notosans/v6/PIbvSEyHEdL91QLOQRnZ1_8zf_FOSsgRmwsS7Aa9k2w.woff2) format('woff2'); + unicode-range: U+0102-0103, U+1EA0-1EF9, U+20AB; +} +/* latin-ext */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 700; + src: local('Noto Sans Bold'), local('NotoSans-Bold'), url(notosans/v6/PIbvSEyHEdL91QLOQRnZ1z0LW-43aMEzIO6XUTLjad8.woff2) format('woff2'); + unicode-range: U+0100-024F, U+1E00-1EFF, U+20A0-20AB, U+20AD-20CF, U+2C60-2C7F, U+A720-A7FF; +} +/* latin */ +@font-face { + font-family: 'Noto Sans'; + font-style: normal; + font-weight: 700; + src: local('Noto Sans Bold'), local('NotoSans-Bold'), url(notosans/v6/PIbvSEyHEdL91QLOQRnZ1-gdm0LZdjqr5-oayXSOefg.woff2) format('woff2'); + unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2212, U+2215; +} \ No newline at end of file diff --git a/static/fonts/notosans/v6/5pCv5Yz4eMu9gmvX8nNhfRJtnKITppOI_IvcXXDNrsc.woff2 b/static/fonts/notosans/v6/5pCv5Yz4eMu9gmvX8nNhfRJtnKITppOI_IvcXXDNrsc.woff2 new file mode 100644 index 00000000..c9a214be Binary files /dev/null and b/static/fonts/notosans/v6/5pCv5Yz4eMu9gmvX8nNhfRJtnKITppOI_IvcXXDNrsc.woff2 differ diff --git a/static/fonts/notosans/v6/C7bP6N8yXZ-PGLzbFLtQKRJtnKITppOI_IvcXXDNrsc.woff2 b/static/fonts/notosans/v6/C7bP6N8yXZ-PGLzbFLtQKRJtnKITppOI_IvcXXDNrsc.woff2 new file mode 100644 index 00000000..715c8be3 Binary files /dev/null and b/static/fonts/notosans/v6/C7bP6N8yXZ-PGLzbFLtQKRJtnKITppOI_IvcXXDNrsc.woff2 differ diff --git a/static/fonts/notosans/v6/LeFlHvsZjXu2c3ZRgBq9nFtXRa8TVwTICgirnJhmVJw.woff2 b/static/fonts/notosans/v6/LeFlHvsZjXu2c3ZRgBq9nFtXRa8TVwTICgirnJhmVJw.woff2 new file mode 100644 index 00000000..4b3b0663 Binary files /dev/null and b/static/fonts/notosans/v6/LeFlHvsZjXu2c3ZRgBq9nFtXRa8TVwTICgirnJhmVJw.woff2 differ diff --git a/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ1-gdm0LZdjqr5-oayXSOefg.woff2 b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ1-gdm0LZdjqr5-oayXSOefg.woff2 new file mode 100644 index 00000000..72744d5c Binary files /dev/null and b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ1-gdm0LZdjqr5-oayXSOefg.woff2 differ diff --git a/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ10Tj6bCwSDA5u__Fbjwz3f0.woff2 b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ10Tj6bCwSDA5u__Fbjwz3f0.woff2 new file mode 100644 index 00000000..b48cacd8 Binary files /dev/null and b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ10Tj6bCwSDA5u__Fbjwz3f0.woff2 differ diff --git a/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ15X5f-9o1vgP2EXwfjgl7AY.woff2 b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ15X5f-9o1vgP2EXwfjgl7AY.woff2 new file mode 100644 index 00000000..54f95cbb Binary files /dev/null and b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ15X5f-9o1vgP2EXwfjgl7AY.woff2 differ diff --git a/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ16-j2U0lmluP9RWlSytm3ho.woff2 b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ16-j2U0lmluP9RWlSytm3ho.woff2 new file mode 100644 index 00000000..cb38ff18 Binary files /dev/null and b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ16-j2U0lmluP9RWlSytm3ho.woff2 differ diff --git a/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ16aRobkAwv3vxw3jMhVENGA.woff2 b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ16aRobkAwv3vxw3jMhVENGA.woff2 new file mode 100644 index 00000000..fa8b979d Binary files /dev/null and b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ16aRobkAwv3vxw3jMhVENGA.woff2 differ diff --git a/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ1_8zf_FOSsgRmwsS7Aa9k2w.woff2 b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ1_8zf_FOSsgRmwsS7Aa9k2w.woff2 new file mode 100644 index 00000000..614ff7d0 Binary files /dev/null and b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ1_8zf_FOSsgRmwsS7Aa9k2w.woff2 differ diff --git a/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ1xWV49_lSm1NYrwo-zkhivY.woff2 b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ1xWV49_lSm1NYrwo-zkhivY.woff2 new file mode 100644 index 00000000..8e7e6aaf Binary files /dev/null and b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ1xWV49_lSm1NYrwo-zkhivY.woff2 differ diff --git a/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ1z0LW-43aMEzIO6XUTLjad8.woff2 b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ1z0LW-43aMEzIO6XUTLjad8.woff2 new file mode 100644 index 00000000..63d06ff6 Binary files /dev/null and b/static/fonts/notosans/v6/PIbvSEyHEdL91QLOQRnZ1z0LW-43aMEzIO6XUTLjad8.woff2 differ diff --git a/static/fonts/notosans/v6/erE3KsIWUumgD1j_Ca-V-xJtnKITppOI_IvcXXDNrsc.woff2 b/static/fonts/notosans/v6/erE3KsIWUumgD1j_Ca-V-xJtnKITppOI_IvcXXDNrsc.woff2 new file mode 100644 index 00000000..69fd6d05 Binary files /dev/null and b/static/fonts/notosans/v6/erE3KsIWUumgD1j_Ca-V-xJtnKITppOI_IvcXXDNrsc.woff2 differ diff --git a/static/fonts/notosans/v6/gEkd0pn-sMtQ_P4HUpi6WBJtnKITppOI_IvcXXDNrsc.woff2 b/static/fonts/notosans/v6/gEkd0pn-sMtQ_P4HUpi6WBJtnKITppOI_IvcXXDNrsc.woff2 new file mode 100644 index 00000000..79a9a934 Binary files /dev/null and b/static/fonts/notosans/v6/gEkd0pn-sMtQ_P4HUpi6WBJtnKITppOI_IvcXXDNrsc.woff2 differ diff --git a/static/fonts/notosans/v6/iLJc6PpCnnbQjYc1Jq4v0xJtnKITppOI_IvcXXDNrsc.woff2 b/static/fonts/notosans/v6/iLJc6PpCnnbQjYc1Jq4v0xJtnKITppOI_IvcXXDNrsc.woff2 new file mode 100644 index 00000000..232f1950 Binary files /dev/null and b/static/fonts/notosans/v6/iLJc6PpCnnbQjYc1Jq4v0xJtnKITppOI_IvcXXDNrsc.woff2 differ diff --git a/static/fonts/notosans/v6/iPF-u8L1qkTPHaKjvXERnxJtnKITppOI_IvcXXDNrsc.woff2 b/static/fonts/notosans/v6/iPF-u8L1qkTPHaKjvXERnxJtnKITppOI_IvcXXDNrsc.woff2 new file mode 100644 index 00000000..5b32a6f0 Binary files /dev/null and b/static/fonts/notosans/v6/iPF-u8L1qkTPHaKjvXERnxJtnKITppOI_IvcXXDNrsc.woff2 differ diff --git a/static/fonts/notosans/v6/mTzVK0-EJOCaJiOPeaz-hxJtnKITppOI_IvcXXDNrsc.woff2 b/static/fonts/notosans/v6/mTzVK0-EJOCaJiOPeaz-hxJtnKITppOI_IvcXXDNrsc.woff2 new file mode 100644 index 00000000..77105736 Binary files /dev/null and b/static/fonts/notosans/v6/mTzVK0-EJOCaJiOPeaz-hxJtnKITppOI_IvcXXDNrsc.woff2 differ diff --git a/static/js/editor.js b/static/js/editor.js index b2c76c87..934f6397 100644 --- a/static/js/editor.js +++ b/static/js/editor.js @@ -232,12 +232,14 @@ function formatBytes($size) { function uploadImage($id,$callback) { /** 粘贴上传图片 **/ document.getElementById($id).addEventListener('paste', function(e) { - e.preventDefault(); + var clipboard = e.clipboardData; for (var i = 0, len = clipboard.items.length; i < len; i++) { if (clipboard.items[i].kind === 'file' || clipboard.items[i].type.indexOf('image') > -1) { + var imageFile = clipboard.items[i].getAsFile(); + console.log(imageFile) var fileName = Date.parse(new Date()); switch (imageFile.type){ @@ -277,6 +279,7 @@ function uploadImage($id,$callback) { } }); + e.preventDefault(); } } }); diff --git a/static/mergely/editor/editor.js b/static/mergely/editor/editor.js index b2ffc147..ab9ab4d1 100644 --- a/static/mergely/editor/editor.js +++ b/static/mergely/editor/editor.js @@ -97,17 +97,20 @@ $(document).ready(function() { height: 'auto', cmsettings: { lineNumbers: true, - readOnly: isSample + readOnly: false } }); - if (parameters.get('lhs', null)) { - var url = parameters.get('lhs'); - crossdomainGET(ed, 'lhs', url); - } - if (parameters.get('rhs', null)) { - var url = parameters.get('rhs'); - crossdomainGET(ed, 'rhs', url); - } + + ed.mergely("lhs", $("#historyContent").html()); + ed.mergely("rhs", $("#documentContent").html()); + // if (parameters.get('lhs', null)) { + // var url = parameters.get('lhs'); + // crossdomainGET(ed, 'lhs', url); + // } + // if (parameters.get('rhs', null)) { + // var url = parameters.get('rhs'); + // crossdomainGET(ed, 'rhs', url); + // } // set query string options var urloptions = {}; @@ -161,7 +164,7 @@ $(document).ready(function() { }); // Load - if (key.length == 8) { + if (key.length === 8) { $.when( $.ajax({ type: 'GET', async: true, dataType: 'text', @@ -301,29 +304,22 @@ $(document).ready(function() { if (id == 'file-new') { window.location = '/editor'; } - else if (id == 'file-save') { - // download directly from browser - var text = ed.mergely('diff'); - if (navigator.userAgent.toLowerCase().indexOf('msie') === -1) { - if (key == '') key = ''.random(8); - var link = jQuery('', { - href: 'data:application/stream;base64,' + window.btoa(unescape(encodeURIComponent(text))), - target: '_blank', - text: 'clickme', - id: key - }); - link.attr('download', key + '.diff'); - jQuery('body').append(link); - var a = $('a#' + key); - a[0].click(); - a.remove(); + else if (id === 'file-save') { + var rhs = ed.mergely('get', 'rhs'); + + if(window.top.hasOwnProperty("editor")){ + if(window.top.editor.hasOwnProperty("$txt")){ + window.top.editor.$txt.html(rhs); + }else{ + + window.top.editor.clear(); + window.top.editor.insertValue(rhs); + } + + window.top.layer.closeAll(); } - else { - var blob = new Blob([text]); - window.navigator.msSaveOrOpenBlob(blob, key + '.diff'); - } - } - else if (id == 'file-share') { + + }else if (id == 'file-share') { handleShare(ed); } else if (id == 'file-import') { diff --git a/static/mergely/editor/editor.min.js b/static/mergely/editor/editor.min.js index fcd83df8..e8086fc2 100644 --- a/static/mergely/editor/editor.min.js +++ b/static/mergely/editor/editor.min.js @@ -1,6 +1 @@ -/** - * Copyright (c) 2016 by Jamie Peabody, http://www.mergely.com - * All rights reserved. - * Version: 3.4.3 2016-09-07 - */ -$(document).ready(function(){function a(){var a={};return window.location.search.substr(1).split("&").forEach(function(b){if(""!==b){var c=b.split("=");2===c.length&&c[1].search(/^(true|1)$/i)>=0?a[c[0]]=!0:2===c.length&&c[1].search(/^(false|0)$/i)>=0?a[c[0]]=!1:a[c[0]]=c[1]&&decodeURIComponent(c[1].replace(/\+/g," "))}}),{get:function(b,c){return a.hasOwnProperty(b)?a[b]:c}}}function f(a){if(!a.length)return!1;var b=$("#mergely"),c=a.find(".find"),d=c.find('input[type="text"]'),e=a.attr("id").indexOf("-lhs")>0?"lhs":"rhs",f=b.mergely("options").autoupdate;c.slideDown("fast",function(){d.focus(),b.mergely("options",{autoupdate:!1}),b.mergely("unmarkup")}),c.find(".find-prev").click(function(){b.mergely("search",e,d.val(),"prev")}),c.find(".find-next").click(function(){b.mergely("search",e,d.val(),"next")}),c.find(".find-close").click(function(){c.css("display","none"),b.mergely("options",{autoupdate:f})}),d.keydown(function(a){return 13!=a.which&&27!=a.which?!0:(27==a.which&&(c.css("display","none"),b.mergely("options",{autoupdate:f})),b.mergely("search",e,d.val()),!1)})}function u(a){if("file-new"==a)window.location="/editor";else if("file-save"==a){var b=g.mergely("diff");if(-1===navigator.userAgent.toLowerCase().indexOf("msie")){""==key&&(key="".random(8));var c=jQuery("",{href:"data:application/stream;base64,"+window.btoa(unescape(encodeURIComponent(b))),target:"_blank",text:"clickme",id:key});c.attr("download",key+".diff"),jQuery("body").append(c);var d=$("a#"+key);d[0].click(),d.remove()}else{var e=new Blob([b]);window.navigator.msSaveOrOpenBlob(e,key+".diff")}}else if("file-share"==a)v(g);else if("file-import"==a)x(g);else if("edit-left-undo"==a)g.mergely("cm","lhs").getDoc().undo();else if("edit-left-redo"==a)g.mergely("cm","lhs").getDoc().redo();else if("edit-right-undo"==a)g.mergely("cm","rhs").getDoc().undo();else if("edit-right-redo"==a)g.mergely("cm","rhs").getDoc().redo();else if("edit-left-find"==a)f(g.find("#mergely-editor-lhs"));else if("edit-left-merge-right"==a)g.mergely("mergeCurrentChange","rhs");else if("edit-left-merge-right-file"==a)g.mergely("merge","rhs");else if(["edit-left-readonly","edit-right-readonly","options-autodiff","options-sidebars","options-swapmargin","options-viewport","options-ignorews","options-wrap","options-linenumbers"].indexOf(a)>=0)s[a].set(!s[a].get()),h.wickedmenu("update",a);else if("edit-left-clear"==a)g.mergely("clear","lhs");else if("edit-right-find"==a)f(g.find("#mergely-editor-rhs"));else if("edit-right-merge-left"==a)g.mergely("mergeCurrentChange","lhs");else if("edit-right-merge-left-file"==a)g.mergely("merge","lhs");else if("edit-right-clear"==a)g.mergely("clear","rhs");else if("options-colors"==a)y(g);else if("view-swap"==a)g.mergely("swap");else if("view-refresh"==a)g.mergely("update");else if("view-change-next"==a)g.mergely("scrollToDiff","next");else if("view-change-prev"==a)g.mergely("scrollToDiff","prev");else if("view-clear"==a)g.mergely("unmarkup");else if(0==a.indexOf("examples-")){var i={test1:{lhs:"one\ntwo\nthree",rhs:"two\nthree"},test2:{lhs:"two\nthree",rhs:"one\ntwo\nthree"},test3:{lhs:"one\nthree",rhs:"one\ntwo\nthree"},test4:{lhs:"one\ntwo\nthree",rhs:"one\nthree"},test5:{lhs:"to bee, or not to be",rhs:"to be, or not to bee"},test6:{lhs:"to be, or not to be z",rhs:"to be, to be"},test7:{lhs:"remained, & to assume",rhs:"and to assume"},test8:{lhs:"to be, or not to be",rhs:"to be, or not to be"}},j=a.split("examples-")[1];g.mergely("lhs",i[j].lhs),g.mergely("rhs",i[j].rhs)}return!1}function v(a){function d(a,d){$.ajax({type:"POST",async:!0,dataType:"text",url:"/ajax/handle_file.php",data:{key:key,name:a,content:d},success:function(a){if(++c,2==c){var d="/ajax/handle_save.php?key="+key;b&&(d+="&nkey="+"".random(8)),$.ajax({type:"GET",async:!1,dataType:"text",url:d,success:function(a){a.length&&(window.location.href="/"+$.trim(a)+"/")},error:function(a,b,c){}})}},error:function(a,b,c){alert(c)}})}function e(){var b=a.mergely("get","lhs"),c=a.mergely("get","rhs");d("lhs",b),d("rhs",c)}var b="fork"==$(this).attr("id");""==key&&(key="".random(8));var c=0;$("#dialog-confirm").dialog({resizable:!1,width:350,modal:!0,buttons:{"Save for Sharing":function(){$(this).dialog("close"),e()},Cancel:function(){$(this).dialog("close")}}})}function w(a,b,c){$.ajax({type:"GET",dataType:"text",data:{url:c},url:"/ajax/handle_crossdomain.php",contentType:"text/plain",success:function(c){a.mergely(b,c)},error:function(a,b,c){console.error("error",a,b,c)}})}function x(a){function b(a,b){function f(a,b){e.trigger(a,b)}var c=a.files[0],d=new FileReader,e=$(a);d.onloadstart=function(a){f("start")},d.onprogress=function(a){f("progress",a)},d.onload=function(a){f("loaded",a.target.result)},d.onerror=function(a){alert(a.target.error.name)};try{d.readAsText(c,"UTF-8")}catch(g){console.error(g),alert(g)}}var c={};$("#file-lhs, #file-rhs").change(function(a){var d=new RegExp(".*[\\\\/](.*)$"),e=d.exec($(this).val()),f=e?e[1]:"unknown",g=$("#"+a.target.id+"-progress");b(a.target),$(a.target).bind("start",function(b){$(a.target).css("display","none"),g.css("display","inline-block")}),$(a.target).bind("progress",function(a,b){var c=b.loaded/b.total*100;g.find("> .progress-label").text(c+"%"),g.progressbar("value",c)}),$(a.target).bind("loaded",function(b,d){g.progressbar("value",100),g.find("> .progress-label").text(f),c[a.target.id]=d})}),$("#file-lhs-progress").progressbar({value:0}),$("#file-rhs-progress").progressbar({value:0}),$("#dialog-upload .tabs").tabs(),$("#dialog-upload").dialog({dialogClass:"no-title",resizable:!1,width:"450px",modal:!0,buttons:{Import:function(){$(this).dialog("close");var b={lhs:$("#url-lhs").val(),rhs:$("#url-rhs").val()};for(var d in b){var e=b[d];e&&w(a,d,e)}c.hasOwnProperty("file-lhs")&&a.mergely("lhs",c["file-lhs"]),c.hasOwnProperty("file-rhs")&&a.mergely("rhs",c["file-rhs"])},Cancel:function(){$(this).dialog("close")}}})}function y(a){var b=$(''),c=$(''),d=$('');$("body").append(b),$("body").append(c),$("body").append(d);var e={"c-border":{id:"#c-border",getColor:function(){return d.css("border-top-color")},setColor:function(a){$("#"+this.id).val(a)}},"c-bg":{id:"#c-bg",getColor:function(){return d.css("background-color")},setColor:function(a){$("#"+this.id).val(a)}},"a-border":{id:"#a-border",getColor:function(){return c.css("border-top-color")},setColor:function(a){$("#"+this.id).val(a)}},"a-bg":{id:"#a-bg",getColor:function(){return c.css("background-color")},setColor:function(a){$("#"+this.id).val(a)}},"d-border":{id:"#d-border",getColor:function(){return b.css("border-top-color")},setColor:function(a){$("#"+this.id).val(a)}},"d-bg":{id:"#d-bg",getColor:function(){return b.css("background-color")},setColor:function(a){$("#"+this.id).val(a)}}};$.each(e,function(a,b){$(b.id).val(b.getColor())});var f=$.farbtastic("#picker");$(".colorwell").each(function(){f.linkTo(this)}).focus(function(){var a=$(this);f.linkTo(this);var b=e[a.attr("id")];f.setColor(b.getColor())}),$("#dialog-colors").dialog({width:490,modal:!0,buttons:{Apply:function(){var a=$("#c-border").val(),b=$("#a-border").val(),c=$("#d-border").val(),d=$("#a-bg").val(),e=$("#d-bg").val(),f=$("#c-bg").val(),g=z(a,f,b,d,c,e);B(g,a,f,b,d,c,e,!0)},Reset:function(){},Close:function(){$(this).dialog("close")}}})}function z(a,b,c,d,e,f){var g=".mergely.a.rhs.start{border-top-color:"+c+";}\n .mergely.a.lhs.start.end,\n .mergely.a.rhs.end{border-bottom-color:"+c+";}\n .mergely.a.rhs{background-color:"+d+";}\n .mergely.d.lhs{background-color:"+f+";}\n .mergely.d.lhs.end,\n .mergely.d.rhs.start.end{border-bottom-color:"+e+";}\n .mergely.d.rhs.start.end.first{border-top-color:"+e+";}\n .mergely.d.lhs.start{border-top-color:"+e+";}\n .mergely.c.lhs,\n .mergely.c.rhs{background-color:"+b+";}\n .mergely.c.lhs.start,\n .mergely.c.rhs.start{border-top-color:"+a+";}\n .mergely.c.lhs.end,\n .mergely.c.rhs.end{border-bottom-color:"+a+";}\n .mergely.ch.a.rhs{background-color:"+d+";}\n .mergely.ch.d.lhs{background-color:"+f+";color: #888;}";return g}function A(a){var c="#"+b.get("cb",o.cb),d="#"+b.get("cg",o.cg),e="#"+b.get("ab",o.ab),f="#"+b.get("ag",o.ag),g="#"+b.get("db",o.db),h="#"+b.get("dg",o.dg);B(z(c,d,e,f,g,h),c,d,e,f,g,h,a)}function B(a,b,c,d,e,f,h,i){$('").appendTo("head"),g.mergely("options",{fgcolor:{a:d,c:b,d:f}});var j=D("cb",b.replace(/#/g,""),o.cb);j=D("cg",c.replace(/#/g,""),o.cg,j),j=D("ab",d.replace(/#/g,""),o.ab,j),j=D("ag",e.replace(/#/g,""),o.ag,j),j=D("db",f.replace(/#/g,""),o.db,j),j=D("dg",h.replace(/#/g,""),o.dg,j),i&&C(j)}function C(a){var b=[location.protocol,"//",location.host,location.pathname].join("");window.history.pushState({},null,b+a)}function D(a,b,c,d){d=d||document.location.search;var e=d.replace(/^\?/,"").split(/&/),f=!1;for(var g in e){if(e[g].startsWith(a+"=")){f=!0,b===c?e.splice(g,1):e[g]=a+"="+b;break}if(0===e[g].length){e.splice(g,1);break}}return f||e.push(a+"="+b),e.length?"?"+e.join("&"):""}var b=a();if(b.get("test",!1)){for(var c=$("
  • Tests
  • "),d=$("