2016-01-26 05:28:36 +01:00
( function ( global , factory ) {
if ( typeof define === "function" && define . amd ) {
2016-01-31 21:39:10 +01:00
define ( 'ss.CMSMain.Tree' , [ 'jQuery' , 'i18n' ] , factory ) ;
2016-01-26 05:28:36 +01:00
} else if ( typeof exports !== "undefined" ) {
2016-01-31 21:39:10 +01:00
factory ( require ( 'jQuery' ) , require ( 'i18n' ) ) ;
2016-01-26 05:28:36 +01:00
} else {
var mod = {
exports : { }
} ;
factory ( global . jQuery , global . i18n ) ;
global . ssCMSMainTree = mod . exports ;
}
} ) ( this , function ( _jQuery , _i18n ) {
'use strict' ;
var _jQuery2 = _interopRequireDefault ( _jQuery ) ;
var _i18n2 = _interopRequireDefault ( _i18n ) ;
function _interopRequireDefault ( obj ) {
return obj && obj . _ _esModule ? obj : {
default : obj
} ;
}
_jQuery2 . default . entwine ( 'ss.tree' , function ( $ ) {
$ ( '.cms-tree' ) . entwine ( {
fromDocument : {
'oncontext_show.vakata' : function oncontext _showVakata ( e ) {
this . adjustContextClass ( ) ;
}
} ,
2016-02-11 20:33:04 +01:00
2016-01-26 05:28:36 +01:00
adjustContextClass : function adjustContextClass ( ) {
var menus = $ ( '#vakata-contextmenu' ) . find ( "ul ul" ) ;
2016-03-04 02:58:17 +01:00
2016-01-26 05:28:36 +01:00
menus . each ( function ( i ) {
var col = "1" ,
count = $ ( menus [ i ] ) . find ( 'li' ) . length ;
if ( count > 20 ) {
col = "3" ;
} else if ( count > 10 ) {
col = "2" ;
}
$ ( menus [ i ] ) . addClass ( 'col-' + col ) . removeClass ( 'right' ) ;
2016-03-04 02:58:17 +01:00
2016-01-26 05:28:36 +01:00
$ ( menus [ i ] ) . find ( 'li' ) . on ( "mouseenter" , function ( e ) {
$ ( this ) . parent ( 'ul' ) . removeClass ( "right" ) ;
} ) ;
} ) ;
} ,
getTreeConfig : function getTreeConfig ( ) {
var self = this ,
config = this . _super ( ) ,
hints = this . getHints ( ) ;
config . plugins . push ( 'contextmenu' ) ;
config . contextmenu = {
'items' : function items ( node ) {
2016-03-04 02:58:17 +01:00
2016-01-26 05:28:36 +01:00
var menuitems = {
2016-08-31 13:15:12 +02:00
edit : {
'label' : node . hasClass ( 'edit-disabled' ) ? _i18n2 . default . _t ( 'Tree.EditPage' , 'Edit page' , 100 , 'Used in the context menu when right-clicking on a page node in the CMS tree' ) : _i18n2 . default . _t ( 'Tree.ViewPage' , 'View page' , 100 , 'Used in the context menu when right-clicking on a page node in the CMS tree' ) ,
2016-01-26 05:28:36 +01:00
'action' : function action ( obj ) {
$ ( '.cms-container' ) . entwine ( '.ss' ) . loadPanel ( _i18n2 . default . sprintf ( self . data ( 'urlEditpage' ) , obj . data ( 'id' ) ) ) ;
}
}
} ;
if ( ! node . hasClass ( 'nochildren' ) ) {
menuitems [ 'showaslist' ] = {
'label' : _i18n2 . default . _t ( 'Tree.ShowAsList' ) ,
'action' : function action ( obj ) {
2016-02-11 20:33:04 +01:00
$ ( '.cms-container' ) . entwine ( '.ss' ) . loadPanel ( self . data ( 'urlListview' ) + '&ParentID=' + obj . data ( 'id' ) , null , { tabState : { 'pages-controller-cms-content' : { 'tabSelector' : '.content-listview' } } } ) ;
2016-01-26 05:28:36 +01:00
}
} ;
}
var pagetype = node . data ( 'pagetype' ) ,
id = node . data ( 'id' ) ,
allowedChildren = node . find ( '>a .item' ) . data ( 'allowedchildren' ) ,
menuAllowedChildren = { } ,
hasAllowedChildren = false ;
2016-03-04 02:58:17 +01:00
2016-01-26 05:28:36 +01:00
$ . each ( allowedChildren , function ( klass , title ) {
hasAllowedChildren = true ;
menuAllowedChildren [ "allowedchildren-" + klass ] = {
'label' : '<span class="jstree-pageicon"></span>' + title ,
'_class' : 'class-' + klass ,
'action' : function action ( obj ) {
$ ( '.cms-container' ) . entwine ( '.ss' ) . loadPanel ( $ . path . addSearchParams ( _i18n2 . default . sprintf ( self . data ( 'urlAddpage' ) , id , klass ) , self . data ( 'extraParams' ) ) ) ;
}
} ;
} ) ;
if ( hasAllowedChildren ) {
menuitems [ 'addsubpage' ] = {
'label' : _i18n2 . default . _t ( 'Tree.AddSubPage' , 'Add page under this page' , 100 , 'Used in the context menu when right-clicking on a page node in the CMS tree' ) ,
'submenu' : menuAllowedChildren
} ;
}
2016-08-31 13:15:12 +02:00
if ( ! node . hasClass ( 'edit-disabled' ) ) {
menuitems [ 'duplicate' ] = {
'label' : _i18n2 . default . _t ( 'Tree.Duplicate' ) ,
'submenu' : [ {
'label' : _i18n2 . default . _t ( 'Tree.ThisPageOnly' ) ,
'action' : function action ( obj ) {
$ ( '.cms-container' ) . entwine ( '.ss' ) . loadPanel ( $ . path . addSearchParams ( _i18n2 . default . sprintf ( self . data ( 'urlDuplicate' ) , obj . data ( 'id' ) ) , self . data ( 'extraParams' ) ) ) ;
}
} , {
'label' : _i18n2 . default . _t ( 'Tree.ThisPageAndSubpages' ) ,
'action' : function action ( obj ) {
$ ( '.cms-container' ) . entwine ( '.ss' ) . loadPanel ( $ . path . addSearchParams ( _i18n2 . default . sprintf ( self . data ( 'urlDuplicatewithchildren' ) , obj . data ( 'id' ) ) , self . data ( 'extraParams' ) ) ) ;
}
} ]
} ;
}
2016-03-04 02:58:17 +01:00
2016-01-26 05:28:36 +01:00
return menuitems ;
}
} ;
return config ;
}
} ) ;
2016-03-04 02:58:17 +01:00
2016-01-26 05:28:36 +01:00
$ ( '.cms-tree a.jstree-clicked' ) . entwine ( {
onmatch : function onmatch ( ) {
var self = this ,
panel = self . parents ( '.cms-panel-content' ) ,
scrollTo ;
if ( self . offset ( ) . top < 0 || self . offset ( ) . top > panel . height ( ) - self . height ( ) ) {
scrollTo = panel . scrollTop ( ) + self . offset ( ) . top + panel . height ( ) / 2 ;
2016-03-04 02:58:17 +01:00
2016-01-26 05:28:36 +01:00
panel . animate ( {
scrollTop : scrollTo
} , 'slow' ) ;
}
}
} ) ;
2016-03-04 02:58:17 +01:00
2016-01-26 05:28:36 +01:00
$ ( '.cms-tree-filtered .clear-filter' ) . entwine ( {
onclick : function onclick ( ) {
window . location = location . protocol + '//' + location . host + location . pathname ;
}
} ) ;
2016-03-04 02:58:17 +01:00
2016-01-26 05:28:36 +01:00
$ ( '.cms-tree-filtered' ) . entwine ( {
onmatch : function onmatch ( ) {
var self = this ,
setHeight = function setHeight ( ) {
var height = $ ( '.cms-content-tools .cms-panel-content' ) . height ( ) - self . parent ( ) . siblings ( '.cms-content-toolbar' ) . outerHeight ( true ) ;
self . css ( 'height' , height + 'px' ) ;
} ;
setHeight ( ) ;
$ ( window ) . on ( 'resize' , window . ss . debounce ( setHeight , 300 ) ) ;
}
} ) ;
} ) ;
} ) ;