$.fn.overlay = function(cb) { if($("#main_container").find('#editor-overlay').length > 0) { $("#main_container").find('#editor-overlay').fadeOut(200, function() {$(this).remove();}); } else { $("#main_container").append('
'); $("#main_container").find('#editor-overlay').css({ 'background-color' : '#000', 'display' : 'block', 'width' : '100%', 'left' : '0', 'top' : '0', 'height' : '100%', 'z-index' : '98', 'position' : 'fixed', 'opacity' : '0.5', 'filter' : 'alpha(opacity=50)' }).fadeIn(200, cb); } }; $.fn.scale = function(parms) { if(!parms.ease) parms.ease = 'easeOutBack'; $(this).hover( function () { parms.cwidth = $(this).width(); parms.cheight = $(this).height(); // Easing methods: easeOutElastic, easeOutBack, linear, easeOutQuart, // $(this).data('zindex', $(this).css('z-index') == 'auto' ? 1 : $(this).css('z-index')).css('z-index', 10).addClass('teeko-editor-hover').animate({width:"+="+parms.width,height:"+="+parms.height,marginTop:"-="+(parms.height / 2),marginLeft:"-="+(parms.width / 2)},parms.speed,parms.ease, function() { /*if($(this).hasClass('teeko-editor-hover')) $(this).rate();*/}); $(this).data('zindex', $(this).css('z-index') == 'auto' ? 1 : $(this).css('z-index')).css('z-index', 10).animate({width:parms.width,height:parms.height,marginTop:((parms.cheight - parms.height) / 2),marginLeft:((parms.cwidth - parms.width) / 2)},{duration:parms.speed,easing:parms.ease,queue:false}, function() { /*if($(this).hasClass('teeko-editor-hover')) $(this).rate();*/}); }, function () { //$(this).hideRate(); $(this).css('z-index',9).animate({width:parms.cwidth,height:parms.cheight,marginTop:0,marginLeft:0},{duration:parms.speed,easing:parms.ease,queue:false}, function() { $(this).css('z-index', $(this).data('zindex')); }); } ); }; jQuery.fn.clearForm = function() { $(this).find(':input').each(function() { switch(this.type) { case 'password': case 'select-multiple': case 'select-one': case 'text': case 'textarea': $(this).val(''); break; case 'checkbox': case 'radio': this.checked = false; } }); }; /// Image preloader class var ImagePreloader = { status: false, load: function() { }, unload: function() { }, init: function() { } }; /// Page Preloader class var preloader = { PRELOADER_TIMEOUT: 300, interval: false, obj: false, status: false, show: function() { this.obj.css({marginLeft:'-175px',opacity:0}).show().animate({marginLeft:'-70px','opacity':1},400); }, load: function() { var $$ = $('#loading_animation'); if($$.length > 0 && this.status === false) { this.obj = $$; this.status = true; this.interval = setTimeout('preloader.show()', this.PRELOADER_TIMEOUT); } }, unload: function() { var preloader = $('#loading_animation'); if(preloader.length > 0) { clearTimeout(this.interval); this.interval = false; if(this.status === true) { this.status = false; preloader.fadeOut(500, function() { $(this).hide();}); } } }, init: function() { } }; /// Custom selectoreitahan vois tehä ihan sellasiakin et #site_editor:wrapper, #site_editor:element-selected /// Custom Selectors ------------------------------------ $.extend($.expr[':'],{ backgroundImage: function(a) { return $(a).css('background-image') !== 'none'; }, wrapper: function(a) { return $(a).data('teeko-wrapper') === 'true'; }, autoOverflow: function(a) { // ei käytössä return $(a).css('overflow') === 'auto'; }, fullSize: function(a) { // Ei käytössä return $(a).css('width') === '100%'; } }); $.fn.extend({_animate: $.fn.animate,_css: $.fn.css}); var parent_showed = false; jQuery.fn.uniqueByTag = function(tag) { var r = new Array(); o:for(var i = 0, n = this.length; i < n; i++) { for(var x = 0, y = r.length; x < y; x++) { if(r[x][tag]==this[i][tag]) { this.splice(x, 1); continue o; } } r[r.length] = this[i]; } /* $.each(this,function(i,item) { console.log(item['src']); $.each(this,function(i2,item2) { if(item[tag] == item2[tag] && ) { //this.splice(i, 1); } }); });*/ }; /* jQuery.fn.css = function(parm, value) { // Lets create IE fix and add alpha filter if opacity is changed! if(parm.opacity) parm.filter = 'alpha(opacity = '+ parm.opacity * 100 +')'; if(value) return $(this)._css(parm, value); else return $(this)._css(parm); } */ jQuery.fn.preload = function() { var $$ = $(this); $$.find('img,div:backgroundImage').each(function() { var src = $(this).attr('src'); if(src === undefined) src = $(this).backgroundImage(); var img = new Image(); $$.data('teeko-editor-preloading',{}); $(img).load(function() { $$.data('teeko-editor-preloading').loaded++; if($$.data('teeko-editor-preloading').loaded == $$.data('teeko-editor-preloading').images) setTimeout( function() {$$.show().data('teeko-editor-preloading',false);},10); }) .error(function() { // If error then continue cause otherwise picture doesnt show anywhere // if element has 5 pictures and 4 pictures is loaded then no animation occurs $$.data('teeko-editor-preloading').loaded++; if($$.data('teeko-editor-preloading').loaded == $$.data('teeko-editor-preloading').images) setTimeout( function() {$$.show().data('teeko-editor-preloading',false);},10); }) .attr('src', src).hide(); }); } function preload() { $('#main_container').preload(); } try { window.addEventListener('load', preload, false); } catch(e) { window.onload = preload; } jQuery.fn.animate = function(parm, speed, cb) { // Tähänhän me voidaan hakea tieto esim. tietokannasta!! tai sitten // ihan vaan templaten alussa on esim. var dont_animate = false; var el = $(this); var imgs = el.find('img,div:backgroundImage'); // TÄÄ HEITTÄÄ VIRHETTÄ ETTEI TOIMI SAFARILLA!!! // DEBUG: OTETAAN NÄÄ UNIIKKI JUTUT VIELÄ POIS MUTTA NE ON LISÄTTÄVÄ MAHD PIAN KOSKA MUUTEN // TÄSSÄ KÄYDÄÄN TURHIA JUTTUJA LÄPI!!! // imgs.uniqueByTag('src'); // imgs.uniqueByTag('background-image'); /// DEBUG: tähän vois myös tehä jonku sellasen et ei sellasii enää tarvi ladata mitkä olis jo latautunu // mutta ei oo ladattu tällä.. sillohan teeko-editor-preloading === undefined vaikka ne olis jo ladattu // ja ei niit uusiks kannata ladata.. mutta mistä se katotaan?!? preloadataanko loppujen lopuks aivan kaikki // graffa et saadaan merkatuks et nyt on preloadattu!!?!? /// DEBUG: Tehty nyt tohon toi et site_editor elementti pitää löytyä ennenku käytetään animate /// preloadingia.. se johtuu IE bugista hellstattoo sivuilla.. eli menu animaatiot ei ekalla clikkauksella /// tehty ollenkaan.. ja se johtu tästä kun jostain syystä se ei preloadannu niitä if( el.data('teeko-editor-preloading') === undefined && imgs.length > 1 && $('#site_editor').length > 0) { el.data('teeko-editor-preloading', {}); if(el.attr('tagName') === 'IMG' || el.css('background-image') !== 'none') imgs.push(el); imgs.each(function() { var src = $(this).attr('src'); if(src === undefined) src = $(this).backgroundImage(); var img = new Image(); $(img).load(function() { el.data('teeko-editor-preloading').loaded++; if(el.data('teeko-editor-preloading').loaded == el.data('teeko-editor-preloading').images) setTimeout( function() {return el._animate(parm, speed, cb).data('teeko-editor-preloading',false);},10); }) .error(function() { // If error then continue cause otherwise picture doesnt show anywhere // if element has 5 pictures and 4 pictures is loaded then no animation occurs if(el.data('teeko-editor-preloading') !== undefined) { el.data('teeko-editor-preloading').loaded++; if(el.data('teeko-editor-preloading').loaded == el.data('teeko-editor-preloading').images) setTimeout( function() {return el._animate(parm, speed, cb).data('teeko-editor-preloading',false);},10); } }) .attr('src', src); }); el.data('teeko-editor-preloading', { status: true, loaded: 0, images: imgs.length }); } else { // if(parm.opacity) parm.filter = 'alpha(opacity = '+parm.opacity * 100+')'; if(dont_animate) el.css(parm); else return el._animate(parm, speed, cb); } } jQuery.fn.backgroundImage = function() { //var regex = new RegExp("url\\('?([^']*)'?\\)", 'gi'); //var match = regex.exec( $(this).css('background-image') ); //if(match !== null) return match[match.index+1]; if($(this).css('backgroundImage') !== undefined && $(this).css('backgroundImage') !== 'none' && $(this).css('backgroundImage') !== null) { /// DEBUG: replace('"','') on vain ja ainoastaan IE Bugi.. se laittaa background-image url('') sisään hipsukat // jolloin css ei ymmärrä sitä kuvaa return $(this).css('backgroundImage').replace(/^url|[\(\)]/g, '').replace('"','').replace('"',''); } }; jQuery.fn.validation = function(act, dest) { $(this).validate( { submitHandler: function(form) { if(!dest) { if($(form).attr('acceptCharset')) document.charset = $(form).attr('acceptCharset'); form.submit(); } else Request(act, {'method':'get','dest':dest}, $(form).attr('id')); }, errorPlacement: function(error, element) { if($(element).length > 0) { if($(element.attr("error")).length > 0) $(element.attr("error")).show(); var $$ = $(element).find('+ div'); $$.show(); /* if($(element).attr('errorClass') !== "") $(element).addClass($(element).attr('errorClass')); */ $(element).keyup(function() {/* if($(element).attr('errorClass') !== "") $(element).removeClass($(element).attr('errorClass')); */ if($(element.attr("error")).length > 0) $(element.attr("error")).hide(); $$.hide(); }); } } }); } jQuery.fn.getattr = function(attr, pos, sum) { var value = $(this).css(attr); if(sum > 0) { value = parseFloat(value.replace('px','')); if(pos == '-') value = value - sum; if(pos == '+') value = value + sum; value = value +'px'; } return value; } jQuery.fn.teeko_effects_show = function(element_id) { var parent_id = $(this).parent().attr('id'); if(parent_id == element_id) { parent_id = $(this).attr('id'); } parent_showed = parent_id; if( $("#element_hider").length == 0 ) { $("#main_container").append("
Hävitit elementit. Paina tästä jos haluat ne takaisin
"); $("#element_hider").hover( function () { $(this).animate({opacity:1}); }, function () { $(this).animate({opacity:0.5}); } ); $("#element_hider").click( function(e) { showed = false; $(this).teeko_effects_hide('background'); e.stopPropagation(); }); } $("#element_hider").animate( {marginLeft:'+=500px'}, 400 ); $("#"+element_id+" .resizable:not(#"+parent_id+"):not(#"+parent_id+" *)").animate({marginLeft:'-=2000px',marginTop:'-=1000px'},1000); } jQuery.fn.teeko_effects_hide = function(element_id) { $("#element_hider").animate( {marginLeft:'-=500px'}, 400 ); parent_id = parent_showed; parent_showed = false; $("#"+element_id+" .resizable:not(#"+parent_id+"):not(#"+parent_id+" *)").animate({marginLeft:'+=2000px',marginTop:'+=1000px'},1000); } /** * Teeko Framework Javascript class * * @copyright (C) 2009 Webisti Oy. All rights reserved * @version 1.0 * @author Tomi Tuovinen */ function AddBookmark() { var title = document.title; var pairs = location.href.split( "#" ); var url = pairs[0]; if (window.sidebar) { // Mozilla Firefox Bookmark window.sidebar.addPanel(title, url,""); } else if( window.external ) { // IE Favorite window.external.AddFavorite( url, title); } else if(window.opera && window.print) { // Opera Hotlist return true; } } function getUnixTimestamp() { return Math.round(new Date().getTime() / 1000); } function addslashes(str) { if(str) { str=str.replace(/\\/g,'\\\\'); str=str.replace(/\'/g,'\\\''); str=str.replace(/\"/g,'\\"'); str=str.replace(/\0/g,'\\0'); return str; } } function stripslashes(str) { str=str.replace(/\\'/g,'\''); str=str.replace(/\\"/g,'"'); str=str.replace(/\\0/g,'\0'); str=str.replace(/\\\\/g,'\\'); return str; } function Error(errortype, efunction, edescription) { var ErrorArr = {}; ErrorArr.scripttype = 'JAVASCRIPT'; // 1=Javascript in Database errorhandler_scripttypes ErrorArr.errortype = errortype; // Database errorhandler_errortypes ErrorArr.file = ''; // Tähän tulee file missä errori on tapahtunut.. miten sen sais automaattisesti? ErrorArr.efunction = efunction; ErrorArr.description = edescription; ErrorArr.trace = ''; // PHP:llä saadaan mukavasti Trace mut mites javascriptillä?!? Request('function/error/SetError', "{'method':'get'}", ErrorArr); } function CreateNewElements(direction) { $('#background *').animate({left:'-300px'},300, 'linear', function() { $('#background *').hide(); Request('function/XML/GetElement',"{'async':false, 'append':'true', 'dest':'background', 'method':'get'}","{'xml':'<?xml version="1.0" encoding="UTF-8"?><template id="Button"> <img><attribute class="resizable"/><attribute src="sites/ilmoitustaulu/images/postit/postit_1_blue_2.png"/><css top="50px"/><css z-index="20"/><css right="-300px"/><css position="absolute"/><css width="100px"/><css height="100px"/></img> </template>'}"); Request('function/XML/GetElement',"{'async':false, 'append':'true', 'dest':'background', 'method':'get'}","{'xml':'<?xml version="1.0" encoding="UTF-8"?><template id="Button"> <img><attribute class="resizable"/><attribute src="sites/ilmoitustaulu/images/postit/postit_2_green_2.png"/><css top="400px"/><css z-index="20"/><css right="-300px"/><css position="absolute"/><css width="100px"/><css height="100px"/></img> </template>'}"); Request('function/XML/GetElement',"{'async':false, 'append':'true', 'dest':'background', 'method':'get'}","{'xml':'<?xml version="1.0" encoding="UTF-8"?><template id="Button"> <img><attribute class="resizable"/><attribute src="sites/ilmoitustaulu/images/polaroid/polaroid1.png"/><css top="80px"/><css z-index="20"/><css left="-300px"/><css position="absolute"/><css width="100px"/><css height="100px"/></img> </template>'}"); $('#background *').animate({right:'300px'},300); } ); } function CheckSiteLogin(json_func_settings, element) { var onErrorFunction = json_func_settings['onError']; var onSuccessFunction = json_func_settings['onSuccess']; var XHR = Request("function/db/CheckLogin", '{method:"get","async":"false"}', element); try { if (XHR.status == 200) { var data = XHR.responseText; if(dest_id && data == 'true') { if(onSuccessFunction) { //Request(act,'{dest:"'+dest_id+'", method:"post"}'); eval(onSuccessFunction); } return true; } else { if(onErrorFunction) { //Request(act,'{dest:"'+dest_id+'", method:"post"}'); eval(onErrorFunction); } return false; } } else {} } catch(ex) {} } function include(filename) { var head = document.getElementsByTagName('head')[0]; script = document.createElement('script'); script.src = filename; script.type = 'text/javascript'; // DEBUG: tässä pitäis tarkistaa onko filenamessa jotain ja palauttaa true tai false // niin että GetElementClasses.js luokassa ei yritetä ees tehä uutta luokkaa jos siinä ei oo // tiedostoa olemassa head.appendChild(script); return true; }