-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
VersionControl.min.js
1 lines (1 loc) · 6.14 KB
/
VersionControl.min.js
1
$(function(){var i=config.VersionControl,e={};$.get(i.processPage+"page",{pages_id:i.pageID,settings:{empty:!0,render:"HTML"}},function(t){$("body").prepend(t),$("#text-field-history > div").each(function(){if($(this).data("revision")){var i=$(".Inputfield_"+$(this).data("field"));if(i.find("> label").addClass("with-history").before($(this)),$(this).find("a:first").addClass("ui-state-active"),i.hasClass("InputfieldTinyMCE")||i.hasClass("InputfieldCKEditor"))return;e[$(this).data("field")+"."+$(this).data("revision")]=i.find("div.ui-widget-content, .InputfieldContent").clone(!0,!0)}}),$(".ui-widget-header.with-history, .InputfieldHeader.with-history").each(function(){var i="field-revisions-toggle",e="";$(this).siblings(".field-revisions").find("li").length<1&&(i+=" inactive",e=" title='"+$(this).siblings(".field-revisions").text()+"'");var t="<a "+e+'class="'+i+'"><i class="fa fa-clock-o"></i></a>';$(this).find(".toggle-icon").length?$(this).find(".toggle-icon").after(t):$(this).append(t)}),$(".field-revisions").on("click","> ul > li > a",function(){if($(this).hasClass("ui-state-active"))return!1;var t={render:"Input"},s=$(this),a=s.parents(".Inputfield:first"),r=s.parents(".field-revisions:first").data("field");a.find(".field-revisions .ui-state-active").removeClass("ui-state-active"),s.addClass("ui-state-active"),$(".compare-revisions").remove();var f=a.find("div.ui-widget-content, .InputfieldContent"),d=$('<span class="field-revisions-loading"></span>').hide().css({height:f.innerHeight()+"px",backgroundColor:f.css("background-color")});(a.hasClass("InputfieldTinyMCE")||a.hasClass("InputfieldCKEditor"))&&(t={render:"JSON"});var l=$(this).data("revision");if(e[r+"."+l])if("JSON"!=t.render&&l==s.parents(".field-revisions:first").data("revision")){if(f.replaceWith(e[r+"."+l].clone(!0,!0)),a.find(".InputfieldFileList").length&&$.getScript(config.urls.modules+"Inputfield/InputfieldFile/InputfieldFile.js"),a.hasClass("InputfieldImage")&&(a.find(".InputfieldImageListToggle").remove(),$.getScript(config.urls.modules+"Inputfield/InputfieldImage/InputfieldImage.js")),a.find(".InputfieldAsmSelect").length){var o=a.find("select[multiple=multiple]"),c="undefined"==typeof config?{sortable:!0}:config[o.attr("id")];o.appendTo(a.find(".InputfieldAsmSelect")).show(),a.find(".asmContainer").remove(),o.asmSelect(c)}}else n(a,f,t,r,e[r+"."+l]);else f.css("position","relative").prepend(d.fadeIn(250)),$.get(i.processPage+"field",{revision:s.data("revision"),field:r,settings:t},function(i){e[r+"."+l]=i,n(a,f,t,r,e[r+"."+l]),d.fadeOut(350,function(){$(this).remove()})});return!1});var n=function(e,t,n,s,a){if("Input"==n.render){var r=t.children("p.description:first"),f=t.children("p.notes:first");if(t.html(a).prepend(r).append(f),e.hasClass("InputfieldImage")||e.hasClass("InputfieldFile")?(e.removeClass("InputfieldImageGrid"),t.prepend('<div class="version-control-overlay"></div>'),$(".version-control-overlay").attr("title",i.i18n.editDisabled).on("click",function(){alert($(this).attr("title"))}).hover(function(){$(this).parent(".overlay-parent").addClass("hover")},function(){$(this).parent(".overlay-parent").removeClass("hover")}).parent(".InputfieldContent").addClass("overlay-parent")):e.hasClass("Inputfield_permissions")&&($(".Inputfield_permissions .Inputfield_permissions > .InputfieldContent").insertAfter($(".Inputfield_permissions:first > .InputfieldContent:first")),$(".Inputfield_permissions:first > .InputfieldContent:first").remove()),e.find(".InputfieldAsmSelect").length){var d=e.find("select[multiple=multiple]"),l="undefined"==typeof config?{sortable:!0}:config[d.attr("id")];d.asmSelect(l)}}else $.each(a,function(i,t){var n=i.replace("data","");n&&(n="__"+n),"undefined"!=typeof tinyMCE&&tinyMCE.get("Inputfield_"+s+n)?tinyMCE.get("Inputfield_"+s+n).setContent(t):e.find(".InputfieldCKEditorInline").length?e.find(".InputfieldCKEditorInline").html(t):"undefined"!=typeof CKEDITOR&&CKEDITOR.instances["Inputfield_"+s+n]&&CKEDITOR.instances["Inputfield_"+s+n].setData(t)})};$(".field-revisions-toggle").on("click mouseenter",function(){if($(this).hasClass("inactive"))return!1;var i=$(this).parent("label").siblings(".field-revisions"),e=!i.is(":visible");return $(".field-revisions").slideUp(),e&&i.slideDown(),!1});var s;$(".field-revisions").on("mouseenter",function(){$(this).slideDown(),s&&(clearTimeout(s),s=!1)}).on("mouseleave",function(){var i=$(this);s=setTimeout(function(){s=!1,i.slideUp(function(){$(".compare-revisions").remove()})},500)}),$(".field-revisions > ul").each(function(){var i=$(this)[0];$(this).parent().show(),i.clientHeight<i.scrollHeight&&$(this).addClass("scroll"),$(this).parent().hide()});var a=function(){var e=new diff_match_patch,t=document.getElementById("r1").value,n=document.getElementById("r2").value;e.Diff_Timeout=i.diff.timeout,e.Diff_EditCost=i.diff.editCost;var s=((new Date).getTime(),e.diff_main(t,n));(new Date).getTime(),i.diff.cleanup&&e["diff_cleanup"+i.diff.cleanup](s);var a=e.diff_prettyHtml(s);document.getElementById("diff").innerHTML=a};$(".field-revisions.diff").on("hover","> ul > li > a",function(){if($(".compare-revisions").remove(),!$(this).hasClass("ui-state-active")){var e=$(this).parents(".field-revisions:first").data("field"),t=$(this).parents(".field-revisions:first").find(".ui-state-active").data("revision"),n=$(this).data("revision"),s=i.processPage+"diff/?revisions="+t+":"+n+"&field="+e,a=i.i18n.compareWithCurrent;$(this).before('<div class="compare-revisions"><a class="diff-trigger" href="'+s+'">'+a+"</a></div>")}}).on("click",".compare-revisions > a.diff-trigger",function(){var e=$(this).parent(),t=$('<span class="field-revisions-loading"></span>').hide().css({height:e.innerHeight()+"px",backgroundColor:e.css("background-color")});return e.prepend(t.fadeIn(250)).load($(this).attr("href"),function(){$(this).find("a.diff-trigger").remove(),e.find("ul.page-diff").length?"function"!=typeof enableDiffSwitch?$.getScript(i.moduleDir+"diff_switch.min.js",function(){enableDiffSwitch(i)}):enableDiffSwitch(i):"function"!=typeof diff_match_patch?$.getScript(i.moduleDir+"diff_match_patch_20121119/javascript/diff_match_patch.js",function(){a()}):a(),$(this).animate({width:"400px",padding:"14px"}),t.fadeOut(350,function(){$(this).remove()})}),!1})})});