openrat-cms

# OpenRat Content Management System
git clone http://git.code.weiherhei.de/openrat-cms.git
Log | Files | Refs

openrat.min.js (15227B)


      1 ;var OR_THEMES_EXT_DIR='modules/cms-ui/themes/';$(function(){$('html').removeClass('nojs');$('.initial-hidden').removeClass('initial-hidden');registerWorkbenchEvents();window.onpopstate=function(e){Navigator.navigateTo(e.state)};initActualHistoryState();Workbench.initialize();Workbench.reloadAll();registerNavigation();$('.keystroke').each(function(){let keystrokeElement=$(this);let keystroke=keystrokeElement.text();if(keystroke.length==0)return;let keyaction=function(){keystrokeElement.click()};$(document).bind('keydown',keystroke,keyaction)});$('#noticebar .notice .image-icon--menu-close').click(function(){$(this).closest('.notice').fadeOut('fast',function(){$(this).remove()})});$('#noticebar .notice').each(function(){let noticeToClose=this;setTimeout(function(){$(noticeToClose).fadeOut('slow',function(){$(this).remove()})},30*1000)});registerOpenClose($('section.toggle-open-close'));$('section.toggle-open-close .on-click-open-close').click(function(){var t=$(this).closest('section');if(t.hasClass('disabled'))return;var e=t.find('div.view-loader');if(e.children().length==0)Workbench.loadNewActionIntoElement(e)})});function initActualHistoryState(){var t={};t.name=window.document.title;var e=new URLSearchParams(window.location.search);if(e.has('action')){t.action=e.get('action');t.id=e.get('id');t.name=window.document.title;t.data={};var e=Array.from(e.entries());for(var i in e){t.data[e[i][0]]=e[i][1]};Navigator.toActualHistory(t)}};function registerNavigation(){$(document).on('orNewAction',function(e,t){let url='./api/?action=tree&subaction=path&id='+Workbench.state.id+'&type='+Workbench.state.action+'&output=json';$.getJSON(url,function(e){$('nav .or-navtree-node').removeClass('or-navtree-node--selected');let output=e['output'];$.each(output.path,function(e,t){$nav=$('nav .or-navtree-node[data-type='+t.type+'][data-id='+t.id+'].or-navtree-node--is-closed .or-navtree-node-control');$nav.click()});if(output.actual)$('nav .or-navtree-node[data-type='+output.actual.type+'][data-id='+output.actual.id+']').addClass('or-navtree-node--selected')}).fail(function(e){console.warn(e);console.warn('failed to load path from '+url)}).always(function(){})})};var Navigator=new function(){'use strict';this.navigateTo=function(e){Workbench.loadNewActionState(e)};this.navigateToNew=function(e){Workbench.loadNewActionState(e);window.history.pushState(e,e.name,'./#/'+e.action+(e.id?'/'+e.id:''))};this.navigateToNewAction=function(e,t,i,n){var o={action:e,method:t,id:Number(i),data:n};this.navigateToNew(o)};this.toActualHistory=function(e){window.history.replaceState(e,e.name,createUrl(e.action,null,e.id,e.data,!1))}},Workbench=new function(){'use strict';this.initialize=function(){this.initializePingTimer();this.initializeState();this.initializeMenues();this.openModalDialog()};this.openModalDialog=function(){if($('#dialog').data('action')){startDialog('',$('#dialog').data('action'),$('#dialog').data('action'),0,{})}};this.initializeMenues=function(){filterMenus()};this.initializeState=function(){let parts=window.location.hash.split('/');let state={action:'index',id:0};if(parts.length>=2)state.action=parts[1].toLowerCase();if(parts.length>=3)state.id=Number(parts[2]);Workbench.state=state;$('#editor').attr('data-action',state.action);$('#editor').attr('data-id',state.id);$('#editor').attr('data-extra','{}')};this.initializePingTimer=function(){var e=function(){$.ajax(createUrl('title','ping',0))},t=5;window.setInterval(e,t*60*1000)};this.loadNewActionState=function(e){Workbench.state=e;Workbench.loadNewAction(e.action,e.id,e.data);filterMenus();$(document).trigger('orNewAction')};this.loadNewAction=function(e,t,i){$('#editor').attr('data-action',e);$('#editor').attr('data-id',t);$('#editor').attr('data-extra',JSON.stringify(i));this.reloadViews()};this.reloadViews=function(){$('#workbench section.closed .view-loader').empty();Workbench.loadViews($('#workbench section.open .view-loader'))};this.reloadAll=function(){$('#workbench .view').empty();Workbench.loadViews($('#workbench .view'))};this.loadViews=function(e){e.each(function(e){let $targetDOMElement=$(this);Workbench.loadNewActionIntoElement($targetDOMElement)})};this.loadNewActionIntoElement=function(e){let action;if(e.is('.view-static'))action=e.attr('data-action');else action=$('#editor').attr('data-action');let id=$('#editor').attr('data-id');let params=$('#editor').attr('data-extra');let method=e.data('method');let view=new View(action,method,id,params);view.start(e)}};function registerWorkbenchEvents(){$('div.header').dblclick(function(){fullscreen(this)})};function loadView(e,t,i,n,o){Navigator.navigateToNewAction(t,i,n,o)};function afterViewLoaded(e){var t=$(e).closest('section');t.toggleClass('is-empty',$(e).is(':empty'));$(e).trigger('orViewLoaded');$(e).closest('div.panel').find('div.header div.dropdown div.entry.perview').remove();$(e).find('.toggle-nav-open-close').click(function(){$('nav').toggleClass('open')});$(e).find('.toggle-nav-small').click(function(){$('nav').toggleClass('small')});$(e).find('div.headermenu > a').each(function(e,t){});$(e).find('div.header > a.back').each(function(t,i){$(i).removeClass('button').wrap('<div class="entry perview" />').parent().appendTo($(e).closest('div.panel').find('div.header div.dropdown').first())});$(e).find('div.selector.tree').each(function(){var e=this;$(this).orTree({type:'project',selectable:$(e).attr('data-types').split(','),id:$(e).attr('data-init-folderid'),onSelect:function(t,i,n){var o=$(e).parent();$(o).find('input[type=text]').attr('value',t);$(o).find('input[type=hidden]').attr('value',n)}})});registerDragAndDrop(e);$(e).find('input').change(function(){$(this).parent('div.view').addClass('dirty')});$(e).find('.or-theme-chooser').change(function(){setUserStyle(this.value)})};function registerDragAndDrop(e){registerDraggable(e);registerDroppable(e)};function registerDraggable(e){$(e).find('.or-draggable').draggable({helper:'clone',opacity:0.7,zIndex:2,distance:10,cursor:'move',revert:'false'})};function registerTreeBranchEvents(e){registerDraggable(e)};function registerDroppable(e){$(e).find('.or-droppable').droppable({accept:'.or-draggable',hoverClass:'or-droppable--hover',activeClass:'or-droppable--active',drop:function(e,t){let dropped=t.draggable;$(this).find('.or-selector-link-value').val(dropped.data('id'));$(this).find('.or-selector-link-name').val(dropped.data('id'))}})};function registerMenuEvents(e){$('body').click(function(){$('.toolbar-icon.menu').parents('.or-menu').removeClass('open')});$(e).find('.toolbar-icon.menu').click(function(e){e.stopPropagation();$(this).parents('.or-menu').toggleClass('open')});$(e).find('.toolbar-icon.menu').mouseover(function(){$(this).parents('.or-menu').find('.toolbar-icon.menu').removeClass('open');$(this).addClass('open')})};function registerSearch(e){$(e).find('.search input').orSearch({dropdown:'#title div.search div.dropdown'})};function registerTree(e){$(e).find('.or-navtree-node').orTree()};function fullscreen(e){$(e).closest('div.panel').fadeOut('fast',function(){$(this).toggleClass('fullscreen').fadeIn('fast')})};function submitUrl(e,t){postUrl(t,e)};function postUrl(e,t){e+='&output=json';$.ajax({'type':'POST',url:e,data:{},success:function(e,i,n){$('div.panel div.status div.loader').html('&nbsp;');doResponse(e,i,t)}})};function Form(){this.setLoadStatus=function(e){$(this.element).closest('div.content').toggleClass('loader',e)};this.initOnElement=function(e){this.element=e;let form=this;$(e).find('form[data-autosave="true"] input[type="checkbox"]').click(function(){form.submit()});$(e).find('.or-form-btn--cancel').click(function(){form.cancel()});$(e).find('.or-form-btn--reset').click(function(){form.rollback()});$(e).submit(function(e){if($(this).data('target')=='view'){form.submit();e.preventDefault()}})};this.cancel=function(){this.close()};this.rollback=function(){this.element.trigger('reset')};this.close=function(){};this.submit=function(){let status=$('<div class="notice info"><div class="text loader"></div></div>');$('#noticebar').prepend(status);$(status).show();$(this.element).find('.error').removeClass('error');var t=$(this.element).serializeArray(),e={};$(t).each(function(t,i){e[i.name]=i.value});if(!e.id)e.id=Workbench.state.id;if(!e.action)e.action=Workbench.state.action;let formMethod=$(this.element).attr('method').toUpperCase();if(formMethod=='GET'){this.forwardTo(e.action,e.subaction,e.id,e)}
      2 else{let url='./api/';this.setLoadStatus(!0);url+='';e.output='json';if($(this.element).data('async')||$(this.element).data('async')=='true'){this.close()};let form=this;$.ajax({'type':'POST',url:url,data:e,success:function(e,t,i){form.setLoadStatus(!1);$(status).remove();doResponse(e,t,form.element)},error:function(e,t,i){form.setLoadStatus(!1);$(status).remove();try{let error=jQuery.parseJSON(e.responseText);notify('','','error',error.error,[error.description])}catch(n){let msg=e.responseText;notify('','','error','Server Error',[msg])}}});$(form.element).fadeIn()}}};function View(e,t,i,n){this.action=e;this.method=t;this.id=i;this.params=n;this.before=function(){};this.start=function(e){this.before();this.element=e;this.loadView()};this.afterLoad=function(){};this.close=function(){};function o(e){registerMenuEvents(e);registerSearch(e);registerTree(e);afterViewLoaded(e)};this.loadView=function(){let url=createUrl(this.action,this.method,this.id,this.params,!0);let element=this.element;let view=this;$(this.element).empty().fadeTo(1,0.7).addClass('loader').html('').load(url,function(e,t,i){$(element).fadeTo(350,1);$(element).removeClass('loader');$(element).find('form').each(function(){let form=new Form();form.close=function(){view.close()};form.initOnElement(this)});if(t=='error'){$(element).html('');notify('','','error','Server Error',['Server Error while requesting url '+url,e]);return};o(element)})}};function startDialog(e,t,i,n,o){if(!t)t=$('#editor').attr('data-action');if(!n)n=$('#editor').attr('data-id');let view=new View(t,i,n,o);view.before=function(){$('#dialog > .view').html('<div class="header"><img class="icon" title="" src="./themes/default/images/icon/'+i+'.png" />'+e+'</div>');$('#dialog > .view').data('id',n);$('#dialog').removeClass('is-closed').addClass('is-open');let view=this;this.escapeKeyClosingHandler=function(e){if(e.keyCode==27){view.close();$(document).off('keyup')}};$(document).keyup(this.escapeKeyClosingHandler);$('#dialog .filler').click(function(){view.close()})};view.close=function(){if($('div#dialog').hasClass('modal'))return;$('#dialog .view').fadeOut('fast').html('');$('#dialog').removeClass('is-open').addClass('is-closed');$(document).unbind('keyup',this.escapeKeyClosingHandler)};view.start($('div#dialog > .view'))};function startEdit(e,t,i,n,o){if(!t)t=Workbench.state.action;if(!n)n=Workbench.state.id;let view=new View(t,i,n,o);view.before=function(){let view=this;$edit=$('#edit');$edit.addClass('is-open');$('#editor').addClass('is-closed');$('#edit .filler').click(function(){view.close()})};view.close=function(){$edit.removeClass('is-open');$('#editor').removeClass('is-closed')};view.start($('#edit > .view'))};function setTitle(e){if(e)$('head > title').text(e+' - '+$('head > title').data('default'));else $('head > title').text($('head > title').data('default'))};function openNewAction(e,t,i,n){$('nav').removeClass('open');setTitle(e);setNewAction(t,i,n)};function filterMenus(){let action=Workbench.state.action;let id=Workbench.state.id;$('div.clickable').addClass('active');$('div.clickable.filtered').removeClass('active').addClass('inactive');$('div.clickable.filtered.on-action-'+action).addClass('active').removeClass('inactive');$('div.clickable.filtered a').attr('data-id',id)};function setNewAction(e,t,i){Navigator.navigateToNewAction(e,'edit',t,i)};function setNewId(e){};function notifyBrowser(e){if(!('Notification' in window)){return}
      3 else if(Notification.permission==='granted'){let notification=new Notification(e)}
      4 else if(Notification.permission!=='denied'){Notification.requestPermission(function(t){if(t==='granted'){let notification=new Notification(e)}})}};function setUserStyle(e){var t=$('html'),i=t.attr('class').split(/\s+/);$.each(i,function(e,i){if(i.startsWith('theme-')){t.removeClass(i)}});t.addClass('theme-'+e.toLowerCase())};function insert(e,t,i){var n=document.forms[0].elements[e];n.focus();if(typeof document.selection!='undefined'){var r=document.selection.createRange(),o=r.text;r.text=t+o+i;r=document.selection.createRange();if(o.length==0){r.move('character',-i.length)}
      5 else{r.moveStart('character',t.length+o.length+i.length)};r.select()}
      6 else if(typeof n.selectionStart!='undefined'){var s=n.selectionStart,l=n.selectionEnd,o=n.value.substring(s,l);n.value=n.value.substr(0,s)+t+o+i+n.value.substr(l);var a;if(o.length==0){a=s+t.length}
      7 else{a=s+t.length+o.length+i.length};n.selectionStart=a;n.selectionEnd=a}
      8 else{a=n.value.length;var o=prompt('Text');n.value=n.value.substr(0,a)+t+o+i+n.value.substr(a)}};function createUrl(e,t,i,n,a){var o='./';o+='?';if(e)o+='&action='+e;if(t)o+='&subaction='+t;if(i)o+='&id='+i;if(typeof n==='string'){n=n.replace(/'/g,'"');var r=jQuery.parseJSON(n);jQuery.each(r,function(e,t){o=o+'&'+e+'='+t})}
      9 else if(typeof n==='object'){jQuery.each(n,function(e,t){o=o+'&'+e+'='+t})}
     10 else{};return o};function resizeWorkbenchContainer(e){};function resizeWorkbench(){};function resizeTabs(e){};function help(e,t,i){var n=$(e).closest('div.panel').find('li.action.active').attr('data-action'),o=$(e).closest('div.panel').find('li.action.active').attr('data-method');window.open(t+n+'/'+o+i,'OpenRat_Help','location=no,menubar=no,scrollbars=yes,toolbar=no,resizable=yes')};function notify(e,t,i,n,log=[]){let notice=$('<div class="notice '+i+'"></div>');let toolbar=$('<div class="or-notice-toolbar"></div>');if(log.length)$(toolbar).append('<i class="or-action-full image-icon image-icon--menu-fullscreen"></i>');$(toolbar).append('<i class="or-action-close image-icon image-icon--menu-close"></i>');$(notice).append(toolbar);id=0;if(t)$(notice).append('<div class="name clickable"><a href="" data-type="open" data-action="'+e+'" data-id="'+id+'"><i class="or-action-full image-icon image-icon--action-'+e+'"></i> '+t+'</a></div>');$(notice).append('<div class="text">'+htmlEntities(n)+'</div>');if(log.length){let logLi=log.reduce((result,item)=>{result+='<li><pre>'+htmlEntities(item)+'</pre></li>';return result},'');$(notice).append('<div class="log"><ul>'+logLi+'</ul></div>')};$('#noticebar').prepend(notice);$(notice).orLinkify();$(notice).find('.or-action-full').click(function(){$(notice).toggleClass('full')});$(notice).find('.or-action-close').click(function(){$(notice).fadeOut('fast',function(){$(notice).remove()})});let timeout=1;if(i=='ok')timeout=20;if(i=='info')timeout=60;if(i=='warning')timeout=120;if(i=='error')timeout=120;if(timeout>0)setTimeout(function(){$(notice).fadeOut('slow',function(){$(this).remove()})},timeout*1000)};function htmlEntities(e){return String(e).replace(/&/g,'&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;').replace(/"/g,'&quot;')};function registerOpenClose(e){$(e).children('.on-click-open-close').click(function(){$(this).closest('.toggle-open-close').toggleClass('open closed')})};