Skip to content

Instantly share code, notes, and snippets.

@meotimdihia
Created September 19, 2010 03:33
Show Gist options
  • Save meotimdihia/586338 to your computer and use it in GitHub Desktop.
Save meotimdihia/586338 to your computer and use it in GitHub Desktop.
$(function(){
$("#flashMessage,#authMessage").hide();
// $("#flashMessage").css('left', ( $(window).width()-$("#flashMessage").outerWidth()) /2 );
$("#flashMessage,#authMessage").css('top', 0).css('left',0);
$("#flashMessage,#authMessage").slideDown('fast');
setTimeout(function(){
$("#flashMessage,#authMessage").slideUp('slow')
},10000);
// $(":submit").click(function(){
// $(this).closest("form").submit();
// $(this).attr('disabled','disabled');
// });
$("form").submit(function(){
$(this).find(":submit").attr('disabled','disabled');
});
$("<div/>",{
"id":"ajaxloading",
"style":"background-color:yellow;padding:7px 15px;border-radius: 5px;-moz-border-radius: 5px;-webkit-border-radius: 5px;box-shadow: 5px 5px 2px black; -moz-box-shadow: 2px 2px 2px #CCC; -webkit-box-shadow: 2px 2px 2px #CCC;z-index:999;"
}).appendTo("body");
$("#ajaxloading").hide();
$("#ajaxloading").css('position','fixed').html("<b>Now Loading ...</b>")
.css('left',($(window).width()-$("#ajaxloading").outerWidth())/2)
.css('top',($(window).height()-$("#ajaxloading").outerWidth())/2);
});
$(function(){
/**
*POP UP BOX
*/
$.fn.popBox = function(options){
var target= options.target;
var trigger = this;
function _showOverlay(target,trigger){
$(trigger).click(function(){
$('<div>',{
id:'overlay',
css:{
width:"100%",
height:"100%",
left:0,
top:0,
position:"fixed",
"z-index":1000,
"background-color":"#222",
opacity:0.3
}
}).hide().appendTo(document.body).fadeIn(100);
$(target).fadeIn(100);
return false;
});
}
function _hideOverlay(target){
$('body').delegate('#overlay','click',function(){
$('#overlay').fadeOut(100,function(){
$(target).fadeOut(100);
$(this).remove();
});
});
}
_showOverlay(target,trigger);
_hideOverlay(target);
};
$.fn.checkedAll = function(){
$(this).click(function(){
form = $(this).closest('form');
if (form.find('input:checkbox').attr('checked') == ""){
$(form).find('input:checkbox').attr('checked','checked');
}else{
$(form).find('input:checkbox').attr('checked','');
}
return false;
});
};
/**
* PREVIEW IMAGE
*/
$.fn.previewImg = function(options){
var options = $.extend({
'removeOld':true,
'event':'click'
},options);
var xOffset =5;
var yOffset = 15;
if (options.event == 'hover'){
$(this).hover(function(e){
_showPreview(e);
},
function(){
this.title = this.t;
$("#screenshot").remove();
});
$(this).mousemove(function(e){
$("#screenshot")
.css("top",(e.pageY + yOffset) + "px")
.css("left",(e.pageX + xOffset) + "px");
});
}
if (options.event =='click'){
$(this).bind('click',_showPreview);
}
$(this).click(function(){
return false
});
function _showPreview(e){
if (options.event == 'click' && options.removeOld == false){
idscreenshot = Math.floor(Math.random()*30000);
}else{
$("#screenshot").remove();
idscreenshot = 'screenshot'
};
e.currentTarget.t = e.currentTarget.title;
e.currentTarget.title = "";
var c = (e.currentTarget.t != "") ? "<br/><div style='text-align:center'>" + e.currentTarget.t+"</div>" : "";
$("body").append("<div id='"+idscreenshot+"' class='screenshot' class='position:absolute;border:1px solid #ccc;background:#333;padding:5px;display:none;color:#fff;'><img src='"+ e.currentTarget.href +"' alt='url preview' />"+ c +"</div>");
$("#"+idscreenshot).css({
position:"absolute",
border:"1px solid #ccc",
background:"#333",
"box-shadow":"5px 5px 2px #CCC",
"-moz-box-shadow": "2px 2px 2px #CCC",
"-webkit-box-shadow": "4px 4px 4px #CCC",
padding:"5px",
display:'none',
color:"#fff",
cursor:"pointer"
})
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn("fast");
$("#"+idscreenshot).click(function(){
$(this).remove();
});
}
}
/**
* TOOL TIP
*/
$.fn.tooltip = function(){
xOffset =5;
yOffset = 10;
if ($(this).attr('title').length > 0){
$(this).hover(function(e){
idtooltip = Math.floor(Math.random()*30000);
this.t = this.title;
this.title = '';
$("body").append("<p id='"+idtooltip+"'>"+ this.t +"</p>");
$("#"+idtooltip).css({
position:"absolute",
border:"1px solid #333",
background:"#f7f5d1",
"box-shadow":"5px 5px 2px #CCC",
"-moz-box-shadow": "2px 2px 2px #CCC",
"-webkit-box-shadow": "2px 2px 2px #CCC",
padding:"2px 5px",
color:"#333",
display:"none"
})
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px")
.fadeIn(100);
},
function(){
this.title = this.t;
$("#"+idtooltip).fadeOut('100',function(){
$(this).remove();
});
});
$(this).mousemove(function(e){
$("#"+idtooltip)
.css("top",(e.pageY - xOffset) + "px")
.css("left",(e.pageX + yOffset) + "px");
});
}
}
});
/**
* CENTER
*/
$.fn.equalWmargin = function(){
$(this).css('left',($(window).width()-$(this).outerWidth())/2);
}
$.fn.equalHmargin = function(){
$(this).css('top',($(window).height()-$(this).outerHeight())/2);
}
$.fn.equalMargin = function(){
$(this).css('top',($(window).height()-$(this).outerHeight())/2);
$(this).css('left',($(window).width()-$(this).outerWidth())/2);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment