10 Best Things « visit
This is my Source Code and I don't want to show it here
View Source Code only (as overlay)
// That code snippet belongs to 10 Best Things - http://10bestthings.com
//10best Global
(function($){
$("#modalContainer .modal-close").live("click",function(e){ $("#modalContainer").dialog("destroy").remove(); $(".ui-custom-overlay").remove(); e.preventDefault(); });
var flashMessage = function(type,message){
alert(message);
};
$.tbModals = function (modalType, options) {
return $.tbModals.impl.init(modalType, options);
};
$.tbModals.defaults = {
wrapTop: '<div><div class="modalWrap"><div class="modalInner"><div class="modalCurrentSlide">',
wrapBottom: '</div></div></div><div class="modalFoot"></div></div>',
tempWrapTop: '<div class="newInner">',
tempWrapBottom: '</div>'
};
$.tbModals.impl = {
init: function(modalType,options){
this.options = $.extend({}, $.tbModals.defaults, options);
this.modalContainer = null;
this.setUpModalSlide(modalType,"init");
$('<div class="ui-custom-overlay"></div>').appendTo("body").height($("body").height()).width($("body").width());
},
handleError:function(message){
this.modalContainer.find(".modalInner .error").remove();
$('<div class="error">'+message+'</div>').insertAfter(this.modalContainer.find(".modalInner legend"));
},
setUpModalSlide: function(modalType, action){
var tbModal = this;
switch(modalType){
case "login":
$.get("/ajaxcontent/modalLogin",{}, function(data){
var setUpScript = function(){
$("#loginIframe").data("finishFunction",tbModal.options.finishFunction).load(function(){
if($(this).contents().text().replace(/^\s+|\s+$/g,"")=='parent.document.getElementById("overallModalContainer").style.display="none";'){
if(typeof(tbModal.options.finishFunction)!="undefined"){
tbModal.options.finishFunction();
}
}
else{
modalForm = $(this).contents().find("form");
modalForm.find("a.modal-submit").click(function(e){ modalForm.submit(); return false; });
modalForm.find(":input").keydown(function(e){ if(e.which==13){ modalForm.submit(); return false;} });
modalForm.find("a.modal-signup").click(function(e){ tbModal.setUpModalSlide("signUp"); return false; });
modalForm.find("a.forgot-password").click(function(e){ tbModal.setUpModalSlide("forgotPassword"); return false; });
$(this).contents().find(".modal-close").click(function(e){ $("#modalContainer").dialog("destroy").remove(); $(".ui-custom-overlay").remove(); e.preventDefault(); });
}
});
};
tbModal.switchModalSlide(data,setUpScript);
},"html");
break;
case "forgotPassword":
$.get("/ajaxcontent/modalForgotPassword",{}, function(data){
var setUpScript = function(){
var modalForm = $("#modalContainer").find("form");
modalForm.submit(function(e){
tbModal.modalContainer.find(".modalInner .error").remove();
var params = $(this).serialize();
$.post($(this).attr("action"),params,function(data){
if(data.success){
tbModal.setUpModalSlide("forgotPasswordSuccess");
}
else{
tbModal.handleError(data.errorMessage);
}
},"json");
return false;
});
modalForm.find("a.modal-submit").click(function(e){ modalForm.submit(); e.preventDefault(); });
};
tbModal.switchModalSlide(data,setUpScript);
},"html");
break;
case "forgotPasswordSuccess":
$.get("/ajaxcontent/modalForgotPasswordSuccess",{"modalType":"forgotPasswordSuccess"}, function(data){
var setUpScript = function(){
$("#modalContainer .returnToSignIn").click(function(e){
tbModal.setUpModalSlide("login");
e.preventDefault();
});
};
tbModal.switchModalSlide(data, setUpScript);
},"html");
break;
case "signUp":
$.get("/ajaxcontent/modalSignup",{}, function(data){
var setUpScript = function(){
var modalForm = $("#modalContainer").find("form");
modalForm.submit(function(e){
tbModal.modalContainer.find(".modalInner .error").remove();
var params = $(this).serialize();
$.post($(this).attr("action"),params,function(data){
if(data.success){
if(typeof(tbModal.options.finishFunction)!="undefined"){
tbModal.options.finishFunction();
}
}
else{
tbModal.handleError(data.errorMessage);
}
},"json");
return false;
});
modalForm.find("a.modal-submit").click(function(e){ modalForm.submit(); e.preventDefault(); });
modalForm.find(":input").keydown(function(e){ if(e.which==13){ modalForm.submit(); e.preventDefault(); } });
modalForm.find("a.checkAvailability").click(function(e){
var modalFormi = modalForm;
$.post("/signup/isAvailable",{"username":modalFormi.find(".userName").val()},function(data){
modalFormi.find(".isAvailable").text(data.isAvailable?"Available!":"Not available");
},"json");
e.preventDefault();
});
};
tbModal.switchModalSlide(data,setUpScript);
},"html");
break;
case "newList":
$.get("/ajaxcontent/modalNewList",{},function(data){
var setUpScript = function(){
var modalForm = $("#modalContainer").find("form");
modalForm.find("a.modal-submit").click(function(e){ modalForm.submit(); e.preventDefault(); });
modalForm.find(":input").keydown(function(e){ if(e.which==13){ modalForm.submit(); e.preventDefault();} });
};
tbModal.switchModalSlide(data,setUpScript);
},"html");
break;
case "remakeList":
$.get("/ajaxcontent/modalRemakeList",{},function(data){
var setUpScript = function(){
$("#modalContainer").find("span.listTitle").text(tbModal.options.listTitle);
$("#modalContainer").find("span.listAuthor").text(tbModal.options.listAuthor);
$("#modalContainer .listID").val(tbModal.options.listID);
var lh = $("#modalContainer .newListOption").height();
var rh = $("#modalContainer .newListOption.r").height();
if(lh>rh){
$("#modalContainer .newListOption.r").height(lh);
}
else{
$("#modalContainer .newListOption").height(rh);
}
$("#modalContainer .submitA").click(function(){
if($(this).hasClass("blankListA")){
$("#modalContainer .blankList").val("true");
}
$("#modalContainer .remakeForm").submit();
return false;
});
};
tbModal.switchModalSlide(data, setUpScript);
},"html");
break;
}
},
switchModalSlide: function(slideHTML,setUpScript){
if(this.modalContainer==null){
this.modalContainer = $(this.options.wrapTop+slideHTML+this.options.wrapBottom)
.dialog({bgiframe: true,resizable:false,width:488})
.attr("id","modalContainer");
$(".ui-dialog").attr("id","overallModalContainer");
if(typeof(setUpScript)!="undefined"){
setUpScript();
}
}
else{
var newSlide = $(this.options.tempWrapTop+slideHTML+this.options.tempWrapBottom);
var tbModal = this;
this.modalContainer.find(".modalInner .modalCurrentSlide").slideUp("normal",function(){
newSlide.hide().appendTo(tbModal.modalContainer.find(".modalInner")).slideDown("slow", function(){
$(this).siblings(".modalCurrentSlide").remove();
$(this).removeClass("newInner").addClass("modalCurrentSlide");
if(typeof(setUpScript)!="undefined"){
setUpScript();
}
});
});
}
}
};
$.tbFollow = function (options) {
return $.tbFollow.impl.init(options);
};
$.tbFollow.impl = {
init: function(options){
var fThis = this;
$("#follow .followThis, #followUser .followThis").live("click",function(){
$.tbFollow.impl.follow(options,$(this));
return false;
});
$("#follow .unfollow, #followUser .unfollow").live("click",function(){
$.tbFollow.impl.unfollow(options, $(this));
return false;
});
},
follow:function(options,theLink){
if(typeof(options.listID)=="undefined"){
var url = "/profile/";
var f = "person";
}
else{
var url = "/list/";
var f = "list";
}
$.post(url+"follow",options,function(data){
if(data.success){
$(theLink).closest(".notFollowing").replaceWith(
$('<div class="following"><h4>You are following this ' + f + '.</h4>(<a href="' + url + 'unfollow" class="unfollow">unfollow</a>)</div>')
);
}
else{
if(typeof(data.errorMessage)=="undefined"){
flashMessage("error","There was an error");
}
else{
flashMessage("error", data.errorMessage);
}
}
},"json");
},
unfollow: function(options,theLink){
if(typeof(options.listID)=="undefined"){
var url = "/profile/";
var f = "person";
}
else{
var url = "/list/";
var f = "list";
}
$.post(url+"unfollow",options,function(data){
if(data.success){
$(theLink).closest(".following").replaceWith(
$('<div class="notFollowing"><a href="'+url+'follow" class="followThis">Follow this '+f+'</a></div>')
);
}
else{
if(typeof(data.errorMessage)=="undefined"){
flashMessage("error","There was an error");
}
else{
flashMessage("error", data.errorMessage);
}
}
},"json");
}
};
$.tbListTools = function (options) {
return $.tbListTools.impl.init(options);
};
$.tbListTools.defaults = { runModalLogin: false };
$.tbListTools.impl = {
init: function(options){
this.options = $.extend({}, $.tbListTools.defaults, options);
var options = this.options;
switch(options.section){
case "comments":
if($("#content").hasClass("isAnimating")){
}
else{
$("#content").addClass("isAnimating");
if($("#content").hasClass("commentsActive")){
$("#viewSidebar .tempList").slideUp("normal",function(){ $(this).remove(); });
$("#commentsContent").slideUp("normal",function(){
$("#listContent").slideDown("normal", function(){
$("#content").removeClass("commentsActive").removeClass("isAnimating");
$("#listTools .comments").removeClass("active");
if(options.el.attr("href")!="#"){
window.location = options.el.attr("href");
}
});
});
}
else{
$("#listContent").slideUp("normal",function(){
var con = $('<div class="tempList"></div>').append($('<h2></h2>').text($("#content .mainContent h2").text()));
var tempList = $('<ul class="theList"></ul>');
$("#theList").children().each(function(){
$('<li></li>')
.append($(this).find("span.index").clone())
.append($("<h3></h3>").append('<a></a>').find("a").text($(this).find("h3").text()).attr("href","#"+$(this).attr("id")).end())
.appendTo(tempList);
});
con.append(tempList).hide().prependTo("#viewSidebar").slideDown("normal");
$("#commentsContent").slideDown("normal",function(){ $("#content").addClass("commentsActive").removeClass("isAnimating");});
});
$("#listTools .comments").addClass("active");
var el = options.el;
if(options.runModalLogin){
if($(".commentForm").data("submitSet")!=true){
$(".commentForm").submit(function(){
$.tbModals("login",{finishFunction:function(){$(".commentForm").unbind("submit").submit();}});
return false;
});
$(".commentForm").data("submitSet",true);
}
}
}
}
break;
}
}
};
$.fn.tbAvatarUpload = function(userOptions) {
return this.each(function() {
var options = {};
options = $.extend({}, userOptions, options);
var params = options.params;
var parentDl = $(this);
var fileInput = parentDl.find(".file");
var cab = parentDl.find(".cabinet");
var loading = parentDl.find(".loading");
var message = parentDl.find(".message");
var avatar = parentDl.find(".avatar .avatarImage");
fileInput.change(function(){
cab.hide();
loading.show();
message.empty();
$.ajaxFileUpload(
{
url:'/file/uploadAvatar',
secureuri:false,
fileElementId:'userFile',
dataType: 'json',
formElements: params,
oldFileElement: fileInput,
success: function (data, status)
{
loading.hide();
cab.show();
if(data.success){
avatar.attr("src",data.imageUrl).width(50).height(50);
if(parentDl.find(".remove").length==0){
parentDl.find("dd div.avatar").append('<span><a href="#" class="remove">Remove</a></span>');
}
}
else{
message.text("Sorry, we had a problem with this upload ("+data.errorMessage+").");
}
$(document).ajaxError(function(type,message){ alert(message);});
},
error: function (data, status, e)
{
loading.hide();
cab.show();
message.text("Sorry, we had a problem with this upload.");
setTimeout(function(){ $(document).ajaxError(function(type,message){ alert(message);});},1);
}
}
);
});
parentDl.find(".remove").live("click",function(){
var handleBackgroundAction = function(data){
if(typeof(data.success)!="undefined" && data.success==true){
//
}
else{
if(typeof(data.errorMessage)=="undefined"){
flashMessage("error","There was an error");
}
else{
flashMessage("error", data.errorMessage);
}
}
};
if(confirm("Are you sure you want to remove your avatar?")){
avatar.attr("src",options.fallbackSrc);
$(this).remove();
$.post("/profile/removeavatar", params, handleBackgroundAction,"json");
}
return false;
});
});
};
$(function(){
$("#header .login, .profile .log-in").live("click", function(e){
var pLink = $(this);
$.tbModals("login", {finishFunction: function(){ window.location=pLink.attr("href"); }});
e.preventDefault();
});
$("#header .signup, .profile .signup").live("click", function(e){
var pLink = $(this);
$.tbModals("signUp", {finishFunction: function(){ window.location=pLink.attr("href"); }});
e.preventDefault();
});
$("#viewSidebar,#listTools li").hover(
function(){$(this).fadeTo(200,".9999"); },
function(){$(this).fadeTo(200,".5"); }
);
$(".followStar").click(function(){
var href = $(this).attr("href");
var theLink = $(this);
var postData = href.substr(href.indexOf("?")+1);
$.post(href.substr(0,href.indexOf("?")),postData,function(data){
if(data.success){
if(theLink.hasClass("following")){
theLink.removeClass("following").addClass("notFollowing").text("Follow this user").attr("title","Follow this user");
theLink.attr("href", "/profile/follow?"+postData);
}
else{
theLink.removeClass("notFollowing").addClass("following").text("Stop following this user").attr("title","Stop following user");
theLink.attr("href", "/profile/unfollow?"+postData);
}
}
else{
if(typeof(data.errorMessage)=="undefined"){
flashMessage("error","There was an error");
}
else{
flashMessage("error", data.errorMessage);
}
}
},"json");
return false;
});
});
})(jQuery);
Syndicate
Categories
Statistics
There are 330 Sites with 745 Links of Interest in 18 Categories. The latest Site was added 4 months ago.
About
This is a project by Sebastian Senf, for his part jQuery user and lover too. Follow me.