2016-01-11 02:25:30 +01:00
( function ( global , factory ) {
if ( typeof define === "function" && define . amd ) {
2016-03-29 00:43:45 +02:00
define ( 'ss.LeftAndMain' , [ 'jQuery' , 'router' , 'config' ] , factory ) ;
2016-01-11 02:25:30 +01:00
} else if ( typeof exports !== "undefined" ) {
2016-03-29 00:43:45 +02:00
factory ( require ( 'jQuery' ) , require ( 'router' ) , require ( 'config' ) ) ;
2016-01-11 02:25:30 +01:00
} else {
var mod = {
exports : { }
} ;
2016-03-29 00:43:45 +02:00
factory ( global . jQuery , global . router , global . config ) ;
2016-01-11 02:25:30 +01:00
global . ssLeftAndMain = mod . exports ;
}
2016-03-29 00:43:45 +02:00
} ) ( this , function ( _jQuery , _router , _config ) {
2016-02-12 04:00:15 +01:00
'use strict' ;
2016-01-11 02:25:30 +01:00
var _jQuery2 = _interopRequireDefault ( _jQuery ) ;
2016-03-29 00:43:45 +02:00
var _router2 = _interopRequireDefault ( _router ) ;
var _config2 = _interopRequireDefault ( _config ) ;
2016-01-11 02:25:30 +01:00
function _interopRequireDefault ( obj ) {
return obj && obj . _ _esModule ? obj : {
default : obj
} ;
}
var _typeof = typeof Symbol === "function" && typeof Symbol . iterator === "symbol" ? function ( obj ) {
return typeof obj ;
} : function ( obj ) {
return obj && typeof Symbol === "function" && obj . constructor === Symbol ? "symbol" : typeof obj ;
} ;
2016-03-29 00:43:45 +02:00
var windowWidth , windowHeight ;
2016-01-11 02:25:30 +01:00
_jQuery2 . default . noConflict ( ) ;
window . ss = window . ss || { } ;
2016-03-29 00:43:45 +02:00
window . ss . router = _router2 . default ;
2016-01-11 02:25:30 +01:00
window . ss . debounce = function ( func , wait , immediate ) {
var timeout , context , args ;
var later = function later ( ) {
timeout = null ;
if ( ! immediate ) func . apply ( context , args ) ;
} ;
return function ( ) {
var callNow = immediate && ! timeout ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
context = this ;
args = arguments ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
clearTimeout ( timeout ) ;
timeout = setTimeout ( later , wait ) ;
if ( callNow ) {
func . apply ( context , args ) ;
}
} ;
} ;
2016-03-29 00:43:45 +02:00
function getUrlPath ( url ) {
var anchor = document . createElement ( 'a' ) ;
anchor . href = url ;
return anchor . pathname ;
}
2016-01-11 02:25:30 +01:00
( 0 , _jQuery2 . default ) ( window ) . bind ( 'resize.leftandmain' , function ( e ) {
var cb = function cb ( ) {
( 0 , _jQuery2 . default ) ( '.cms-container' ) . trigger ( 'windowresize' ) ;
} ;
if ( _jQuery2 . default . browser . msie && parseInt ( _jQuery2 . default . browser . version , 10 ) < 9 ) {
var newWindowWidth = ( 0 , _jQuery2 . default ) ( window ) . width ( ) ,
newWindowHeight = ( 0 , _jQuery2 . default ) ( window ) . height ( ) ;
if ( newWindowWidth != windowWidth || newWindowHeight != windowHeight ) {
windowWidth = newWindowWidth ;
windowHeight = newWindowHeight ;
cb ( ) ;
}
} else {
cb ( ) ;
}
} ) ;
2016-02-25 02:51:59 +01:00
2016-03-04 04:40:54 +01:00
_jQuery2 . default . entwine . warningLevel = _jQuery2 . default . entwine . WARN _LEVEL _BESTPRACTISE ;
2016-03-29 00:43:45 +02:00
2016-01-11 02:25:30 +01:00
_jQuery2 . default . entwine ( 'ss' , function ( $ ) {
$ ( window ) . on ( "message" , function ( e ) {
var target ,
event = e . originalEvent ,
data = _typeof ( event . data ) === 'object' ? event . data : JSON . parse ( event . data ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
if ( $ . path . parseUrl ( window . location . href ) . domain !== $ . path . parseUrl ( event . origin ) . domain ) return ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
target = typeof data . target === 'undefined' ? $ ( window ) : $ ( data . target ) ;
switch ( data . type ) {
case 'event' :
target . trigger ( data . event , data . data ) ;
break ;
case 'callback' :
target [ data . callback ] . call ( target , data . data ) ;
break ;
}
} ) ;
var positionLoadingSpinner = function positionLoadingSpinner ( ) {
var offset = 120 ;
var spinner = $ ( '.ss-loading-screen .loading-animation' ) ;
var top = ( $ ( window ) . height ( ) - spinner . height ( ) ) / 2 ;
spinner . css ( 'top' , top + offset ) ;
spinner . show ( ) ;
} ;
var applyChosen = function applyChosen ( el ) {
if ( el . is ( ':visible' ) ) {
el . addClass ( 'has-chzn' ) . chosen ( {
allow _single _deselect : true ,
disable _search _threshold : 20
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
var title = el . prop ( 'title' ) ;
if ( title ) {
el . siblings ( '.chzn-container' ) . prop ( 'title' , title ) ;
}
} else {
setTimeout ( function ( ) {
el . show ( ) ;
applyChosen ( el ) ;
} , 500 ) ;
}
} ;
var isSameUrl = function isSameUrl ( url1 , url2 ) {
var baseUrl = $ ( 'base' ) . attr ( 'href' ) ;
url1 = $ . path . isAbsoluteUrl ( url1 ) ? url1 : $ . path . makeUrlAbsolute ( url1 , baseUrl ) , url2 = $ . path . isAbsoluteUrl ( url2 ) ? url2 : $ . path . makeUrlAbsolute ( url2 , baseUrl ) ;
var url1parts = $ . path . parseUrl ( url1 ) ,
url2parts = $ . path . parseUrl ( url2 ) ;
return url1parts . pathname . replace ( /\/*$/ , '' ) == url2parts . pathname . replace ( /\/*$/ , '' ) && url1parts . search == url2parts . search ;
} ;
var ajaxCompleteEvent = window . ss . debounce ( function ( ) {
$ ( window ) . trigger ( 'ajaxComplete' ) ;
} , 1000 , true ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( window ) . bind ( 'resize' , positionLoadingSpinner ) . trigger ( 'resize' ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( document ) . ajaxComplete ( function ( e , xhr , settings ) {
2016-03-29 00:43:45 +02:00
var url = xhr . getResponseHeader ( 'X-ControllerURL' ) ,
origUrl = window . history . state . path . replace ( /\/$/ , '' ) ,
destUrl = settings . url ,
msg = xhr . getResponseHeader ( 'X-Status' ) !== null ? xhr . getResponseHeader ( 'X-Status' ) : xhr . statusText ,
2016-01-11 02:25:30 +01:00
msgType = xhr . status < 200 || xhr . status > 399 ? 'bad' : 'good' ,
ignoredMessages = [ 'OK' ] ;
2016-03-29 00:43:45 +02:00
if ( url !== null && ( ! isSameUrl ( origUrl , url ) || ! isSameUrl ( destUrl , url ) ) ) {
_router2 . default . show ( url , {
id : new Date ( ) . getTime ( ) + String ( Math . random ( ) ) . replace ( /\D/g , '' ) ,
pjax : xhr . getResponseHeader ( 'X-Pjax' ) ? xhr . getResponseHeader ( 'X-Pjax' ) : settings . headers [ 'X-Pjax' ]
} ) ;
}
if ( xhr . getResponseHeader ( 'X-Reauthenticate' ) ) {
2016-01-11 02:25:30 +01:00
$ ( '.cms-container' ) . showLoginDialog ( ) ;
return ;
}
if ( xhr . status !== 0 && msg && $ . inArray ( msg , ignoredMessages ) ) {
statusMessage ( decodeURIComponent ( msg ) , msgType ) ;
}
ajaxCompleteEvent ( this ) ;
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '.cms-container' ) . entwine ( {
StateChangeXHR : null ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
FragmentXHR : { } ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
StateChangeCount : 0 ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
LayoutOptions : {
minContentWidth : 940 ,
minPreviewWidth : 400 ,
mode : 'content'
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
onadd : function onadd ( ) {
2016-03-29 00:43:45 +02:00
var self = this ,
basePath = getUrlPath ( $ ( 'base' ) [ 0 ] . href ) ;
if ( basePath [ basePath . length - 1 ] === '/' ) {
basePath += 'admin' ;
} else {
basePath = '/admin' ;
}
_router2 . default . base ( basePath ) ;
_config2 . default . getTopLevelRoutes ( ) . forEach ( function ( route ) {
( 0 , _router2 . default ) ( '/' + route + '/*' , function ( ctx , next ) {
if ( document . readyState !== 'complete' || typeof ctx . state . _ _forceReferer === 'undefined' ) {
return next ( ) ;
}
self . handleStateChange ( null , ctx . state ) . done ( next ) ;
} ) ;
} ) ;
_router2 . default . start ( ) ;
2016-01-11 02:25:30 +01:00
if ( $ . browser . msie && parseInt ( $ . browser . version , 10 ) < 8 ) {
$ ( '.ss-loading-screen' ) . append ( '<p class="ss-loading-incompat-warning"><span class="notice">' + 'Your browser is not compatible with the CMS interface. Please use Internet Explorer 8+, Google Chrome or Mozilla Firefox.' + '</span></p>' ) . css ( 'z-index' , $ ( '.ss-loading-screen' ) . css ( 'z-index' ) + 1 ) ;
$ ( '.loading-animation' ) . remove ( ) ;
this . _super ( ) ;
return ;
}
this . redraw ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '.ss-loading-screen' ) . hide ( ) ;
$ ( 'body' ) . removeClass ( 'loading' ) ;
$ ( window ) . unbind ( 'resize' , positionLoadingSpinner ) ;
this . restoreTabState ( ) ;
this . _super ( ) ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
fromWindow : {
2016-03-29 00:43:45 +02:00
onstatechange : function onstatechange ( event , historyState ) {
this . handleStateChange ( event , historyState ) ;
2016-01-11 02:25:30 +01:00
}
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
'onwindowresize' : function onwindowresize ( ) {
this . redraw ( ) ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
'from .cms-panel' : {
ontoggle : function ontoggle ( ) {
this . redraw ( ) ;
}
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
'from .cms-container' : {
onaftersubmitform : function onaftersubmitform ( ) {
this . redraw ( ) ;
}
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
'from .cms-menu-list li a' : {
onclick : function onclick ( e ) {
var href = $ ( e . target ) . attr ( 'href' ) ;
if ( e . which > 1 || href == this . _tabStateUrl ( ) ) return ;
this . splitViewMode ( ) ;
}
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
updateLayoutOptions : function updateLayoutOptions ( newSpec ) {
var spec = this . getLayoutOptions ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
var dirty = false ;
for ( var k in newSpec ) {
if ( spec [ k ] !== newSpec [ k ] ) {
spec [ k ] = newSpec [ k ] ;
dirty = true ;
}
}
if ( dirty ) this . redraw ( ) ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
splitViewMode : function splitViewMode ( ) {
this . updateLayoutOptions ( {
mode : 'split'
} ) ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
contentViewMode : function contentViewMode ( ) {
this . updateLayoutOptions ( {
mode : 'content'
} ) ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
previewMode : function previewMode ( ) {
this . updateLayoutOptions ( {
mode : 'preview'
} ) ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
RedrawSuppression : false ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
redraw : function redraw ( ) {
if ( this . getRedrawSuppression ( ) ) return ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
if ( window . debug ) console . log ( 'redraw' , this . attr ( 'class' ) , this . get ( 0 ) ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
this . data ( 'jlayout' , jLayout . threeColumnCompressor ( {
menu : this . children ( '.cms-menu' ) ,
content : this . children ( '.cms-content' ) ,
preview : this . children ( '.cms-preview' )
} , this . getLayoutOptions ( ) ) ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
this . layout ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
this . find ( '.cms-panel-layout' ) . redraw ( ) ;
this . find ( '.cms-content-fields[data-layout-type]' ) . redraw ( ) ;
this . find ( '.cms-edit-form[data-layout-type]' ) . redraw ( ) ;
this . find ( '.cms-preview' ) . redraw ( ) ;
this . find ( '.cms-content' ) . redraw ( ) ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
checkCanNavigate : function checkCanNavigate ( selectors ) {
var contentEls = this . _findFragments ( selectors || [ 'Content' ] ) ,
trackedEls = contentEls . find ( ':data(changetracker)' ) . add ( contentEls . filter ( ':data(changetracker)' ) ) ,
safe = true ;
if ( ! trackedEls . length ) {
return true ;
}
trackedEls . each ( function ( ) {
if ( ! $ ( this ) . confirmUnsavedChanges ( ) ) {
safe = false ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
return safe ;
} ,
2016-03-04 04:40:54 +01:00
2016-03-29 00:43:45 +02:00
loadPanel : function loadPanel ( url ) {
var title = arguments . length <= 1 || arguments [ 1 ] === undefined ? '' : arguments [ 1 ] ;
var data = arguments . length <= 2 || arguments [ 2 ] === undefined ? { } : arguments [ 2 ] ;
var forceReload = arguments [ 3 ] ;
var forceReferer = arguments . length <= 4 || arguments [ 4 ] === undefined ? window . history . state . path : arguments [ 4 ] ;
2016-01-11 02:25:30 +01:00
if ( ! this . checkCanNavigate ( data . pjax ? data . pjax . split ( ',' ) : [ 'Content' ] ) ) {
return ;
}
this . saveTabState ( ) ;
2016-03-29 00:43:45 +02:00
data . _ _forceReferer = forceReferer ;
2016-01-11 02:25:30 +01:00
2016-03-29 00:43:45 +02:00
if ( forceReload ) {
data . _ _forceReload = Math . random ( ) ;
2016-01-11 02:25:30 +01:00
}
2016-03-29 00:43:45 +02:00
_router2 . default . show ( url , data ) ;
2016-01-11 02:25:30 +01:00
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
reloadCurrentPanel : function reloadCurrentPanel ( ) {
2016-03-29 00:43:45 +02:00
this . loadPanel ( window . history . state . path , null , null , true ) ;
2016-01-11 02:25:30 +01:00
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
submitForm : function submitForm ( form , button , callback , ajaxOptions ) {
var self = this ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
if ( ! button ) button = this . find ( '.Actions :submit[name=action_save]' ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
if ( ! button ) button = this . find ( '.Actions :submit:first' ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
form . trigger ( 'beforesubmitform' ) ;
2016-03-04 04:40:54 +01:00
this . trigger ( 'submitform' , { form : form , button : button } ) ;
2016-01-11 02:25:30 +01:00
$ ( button ) . addClass ( 'loading' ) ;
2016-02-25 02:51:59 +01:00
2016-03-04 04:40:54 +01:00
var validationResult = form . validate ( ) ;
2016-01-11 02:25:30 +01:00
if ( typeof validationResult !== 'undefined' && ! validationResult ) {
statusMessage ( "Validation failed." , "bad" ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( button ) . removeClass ( 'loading' ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
return false ;
}
var formData = form . serializeArray ( ) ;
2016-03-04 04:40:54 +01:00
formData . push ( { name : $ ( button ) . attr ( 'name' ) , value : '1' } ) ;
2016-03-29 00:43:45 +02:00
formData . push ( { name : 'BackURL' , value : window . history . state . path . replace ( /\/$/ , '' ) } ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
this . saveTabState ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
jQuery . ajax ( jQuery . extend ( {
2016-03-04 04:40:54 +01:00
headers : { "X-Pjax" : "CurrentForm,Breadcrumbs" } ,
2016-01-11 02:25:30 +01:00
url : form . attr ( 'action' ) ,
data : formData ,
type : 'POST' ,
complete : function complete ( ) {
$ ( button ) . removeClass ( 'loading' ) ;
} ,
success : function success ( data , status , xhr ) {
form . removeClass ( 'changed' ) ;
if ( callback ) callback ( data , status , xhr ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
var newContentEls = self . handleAjaxResponse ( data , status , xhr ) ;
if ( ! newContentEls ) return ;
2016-03-04 04:40:54 +01:00
newContentEls . filter ( 'form' ) . trigger ( 'aftersubmitform' , { status : status , xhr : xhr , formData : formData } ) ;
2016-01-11 02:25:30 +01:00
}
} , ajaxOptions ) ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
return false ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
LastState : null ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
PauseState : false ,
2016-03-04 04:40:54 +01:00
2016-03-29 00:43:45 +02:00
handleStateChange : function handleStateChange ( event ) {
var historyState = arguments . length <= 1 || arguments [ 1 ] === undefined ? window . history . state : arguments [ 1 ] ;
2016-01-11 02:25:30 +01:00
if ( this . getPauseState ( ) ) {
return ;
}
2016-03-29 00:43:45 +02:00
if ( this . getStateChangeXHR ( ) ) {
this . getStateChangeXHR ( ) . abort ( ) ;
}
2016-01-11 02:25:30 +01:00
var self = this ,
2016-03-29 00:43:45 +02:00
fragments = historyState . pjax || 'Content' ,
2016-01-11 02:25:30 +01:00
headers = { } ,
fragmentsArr = fragments . split ( ',' ) ,
contentEls = this . _findFragments ( fragmentsArr ) ;
this . setStateChangeCount ( this . getStateChangeCount ( ) + 1 ) ;
if ( ! this . checkCanNavigate ( ) ) {
var lastState = this . getLastState ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
this . setPauseState ( true ) ;
2016-03-29 00:43:45 +02:00
if ( lastState !== null ) {
_router2 . default . show ( lastState . url ) ;
2016-01-11 02:25:30 +01:00
} else {
2016-03-29 00:43:45 +02:00
_router2 . default . back ( ) ;
2016-01-11 02:25:30 +01:00
}
2016-03-29 00:43:45 +02:00
2016-02-25 02:51:59 +01:00
this . setPauseState ( false ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
return ;
}
2016-03-29 00:43:45 +02:00
this . setLastState ( historyState ) ;
2016-01-11 02:25:30 +01:00
if ( contentEls . length < fragmentsArr . length ) {
fragments = 'Content' , fragmentsArr = [ 'Content' ] ;
contentEls = this . _findFragments ( fragmentsArr ) ;
}
2016-03-29 00:43:45 +02:00
this . trigger ( 'beforestatechange' , { state : historyState , element : contentEls } ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
headers [ 'X-Pjax' ] = fragments ;
2016-03-29 00:43:45 +02:00
if ( typeof historyState . _ _forceReferer !== 'undefined' ) {
var url = historyState . _ _forceReferer ;
2016-01-11 02:25:30 +01:00
try {
url = decodeURI ( url ) ;
} catch ( e ) { } finally {
headers [ 'X-Backurl' ] = encodeURI ( url ) ;
}
}
contentEls . addClass ( 'loading' ) ;
2016-03-04 04:40:54 +01:00
2016-03-29 00:43:45 +02:00
var promise = $ . ajax ( {
headers : headers ,
url : historyState . path
} ) . done ( function ( data , status , xhr ) {
var els = self . handleAjaxResponse ( data , status , xhr , historyState ) ;
self . trigger ( 'afterstatechange' , { data : data , status : status , xhr : xhr , element : els , state : historyState } ) ;
} ) . always ( function ( ) {
self . setStateChangeXHR ( null ) ;
contentEls . removeClass ( 'loading' ) ;
2016-01-11 02:25:30 +01:00
} ) ;
2016-03-04 04:40:54 +01:00
2016-03-29 00:43:45 +02:00
this . setStateChangeXHR ( promise ) ;
return promise ;
2016-01-11 02:25:30 +01:00
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
loadFragment : function loadFragment ( url , pjaxFragments ) {
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
var self = this ,
xhr ,
headers = { } ,
baseUrl = $ ( 'base' ) . attr ( 'href' ) ,
fragmentXHR = this . getFragmentXHR ( ) ;
if ( typeof fragmentXHR [ pjaxFragments ] !== 'undefined' && fragmentXHR [ pjaxFragments ] !== null ) {
fragmentXHR [ pjaxFragments ] . abort ( ) ;
fragmentXHR [ pjaxFragments ] = null ;
}
url = $ . path . isAbsoluteUrl ( url ) ? url : $ . path . makeUrlAbsolute ( url , baseUrl ) ;
headers [ 'X-Pjax' ] = pjaxFragments ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
xhr = $ . ajax ( {
headers : headers ,
url : url ,
success : function success ( data , status , xhr ) {
var elements = self . handleAjaxResponse ( data , status , xhr , null ) ;
2016-03-04 04:40:54 +01:00
self . trigger ( 'afterloadfragment' , { data : data , status : status , xhr : xhr , elements : elements } ) ;
2016-01-11 02:25:30 +01:00
} ,
error : function error ( xhr , status , _error ) {
2016-03-04 04:40:54 +01:00
self . trigger ( 'loadfragmenterror' , { xhr : xhr , status : status , error : _error } ) ;
2016-01-11 02:25:30 +01:00
} ,
complete : function complete ( ) {
var fragmentXHR = self . getFragmentXHR ( ) ;
if ( typeof fragmentXHR [ pjaxFragments ] !== 'undefined' && fragmentXHR [ pjaxFragments ] !== null ) {
fragmentXHR [ pjaxFragments ] = null ;
}
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
fragmentXHR [ pjaxFragments ] = xhr ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
return xhr ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
handleAjaxResponse : function handleAjaxResponse ( data , status , xhr , state ) {
var self = this ,
url ,
selectedTabs ,
guessFragment ,
fragment ,
$data ;
if ( xhr . getResponseHeader ( 'X-Reload' ) && xhr . getResponseHeader ( 'X-ControllerURL' ) ) {
var baseUrl = $ ( 'base' ) . attr ( 'href' ) ,
rawURL = xhr . getResponseHeader ( 'X-ControllerURL' ) ,
url = $ . path . isAbsoluteUrl ( rawURL ) ? rawURL : $ . path . makeUrlAbsolute ( rawURL , baseUrl ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
document . location . href = url ;
return ;
}
if ( ! data ) return ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
var title = xhr . getResponseHeader ( 'X-Title' ) ;
if ( title ) document . title = decodeURIComponent ( title . replace ( /\+/g , ' ' ) ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
var newFragments = { } ,
newContentEls ;
if ( xhr . getResponseHeader ( 'Content-Type' ) . match ( /^((text)|(application))\/json[ \t]*;?/i ) ) {
newFragments = data ;
} else {
fragment = document . createDocumentFragment ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
jQuery . clean ( [ data ] , document , fragment , [ ] ) ;
$data = $ ( jQuery . merge ( [ ] , fragment . childNodes ) ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
guessFragment = 'Content' ;
if ( $data . is ( 'form' ) && ! $data . is ( '[data-pjax-fragment~=Content]' ) ) guessFragment = 'CurrentForm' ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
newFragments [ guessFragment ] = $data ;
}
this . setRedrawSuppression ( true ) ;
try {
$ . each ( newFragments , function ( newFragment , html ) {
var contentEl = $ ( '[data-pjax-fragment]' ) . filter ( function ( ) {
return $ . inArray ( newFragment , $ ( this ) . data ( 'pjaxFragment' ) . split ( ' ' ) ) != - 1 ;
} ) ,
newContentEl = $ ( html ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
if ( newContentEls ) newContentEls . add ( newContentEl ) ; else newContentEls = newContentEl ;
if ( newContentEl . find ( '.cms-container' ) . length ) {
throw 'Content loaded via ajax is not allowed to contain tags matching the ".cms-container" selector to avoid infinite loops' ;
}
var origStyle = contentEl . attr ( 'style' ) ;
var origParent = contentEl . parent ( ) ;
var origParentLayoutApplied = typeof origParent . data ( 'jlayout' ) !== 'undefined' ;
var layoutClasses = [ 'east' , 'west' , 'center' , 'north' , 'south' , 'column-hidden' ] ;
var elemClasses = contentEl . attr ( 'class' ) ;
var origLayoutClasses = [ ] ;
if ( elemClasses ) {
origLayoutClasses = $ . grep ( elemClasses . split ( ' ' ) , function ( val ) {
return $ . inArray ( val , layoutClasses ) >= 0 ;
} ) ;
}
newContentEl . removeClass ( layoutClasses . join ( ' ' ) ) . addClass ( origLayoutClasses . join ( ' ' ) ) ;
if ( origStyle ) newContentEl . attr ( 'style' , origStyle ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
var styles = newContentEl . find ( 'style' ) . detach ( ) ;
if ( styles . length ) $ ( document ) . find ( 'head' ) . append ( styles ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
contentEl . replaceWith ( newContentEl ) ;
if ( ! origParent . is ( '.cms-container' ) && origParentLayoutApplied ) {
origParent . layout ( ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
var newForm = newContentEls . filter ( 'form' ) ;
if ( newForm . hasClass ( 'cms-tabset' ) ) newForm . removeClass ( 'cms-tabset' ) . addClass ( 'cms-tabset' ) ;
} finally {
this . setRedrawSuppression ( false ) ;
}
this . redraw ( ) ;
2016-03-29 00:43:45 +02:00
this . restoreTabState ( state && typeof state . tabState !== 'undefined' ? state . tabState : null ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
return newContentEls ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
_findFragments : function _findFragments ( fragments ) {
return $ ( '[data-pjax-fragment]' ) . filter ( function ( ) {
var i ,
nodeFragments = $ ( this ) . data ( 'pjaxFragment' ) . split ( ' ' ) ;
for ( i in fragments ) {
if ( $ . inArray ( fragments [ i ] , nodeFragments ) != - 1 ) return true ;
}
return false ;
} ) ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
refresh : function refresh ( ) {
$ ( window ) . trigger ( 'statechange' ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( this ) . redraw ( ) ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
saveTabState : function saveTabState ( ) {
if ( typeof window . sessionStorage == "undefined" || window . sessionStorage === null ) return ;
var selectedTabs = [ ] ,
url = this . _tabStateUrl ( ) ;
this . find ( '.cms-tabset,.ss-tabset' ) . each ( function ( i , el ) {
var id = $ ( el ) . attr ( 'id' ) ;
if ( ! id ) return ;
if ( ! $ ( el ) . data ( 'tabs' ) ) return ;
if ( $ ( el ) . data ( 'ignoreTabState' ) || $ ( el ) . getIgnoreTabState ( ) ) return ;
2016-03-04 04:40:54 +01:00
selectedTabs . push ( { id : id , selected : $ ( el ) . tabs ( 'option' , 'selected' ) } ) ;
2016-01-11 02:25:30 +01:00
} ) ;
if ( selectedTabs ) {
var tabsUrl = 'tabs-' + url ;
try {
window . sessionStorage . setItem ( tabsUrl , JSON . stringify ( selectedTabs ) ) ;
} catch ( err ) {
if ( err . code === DOMException . QUOTA _EXCEEDED _ERR && window . sessionStorage . length === 0 ) {
return ;
} else {
throw err ;
}
}
}
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
restoreTabState : function restoreTabState ( overrideStates ) {
var self = this ,
url = this . _tabStateUrl ( ) ,
hasSessionStorage = typeof window . sessionStorage !== "undefined" && window . sessionStorage ,
sessionData = hasSessionStorage ? window . sessionStorage . getItem ( 'tabs-' + url ) : null ,
sessionStates = sessionData ? JSON . parse ( sessionData ) : false ;
this . find ( '.cms-tabset, .ss-tabset' ) . each ( function ( ) {
var index ,
tabset = $ ( this ) ,
tabsetId = tabset . attr ( 'id' ) ,
tab ,
forcedTab = tabset . find ( '.ss-tabs-force-active' ) ;
if ( ! tabset . data ( 'tabs' ) ) {
return ;
}
tabset . tabs ( 'refresh' ) ;
if ( forcedTab . length ) {
index = forcedTab . index ( ) ;
} else if ( overrideStates && overrideStates [ tabsetId ] ) {
tab = tabset . find ( overrideStates [ tabsetId ] . tabSelector ) ;
if ( tab . length ) {
index = tab . index ( ) ;
}
} else if ( sessionStates ) {
$ . each ( sessionStates , function ( i , sessionState ) {
if ( tabset . is ( '#' + sessionState . id ) ) {
index = sessionState . selected ;
}
} ) ;
}
if ( index !== null ) {
tabset . tabs ( 'option' , 'active' , index ) ;
self . trigger ( 'tabstaterestored' ) ;
}
} ) ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
clearTabState : function clearTabState ( url ) {
if ( typeof window . sessionStorage == "undefined" ) return ;
2016-02-25 02:51:59 +01:00
2016-03-04 04:40:54 +01:00
var s = window . sessionStorage ;
2016-01-11 02:25:30 +01:00
if ( url ) {
s . removeItem ( 'tabs-' + url ) ;
} else {
for ( var i = 0 ; i < s . length ; i ++ ) {
if ( s . key ( i ) . match ( /^tabs-/ ) ) s . removeItem ( s . key ( i ) ) ;
}
}
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
clearCurrentTabState : function clearCurrentTabState ( ) {
this . clearTabState ( this . _tabStateUrl ( ) ) ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
_tabStateUrl : function _tabStateUrl ( ) {
2016-03-29 00:43:45 +02:00
return window . history . state . path . replace ( /\?.*/ , '' ) . replace ( /#.*/ , '' ) . replace ( $ ( 'base' ) . attr ( 'href' ) , '' ) ;
2016-01-11 02:25:30 +01:00
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
showLoginDialog : function showLoginDialog ( ) {
var tempid = $ ( 'body' ) . data ( 'member-tempid' ) ,
dialog = $ ( '.leftandmain-logindialog' ) ,
url = 'CMSSecurity/login' ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
if ( dialog . length ) dialog . remove ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
url = $ . path . addSearchParams ( url , {
'tempid' : tempid ,
'BackURL' : window . location . href
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
dialog = $ ( '<div class="leftandmain-logindialog"></div>' ) ;
dialog . attr ( 'id' , new Date ( ) . getTime ( ) ) ;
dialog . data ( 'url' , url ) ;
$ ( 'body' ) . append ( dialog ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '.leftandmain-logindialog' ) . entwine ( {
onmatch : function onmatch ( ) {
this . _super ( ) ;
this . ssdialog ( {
iframeUrl : this . data ( 'url' ) ,
dialogClass : "leftandmain-logindialog-dialog" ,
autoOpen : true ,
minWidth : 500 ,
maxWidth : 500 ,
minHeight : 370 ,
maxHeight : 400 ,
closeOnEscape : false ,
open : function open ( ) {
$ ( '.ui-widget-overlay' ) . addClass ( 'leftandmain-logindialog-overlay' ) ;
} ,
close : function close ( ) {
$ ( '.ui-widget-overlay' ) . removeClass ( 'leftandmain-logindialog-overlay' ) ;
}
} ) ;
} ,
onunmatch : function onunmatch ( ) {
this . _super ( ) ;
} ,
open : function open ( ) {
this . ssdialog ( 'open' ) ;
} ,
close : function close ( ) {
this . ssdialog ( 'close' ) ;
} ,
toggle : function toggle ( bool ) {
if ( this . is ( ':visible' ) ) this . close ( ) ; else this . open ( ) ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
reauthenticate : function reauthenticate ( data ) {
if ( typeof data . SecurityID !== 'undefined' ) {
$ ( ':input[name=SecurityID]' ) . val ( data . SecurityID ) ;
}
if ( typeof data . TempID !== 'undefined' ) {
$ ( 'body' ) . data ( 'member-tempid' , data . TempID ) ;
}
this . close ( ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( 'form.loading,.cms-content.loading,.cms-content-fields.loading,.cms-content-view.loading' ) . entwine ( {
onmatch : function onmatch ( ) {
this . append ( '<div class="cms-content-loading-overlay ui-widget-overlay-light"></div><div class="cms-content-loading-spinner"></div>' ) ;
this . _super ( ) ;
} ,
onunmatch : function onunmatch ( ) {
this . find ( '.cms-content-loading-overlay,.cms-content-loading-spinner' ) . remove ( ) ;
this . _super ( ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '.cms input[type="submit"], .cms button, .cms input[type="reset"], .cms .ss-ui-button' ) . entwine ( {
onadd : function onadd ( ) {
this . addClass ( 'ss-ui-button' ) ;
if ( ! this . data ( 'button' ) ) this . button ( ) ;
this . _super ( ) ;
} ,
onremove : function onremove ( ) {
if ( this . data ( 'button' ) ) this . button ( 'destroy' ) ;
this . _super ( ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '.cms .cms-panel-link' ) . entwine ( {
onclick : function onclick ( e ) {
if ( $ ( this ) . hasClass ( 'external-link' ) ) {
e . stopPropagation ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
return ;
}
var href = this . attr ( 'href' ) ,
url = href && ! href . match ( /^#/ ) ? href : this . data ( 'href' ) ,
2016-03-04 04:40:54 +01:00
data = { pjax : this . data ( 'pjaxTarget' ) } ;
2016-01-11 02:25:30 +01:00
$ ( '.cms-container' ) . loadPanel ( url , null , data ) ;
e . preventDefault ( ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '.cms .ss-ui-button-ajax' ) . entwine ( {
onclick : function onclick ( e ) {
$ ( this ) . removeClass ( 'ui-button-text-only' ) ;
$ ( this ) . addClass ( 'ss-ui-button-loading ui-button-text-icons' ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
var loading = $ ( this ) . find ( ".ss-ui-loading-icon" ) ;
if ( loading . length < 1 ) {
loading = $ ( "<span></span>" ) . addClass ( 'ss-ui-loading-icon ui-button-icon-primary ui-icon' ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( this ) . prepend ( loading ) ;
}
loading . show ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
var href = this . attr ( 'href' ) ,
url = href ? href : this . data ( 'href' ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
jQuery . ajax ( {
url : url ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
complete : function complete ( xmlhttp , status ) {
var msg = xmlhttp . getResponseHeader ( 'X-Status' ) ? xmlhttp . getResponseHeader ( 'X-Status' ) : xmlhttp . responseText ;
try {
if ( typeof msg != "undefined" && msg !== null ) eval ( msg ) ;
} catch ( e ) { }
loading . hide ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( ".cms-container" ) . refresh ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( this ) . removeClass ( 'ss-ui-button-loading ui-button-text-icons' ) ;
$ ( this ) . addClass ( 'ui-button-text-only' ) ;
} ,
dataType : 'html'
} ) ;
e . preventDefault ( ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '.cms .ss-ui-dialog-link' ) . entwine ( {
UUID : null ,
onmatch : function onmatch ( ) {
this . _super ( ) ;
this . setUUID ( new Date ( ) . getTime ( ) ) ;
} ,
onunmatch : function onunmatch ( ) {
this . _super ( ) ;
} ,
onclick : function onclick ( ) {
this . _super ( ) ;
var self = this ,
id = 'ss-ui-dialog-' + this . getUUID ( ) ;
var dialog = $ ( '#' + id ) ;
if ( ! dialog . length ) {
dialog = $ ( '<div class="ss-ui-dialog" id="' + id + '" />' ) ;
$ ( 'body' ) . append ( dialog ) ;
}
var extraClass = this . data ( 'popupclass' ) ? this . data ( 'popupclass' ) : '' ;
2016-03-04 04:40:54 +01:00
dialog . ssdialog ( { iframeUrl : this . attr ( 'href' ) , autoOpen : true , dialogExtraClass : extraClass } ) ;
2016-01-11 02:25:30 +01:00
return false ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '.cms-content .Actions' ) . entwine ( {
onmatch : function onmatch ( ) {
this . find ( '.ss-ui-button' ) . click ( function ( ) {
var form = this . form ;
if ( form ) {
form . clickedButton = this ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
setTimeout ( function ( ) {
form . clickedButton = null ;
} , 10 ) ;
}
} ) ;
2016-02-25 02:51:59 +01:00
2016-03-04 04:40:54 +01:00
this . redraw ( ) ;
2016-01-11 02:25:30 +01:00
this . _super ( ) ;
} ,
onunmatch : function onunmatch ( ) {
this . _super ( ) ;
} ,
redraw : function redraw ( ) {
if ( window . debug ) console . log ( 'redraw' , this . attr ( 'class' ) , this . get ( 0 ) ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
this . contents ( ) . filter ( function ( ) {
return this . nodeType == 3 && ! /\S/ . test ( this . nodeValue ) ;
} ) . remove ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
this . find ( '.ss-ui-button' ) . each ( function ( ) {
if ( ! $ ( this ) . data ( 'button' ) ) $ ( this ) . button ( ) ;
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
this . find ( '.ss-ui-buttonset' ) . buttonset ( ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '.cms .field.date input.text' ) . entwine ( {
onmatch : function onmatch ( ) {
var holder = $ ( this ) . parents ( '.field.date:first' ) ,
config = holder . data ( ) ;
if ( ! config . showcalendar ) {
this . _super ( ) ;
return ;
}
config . showOn = 'button' ;
if ( config . locale && $ . datepicker . regional [ config . locale ] ) {
config = $ . extend ( config , $ . datepicker . regional [ config . locale ] , { } ) ;
}
$ ( this ) . datepicker ( config ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
this . _super ( ) ;
} ,
onunmatch : function onunmatch ( ) {
this . _super ( ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '.cms .field.dropdown select, .cms .field select[multiple], .fieldholder-small select.dropdown' ) . entwine ( {
onmatch : function onmatch ( ) {
if ( this . is ( '.no-chzn' ) ) {
this . _super ( ) ;
return ;
}
if ( ! this . data ( 'placeholder' ) ) this . data ( 'placeholder' , ' ' ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
this . removeClass ( 'has-chzn chzn-done' ) ;
this . siblings ( '.chzn-container' ) . remove ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
applyChosen ( this ) ;
this . _super ( ) ;
} ,
onunmatch : function onunmatch ( ) {
this . _super ( ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( ".cms-panel-layout" ) . entwine ( {
redraw : function redraw ( ) {
if ( window . debug ) console . log ( 'redraw' , this . attr ( 'class' ) , this . get ( 0 ) ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '.cms .ss-gridfield' ) . entwine ( {
showDetailView : function showDetailView ( url ) {
var params = window . location . search . replace ( /^\?/ , '' ) ;
if ( params ) url = $ . path . addSearchParams ( url , params ) ;
$ ( '.cms-container' ) . loadPanel ( url ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '.cms-search-form' ) . entwine ( {
onsubmit : function onsubmit ( e ) {
var nonEmptyInputs , url ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
nonEmptyInputs = this . find ( ':input:not(:submit)' ) . filter ( function ( ) {
var vals = $ . grep ( $ ( this ) . fieldValue ( ) , function ( val ) {
return val ;
} ) ;
return vals . length ;
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
url = this . attr ( 'action' ) ;
if ( nonEmptyInputs . length ) {
url = $ . path . addSearchParams ( url , nonEmptyInputs . serialize ( ) ) ;
}
var container = this . closest ( '.cms-container' ) ;
container . find ( '.cms-edit-form' ) . tabs ( 'select' , 0 ) ;
container . loadPanel ( url , "" , { } , true ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
return false ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( ".cms-search-form button[type=reset], .cms-search-form input[type=reset]" ) . entwine ( {
onclick : function onclick ( e ) {
e . preventDefault ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
var form = $ ( this ) . parents ( 'form' ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
form . clearForm ( ) ;
form . find ( ".dropdown select" ) . prop ( 'selectedIndex' , 0 ) . trigger ( "liszt:updated" ) ;
form . submit ( ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
window . _panelDeferredCache = { } ;
$ ( '.cms-panel-deferred' ) . entwine ( {
onadd : function onadd ( ) {
this . _super ( ) ;
this . redraw ( ) ;
} ,
onremove : function onremove ( ) {
if ( window . debug ) console . log ( 'saving' , this . data ( 'url' ) , this ) ;
2016-02-25 02:51:59 +01:00
2016-03-04 04:40:54 +01:00
if ( ! this . data ( 'deferredNoCache' ) ) window . _panelDeferredCache [ this . data ( 'url' ) ] = this . html ( ) ;
2016-01-11 02:25:30 +01:00
this . _super ( ) ;
} ,
redraw : function redraw ( ) {
if ( window . debug ) console . log ( 'redraw' , this . attr ( 'class' ) , this . get ( 0 ) ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
var self = this ,
url = this . data ( 'url' ) ;
if ( ! url ) throw 'Elements of class .cms-panel-deferred need a "data-url" attribute' ;
this . _super ( ) ;
if ( ! this . children ( ) . length ) {
if ( ! this . data ( 'deferredNoCache' ) && typeof window . _panelDeferredCache [ url ] !== 'undefined' ) {
this . html ( window . _panelDeferredCache [ url ] ) ;
} else {
this . addClass ( 'loading' ) ;
$ . ajax ( {
url : url ,
complete : function complete ( ) {
self . removeClass ( 'loading' ) ;
} ,
success : function success ( data , status , xhr ) {
self . html ( data ) ;
}
} ) ;
}
}
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '.cms-tabset' ) . entwine ( {
onadd : function onadd ( ) {
this . redrawTabs ( ) ;
this . _super ( ) ;
} ,
onremove : function onremove ( ) {
if ( this . data ( 'tabs' ) ) this . tabs ( 'destroy' ) ;
this . _super ( ) ;
} ,
redrawTabs : function redrawTabs ( ) {
this . rewriteHashlinks ( ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
var id = this . attr ( 'id' ) ,
activeTab = this . find ( 'ul:first .ui-tabs-active' ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
if ( ! this . data ( 'uiTabs' ) ) this . tabs ( {
active : activeTab . index ( ) != - 1 ? activeTab . index ( ) : 0 ,
beforeLoad : function beforeLoad ( e , ui ) {
return false ;
} ,
activate : function activate ( e , ui ) {
var actions = $ ( this ) . closest ( 'form' ) . find ( '.Actions' ) ;
if ( $ ( ui . newTab ) . closest ( 'li' ) . hasClass ( 'readonly' ) ) {
actions . fadeOut ( ) ;
} else {
actions . show ( ) ;
}
}
} ) ;
} ,
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
rewriteHashlinks : function rewriteHashlinks ( ) {
$ ( this ) . find ( 'ul a' ) . each ( function ( ) {
if ( ! $ ( this ) . attr ( 'href' ) ) return ;
var matches = $ ( this ) . attr ( 'href' ) . match ( /#.*/ ) ;
if ( ! matches ) return ;
$ ( this ) . attr ( 'href' , document . location . href . replace ( /#.*/ , '' ) + matches [ 0 ] ) ;
} ) ;
}
} ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$ ( '#filters-button' ) . entwine ( {
onmatch : function onmatch ( ) {
this . _super ( ) ;
this . data ( 'collapsed' , true ) ;
this . data ( 'animating' , false ) ;
} ,
onunmatch : function onunmatch ( ) {
this . _super ( ) ;
} ,
showHide : function showHide ( ) {
var self = this ,
$filters = $ ( '.cms-content-filters' ) . first ( ) ,
collapsed = this . data ( 'collapsed' ) ;
if ( this . data ( 'animating' ) ) {
return ;
}
this . toggleClass ( 'active' ) ;
this . data ( 'animating' , true ) ;
2016-03-04 04:40:54 +01:00
2016-01-11 02:25:30 +01:00
$filters [ collapsed ? 'slideDown' : 'slideUp' ] ( {
complete : function complete ( ) {
self . data ( 'collapsed' , ! collapsed ) ;
self . data ( 'animating' , false ) ;
}
} ) ;
} ,
onclick : function onclick ( ) {
this . showHide ( ) ;
}
} ) ;
} ) ;
var statusMessage = function statusMessage ( text , type ) {
text = jQuery ( '<div/>' ) . text ( text ) . html ( ) ;
2016-03-04 04:40:54 +01:00
jQuery . noticeAdd ( { text : text , type : type , stayTime : 5000 , inEffect : { left : '0' , opacity : 'show' } } ) ;
2016-01-11 02:25:30 +01:00
} ;
var errorMessage = function errorMessage ( text ) {
2016-03-04 04:40:54 +01:00
jQuery . noticeAdd ( { text : text , type : 'error' , stayTime : 5000 , inEffect : { left : '0' , opacity : 'show' } } ) ;
2016-01-11 02:25:30 +01:00
} ;
} ) ;