| Current Path : /home/bonneesp/www/administrator/components/com_templateck/assets/ |
| Current File : /home/bonneesp/www/administrator/components/com_templateck/assets/preview.js |
$ck = jQuery.noConflict();
jQuery(document).ready(function (){
$ck('#menuck').fadeIn();
$ck('.menuckpanel').click(function() {
ckCloseSliderOverTab();
ckClosePreviewEdition();
ckActivatePanel($ck(this).attr('data-target'));
});
$ck('#ckcustomcsssettingsbutton').click(function() {
ckOpenCustomCssEditor();
});
$ck('.menuitemck_group').click(function() {
$ck(this).find('+ div').toggle('fast');
});
ckInitPreviewInterface();
});
/* override for the preview feature */
function ckInitOptionsSliders(wrap) {
wrap = wrap ? wrap : $ck('#ckelementscontainer');
$ck('.ckinterfaceslider', wrap).hide();
$ck('.ckinterfacesliderlink', wrap).each(function(i, tab) {
tab = $ck(tab);
var targetTab = $ck('#' + tab.attr('tab'));
tab.click(function() {
$ck('.ckinterfaceslider', targetTab.parent()).hide();
$ck('#' + tab.attr('tab')).show();
wrap.stop().animate({'margin-left': '-=300px'});
});
$ck('.ckinterfacesliderback', wrap).click(function() {
wrap.stop().animate({'margin-left': '+=300px'}, function() {
$ck('.ckinterfaceslider', targetTab.parent()).hide();
});
});
});
}
function ckInitOptionsSlidersOver() {
$ck('.ckinterfaceslidercontentover').hide();
$ck('.ckinterfacesliderlinkover').each(function(i, link) {
var $link = $ck(link);
var $targetTab = $ck('#' + $link.attr('tab'));
$link.click(function() {
if ($targetTab.hasClass('opened')) {
ckCloseSliderOverTab()
} else {
$link.addClass('active');
$ck('.ckinterfaceslidercontentover').hide();
$ck(document.body).append($targetTab);
$targetTab.show('fast').addClass('opened');
$ck(document.body).stop().animate({'margin-left': '257px'});
}
});
$ck('.ckinterfaceslideroverclose').click(function() {
ckCloseSliderOverTab(tabid)
});
});
}
function ckCloseSliderOverTab() {
$ck(document.body).stop().animate({'margin-left': '0'},
function() {
// $ck('.ckinterfaceslidercontentover').hide();
}
);
$ck('.ckinterfaceslidercontentover').hide('fast').removeClass('opened');
$ck('.ckinterfacesliderlinkover').removeClass('active');
}
function ckInitPreviewInterface() {
ckPreviewFillLayoutInterface();
ckInitOptionsSliders($ck('#ckinterfacesliderparent'));
ckInitOptionsSliders($ck('#ckinterfaceslideraddons'));
ckInitOptionsSlidersOver();
ckInitOptionsAccordions();
ckInitColorPickers();
// ckInitTooltip(); // TODO : utiliser CKAPI.tooltip
ckAddEventOnFields($ck('#menuck'), '');
ckRenderCss();
}
function ckActivatePanel(target) {
$ck('.menuckpanel').removeClass('active');
$ck('.menuckpanel[data-target="' + target + '"]').addClass('active');
$ck('.menuckpaneltarget').hide();
$ck('.menuckpaneltarget[data-target="' + target + '"]').show();
}
function ckGetPreviewIframe() {
return document.getElementById('ckiframepreview').contentDocument;
}
function ckPreviewFillLayoutInterface() {
var frame = $ck('#body');
var layoutwrap = $ck('#ckPreviewLayout');
layoutwrap.empty();
var wrappers = frame.find('> .ckbloc');
var html = '';
wrappers.each(function() {
html += '<ul class="ckPreviewLayout_wrapper"><li>'
+ ckPreviewLayoutExploreDom(this)
+ '</li></ul>';
});
layoutwrap.append(html);
ckEnablePreviewLayoutTogglers();
ckEnablePreviewLayoutSortable();
ckEnablePreviewLayoutOptions();
ckEnablePreviewLayoutFocus();
}
function ckPreviewLayoutExploreDom(item) {
if ($ck(item).attr('isdisabled') == 'true') return '';
var children = $ck(item).find('> .inner > .ckbloc, > .inner > .ckrowcontainer, > .ckbloc');
var html = '', classes = '', toggleBtn = '', itemIcon = '';
var dataAttrs = 'data-id="' + item.id + '"';
// only for parent items
if (children.length) {
// dataAttrs += ' data-children="1"';
classes += ' opened';
toggleBtn += '<span class="ckPreviewLayoutItemToggler"><i class="fa fa-chevron-down"></i></span>';
}
// item icons
if (item.className.indexOf('wrapper') != -1) {
itemIcon = '<i class="fa fa-window-maximize"></i>';
} else if (item.className.indexOf('ckrow') != -1
&& item.className.indexOf('ckrowcontainer') == -1) {
itemIcon = '<i class="fa fa-columns"></i>';
} else if (item.className.indexOf('flexiblemodules') != -1) {
itemIcon = '<i class="fa fa-cubes"></i>';
} else if (item.className.indexOf('singlemodule') != -1
|| item.className.indexOf('flexiblemodule') != -1
|| item.className.indexOf('column1') != -1
|| item.className.indexOf('column2') != -1
&& item.className.indexOf('flexiblemodules') == -1
) {
itemIcon = '<i class="fa fa-cube"></i>';
} else if (item.className.indexOf('horiznav') != -1) {
itemIcon = '<i class="fa fa-ellipsis-h"></i>';
} else if (item.className.indexOf('module') != -1) {
if (item.getAttribute('data-element') == 'mod_menu') {
itemIcon = '<i class="fa fa-navicon"></i>';
} else if (item.getAttribute('data-element') == 'mod_slideshowck') {
itemIcon = '<i class="fa fa-film"></i>';
}
} else if (item.className.indexOf('custombloc') != -1) {
itemIcon = '<i class="fa fa-file-text-o"></i>';
} else if (item.className.indexOf('emptybloc') != -1) {
itemIcon = '<i class="fa fa-question"></i>';
}
var optionBtn = '<span class="ckPreviewLayoutItemOptions"><i class="fa fa-cog"></i></span>';
html += '<div class="ckPreviewLayoutItem' + classes + '" ' + dataAttrs +'>'
+ itemIcon
+ '<span>' + item.id + '</span>'
+ optionBtn
+ toggleBtn
+ '</div>';
html += '<ul>';
if (children.length) {
children.each(function() {
html += '<li>'
// + getPreviewLayoutItemHtml(this)
+ ckPreviewLayoutExploreDom(this)
+ '</li>';
});
}
html += '</ul>'
return html;
}
function ckEnablePreviewLayoutTogglers() {
$ck('#ckPreviewLayout .ckPreviewLayoutItemToggler').each(function() {
var $this = $ck(this);
var $parent = $ck(this).parent();
var $childCont = $parent.find('+ ul');
$this.click(function() {
if ($parent.hasClass('opened')) {
$childCont.slideUp('fast');
$parent.removeClass('opened');
$parent.addClass('closed');
} else {
$childCont.slideDown('fast');
$parent.addClass('opened');
$parent.removeClass('closed');
}
});
})
}
function ckEnablePreviewLayoutSortable() {
// wrapper, row, column, module
// un module peut aller n'importe où sauf direct dans row. Il doit aller dans colonne
$ck('#ckPreviewLayout ul').sortable({
items: "> li",
// containment: "parent",
// axis: "y",
connectWith: "#ckPreviewLayout ul",
tolerance: "pointer",
// handle: "> .editorck .controlMove",
forceHelperSize: true,
dropOnEmpty: true,
forcePlaceholderSize: true,
placeholder: "ckplaceholder",
zIndex: 9999,
sort: function( event, ui ) {
// ckOnSortStart(ui);
},
start: function( event, ui ){
// ui.placeholder.height(parseInt($ck('> .inner',ui.helper).height()));
// ui.placeholder.parent().trigger('mouseover');
},
receive: function( event, ui ) {
// var newblock = $ck(this).find('.blocselect');
// if (ui.sender.hasClass('dragtoadd')) {
// newblock.css('float', 'none').addClass('ckwait');
// createBloc(newblock, ui.sender.attr('data-type'));
// ckMakeRowcontainerSortable($ck('.ckrowcontainer'));
// } else if (ui.sender.hasClass('ckdragtoaddelement')) {
// var newblock = $ck(this).find('.ckdragtoaddelement');
// newblock.css('float', 'none').addClass('ckwait');
// ckLoadLibraryElement(newblock);
// } else {
// newblock.remove();
// }
// ui.placeholder.parent().trigger('mouseleave');
},
stop: function( event, ui ){
// ui.placeholder.parent().trigger('mouseleave');
// if (! $ck(ui.item).hasClass('blocselect')) {
// ckSaveAction(); // only save action if not from left menu
// }
},
out: function( event, ui ) {
}
});
}
function ckEnablePreviewLayoutOptions() {
$ck('#ckPreviewLayout .ckPreviewLayoutItemOptions').on('click', function() {
var $item = $ck($ck(this).parents('.ckPreviewLayoutItem')[0])
var id = $item.attr('data-id');
ckShowEdition(id);
});
}
function ckEnablePreviewLayoutFocus() {
$ck('#ckPreviewLayout .ckPreviewLayoutItem').on('mouseover', function() {
var $target = $ck('#body #' + this.getAttribute('data-id'));
$target.addClass('ckhover');
}).on('mouseleave', function() {
var $this = $ck(this);
if (! $this.hasClass('ckfocus')) {
var $target = $ck('#body #' + this.getAttribute('data-id'));
$target.removeClass('ckhover');
}
}).on('click', function() {
var $this = $ck(this);
var $target = $ck('#body #' + this.getAttribute('data-id'));
if ($this.hasClass('ckfocus')) {
$this.removeClass('ckfocus');
$ck('.ckhover').removeClass('ckhover');
} else {
$ck('#ckPreviewLayout .ckfocus').removeClass('ckfocus');
$ck('.ckhover').removeClass('ckhover');
$this.addClass('ckfocus');
$target.addClass('ckhover');
$ck('html, body').animate( { scrollTop: $target.offset().top - 200, scrollLeft: $target.offset().left - 310 - $ck(document.body).css('margin-left') }, 300);
}
});
}
function ckLayoutOpenAddons() {
}
function ckShowEdition(blocid, savefunc, onAfterLoaded) {
if (! savefunc) savefunc = '';
if (! onAfterLoaded) onAfterLoaded = '';
// blocid = '#' + blocid;
// ckKeepAlive();
// $ck(document.body).append('<div id="ckwaitoverlay"></div>');
var bloc = $ck('#' + blocid);
$ck('.ckfocus').removeClass('ckfocus');
bloc.addClass('ckfocus');
$ck('#ckpreviewedition').css({'left': '150px', 'opacity': 0, 'display': 'block'});;
var editionarea = $ck('#ckpreviewedition');
var myurl = TEMPLATECREATORCK_ADMIN_URL + "&task=interface.load&layout=ajaxpreviewstylescss&" + CKTOKEN;
$ck.ajax({
type: "POST",
url: myurl,
data: {
objclass: bloc.attr('class'),
expertmode: $ck('#body').hasClass('expert'),
savefunc: savefunc,
element: bloc.attr('data-element'),
ckobjid: bloc.attr('id')
}
}).done(function(code) {
$ck('#ckpreviewedition').empty().animate({'left': '0px', 'opacity': 1}).append(code);
$ck('#ckpreviewedition').find('.ckinterfacesliderback-stylescss').on('click', function() {
ckClosePreviewEdition();
});
ckFillEdition(blocid);
ckAddEventOnFields(editionarea, blocid);
if (onAfterLoaded && typeof(window[onAfterLoaded]) == 'function') window[onAfterLoaded]();
// loadPreviewAreaStyles(blocid);
ckAddGoogleFontsToList();
}).fail(function() {
alert(TCK.Text._('CK_FAILED', 'Failed'));
// $ck('#ckwaitoverlay').remove();
});
}
function ckClosePreviewEdition() {
if (typeof ckBeforeCloseEditionPopup == 'function') { ckBeforeCloseEditionPopup(); }
$ck('#ckpreviewedition').animate({'left': '150px', 'opacity': 0}, function() { this.style.display = 'none'; });
$ck('.ckfocus').removeClass('ckfocus');
}