ACC SHELL

Path : /srv/www/vhosts/agroing/web/views/_default/www/js/
File Upload :
Current File : /srv/www/vhosts/agroing/web/views/_default/www/js/admin.js

$(document).ready(function(){

	//mce is initialized called in form.js

	//////   ROLLERS  /////
	// on click
	$('.roller').click(function(){ toggle_roller($(this)) })
	// from cookie
	var r = (cookie("hiden_rollers"));
	if(!r) r = "";
	hid = r.split("#");
	for (var i in hid) {
		if(hid[i].indexOf("r")!=-1){
			toggle_roller($("#"+hid[i]));
		}
	}
	// first view
	if(!cookie("nofirst_roller")) $(".sites ol ol .roller").each(function(){
		toggle_roller($(this));
	})
	function toggle_roller(roller){
		cookie("nofirst_roller",1); // indicator of first view
		var r = (cookie("hiden_rollers"));
		if(!r) r = "";
		var ol = roller.parent("li").children("ol");
		var hash = "#"+roller.attr("id")+"#";
		if(ol.is(":visible")){
			if(r.indexOf(hash) == -1) cookie("hiden_rollers",r+hash);
		}else{
			cookie("hiden_rollers",r.replace(hash,""));
		}
		roller.toggleClass("r-hidden");
		ol.toggle(100);
		$(".roller").html("-");
		$(".r-hidden").html("+");
	}
	////////   END ROLLERS   //////

	$(".del_alias").click(function(){
		if(!confirm("opravdu chcete smazat tento alias z databáze? (všechny výskyty)")) return false;
	})

	$('ol.sortable').nestedSortable({
		disableNesting: 'no-nest',
		forcePlaceholderSize: true,
		handle: '.move',
		helper:	'clone',
		items: 'li',
		opacity: .6,
		placeholder: 'placeholder',
		revert: 200,
		tabSize: 25,
		tolerance: 'pointer',
		toleranceElement: '> div',
		disableNesting: 'no-sortable',
		update: function(event, ui) {
			$.ajax({
				url: '/admin/site_serialize',
				type: "POST",
				data: $(this).nestedSortable('serialize'),
				success: function(data) {
					//alert(data);
				}
			});
		}
	});
	$('.sortable-files').sortable({
		handle: '.move',
		items: 'li',
		opacity: .6,
		revert: 200,
		tolerance: 'pointer',
		update: function(event, ui) {
			$.ajax({
				url: '/admin/file_serialize',
				type: "POST",
				data: $(this).sortable('serialize'),
				success: function(data) {
					//alert(data);
				}
			});
		}
	});
	$( ".sites" ).disableSelection();

	$(".expanding").TextAreaExpander();
	// file-expanding titles
	$(".file textarea").focus(function(){
		$(this).addClass("expanding");
		$(".expanding").TextAreaExpander();
	})

	$(".file .edit").each(function(){
		napozicuj($(this));
	})
	$(".file .edit").hover(function(){
		napozicuj($(this));
	})

	$(".fancy, [href$='.jpg'], [href$='.gif'], [href$='.png'], [href$='.JPG'], [href$='.GIF'], [href$='.PNG']").not(".wt-rotator a, .no-fancy").attr("rel","fancy").fancybox({
		'transitionIn' : 'elastic',
		'transitionOut' : 'elastic',
		'speedIn' : 400,
		'speedOut' : 200,
		'titleShow' : false,
		'overlayOpacity' : 0.2
	});

	$(".parts .tabs li").click(function(){
		$(".parts .tabs li").removeClass("sel");
		$(this).addClass("sel");
		$(".parts .part").hide();
		$(".parts .part-"+$(this).html().trim()).show();
		//tinyMCE.activeEditor.selection.setNode(tinyMCE.activeEditor.dom.create('img', {src : '/www/files/napodlaze.jpg', title : 'some title'}));
		tinyMCE.execCommand('mceFocus',false,'part-'+$(this).html().trim());
		goToTheEnd();
	});

    $(".select-me").click( function (){
		$(this).select();
	})

	$("#more").click(function() {
		$(".hid").toggle(200);
	});

//	zastavuje klik na "ulozit a pokracovat" v editaci prispevku
//	$('input[type=submit]').each(function(){
//		if($(this).attr('name')=='save_continue'){
//			$(this).click(function(){
//				alert('test');
//				return false;
//			});
//		}
//	});

});

function napozicuj(e){
	pos = e.position();
	e.children("ul").css("top",(pos.top-14)+"px").css("left",(pos.left-8)+"px");
}

function delete_file(id,state){
	$('.file-'+id).addClass('del_file');
	$('#del_files_'+id).val(state)
}

function open_mce_image(src,alt,title,width,height){
	url = '../../views/_default/www/js/tiny_mce/plugins/advimage'
	url = url + '/image.htm?src='+src+'&alt='+alt+'&title='+title+'&width='+width+'&height='+height;
	tinyMCE.activeEditor.windowManager.open({
		file : url,
		width : 480 ,
		height : 385 ,
		inline : 1
	}, {
		plugin_url : url
	});
}

function goToTheEnd() {
	var ed=tinyMCE.activeEditor;
	var root=ed.dom.getRoot();  // This gets the root node of the editor window
	var lastnode=root.childNodes[root.childNodes.length-1]; // And this gets the last node inside of it, so the last <p>...</p> tag
	if (tinymce.isGecko) { // But firefox places the selection outside of that tag, so we need to go one level deeper:
		lastnode=lastnode.childNodes[lastnode.childNodes.length-1];
	}
	ed.selection.select(lastnode); // Now, we select the node
	ed.selection.collapse(false); // And collapse the selection to the end to put the caret there:
}

function cookie(name,value,days) {
	if(typeof value == "undefined"){ // return
		var nameEQ = name + "=";
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
	}else if(value === null){ // delete
		cookie(name,"",-1);
	}else{						// save
		var re1=/^[a-z0-9:_\/-]+$/;
		if(!re1.test(name))	throw "bad parameter name!";
		if(days && typeof days !== typeof 1) throw "bad parameter days!";
		if (!days) days = 30;
		if(name==""){
			alert("function cookies() get empty name parameter!");
			return null;
		}
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
		document.cookie = name+"="+value+expires+"; path=/";
	}
	return null;
}

ACC SHELL 2018