Skip to content

Commit

Permalink
every function extend from $.catface
Browse files Browse the repository at this point in the history
  • Loading branch information
jney committed Oct 23, 2008
1 parent 57c8336 commit 15d261f
Showing 1 changed file with 62 additions and 61 deletions.
123 changes: 62 additions & 61 deletions jquery.catface.js
Original file line number Diff line number Diff line change
@@ -1,64 +1,65 @@
/*
* Catface (for jQuery)
* version: 1.0 beta
* @requires jQuery v1.2 or later
*
* Licensed under the MIT:
* http://www.opensource.org/licenses/mit-license.php
*
* catface is fishcat + facebox
* Is almost like facebox see it at : http://famspam.com/facebox
*
* Usage:
*
* jQuery(document).ready(function($) {
* $('a[rel*=catface]').catface()
* })
*
* <a href="#terms" rel="catface">Terms</a>
* Loads the #terms div in the box
*
* <a href="terms.html" rel="catface">Terms</a>
* Loads the terms.html page in the box
*
* <a href="terms.png" rel="catface">Terms</a>
* Loads the terms.png image in the box
*
*
* You can also use it programmatically:
*
* jQuery.catface('some html')
*
* This will open a facebox with "some html" as the content.
*
* jQuery.catface(function($) { $.ajaxes() })
*
* thanks too err team : http://errtheblog.com/
*/
// =======================================================================
// Catface (for jQuery)
// version: 1.0 beta
// @requires jQuery v1.2 or later
//
// Licensed under the MIT:
// http://www.opensource.org/licenses/mit-license.php
//
// catface is fishcat + facebox
// Is almost like facebox see it at : http://famspam.com/facebox
//
// Usage:
//
// jQuery(document).ready(function($) {
// $('a[rel*=catface]').catface();
// });
//
// <a href="#terms" rel="catface">Terms</a>
// Loads the #terms div in the box
//
// <a href="terms.html" rel="catface">Terms</a>
// Loads the terms.html page in the box
//
// <a href="terms.png" rel="catface">Terms</a>
// Loads the terms.png image in the box
//
//
// You can also use it programmatically:
//
// jQuery.catface('some html')
//
// This will open a facebox with "some html" as the content.
//
// jQuery.catface(function($) { $.ajaxes() })
//
// thanks too err team : http://errtheblog.com/
// =======================================================================

(function($) {

$.catface = function(data, settings) {
$.catface_init();
$.catface.init();
if(data.match(/\S/)){
$.catface_loading();
$.isFunction(data) ? data.call(this, $) : $.catface_open(data, settings);
$.catface.loading();
$.isFunction(data) ? data.call(this, $) : $.catface.open(data, settings);
}
return $;
};

$.catface.settings = {
loading_image : '/images/catface/loading.gif',
close_image : '/images/catface/close.png',
loading_image : 'catface/loading.gif',
close_image : 'catface/close.png',
html : '\
<div id="catface" style="display:none">\
<div class="body" style="position:relative;z-index:100">\
<a href="#" class="close" style="border:0;position:absolute;right:4px;top:4px">\
<img src="/images/catface/close.png" alt="X" style="border:0"/>\
<img src="../catface/close.png" alt="X" style="border:0"/>\
</a>\
<div class="content"></div>\
</div>\
<div class="loading" style="text-align:center">\
<img src="/images/catface/loading.gif" style="margin:auto;padding:10px 20px" alt="loading" />\
<img src="../catface/loading.gif" style="margin:auto;padding:10px 20px" alt="loading" />\
</div>\
</div>'
};
Expand All @@ -68,10 +69,10 @@
};

$.fn.catface = function(settings) {
$.catface_init(settings);
$.catface.init(settings);
var click_handler = function() {
if ($('#catface .loading:visible').length == 1) return false;
$.catface_loading();
if ($('#catface .loading:visible').length) return false;
$.catface.loading();
// div
if (this.href.match(/#/)) {

Expand All @@ -85,11 +86,11 @@
if(k.length==2) $.catface.settings[k[0]] = k[1];
}
// ary[0] is the target
$.catface_open($(ary[0]).clone().show());
$.catface.open($(ary[0]).clone().show());
// ajax
} else {
try {
$.get( this.href, function(data) { $.catface_open(data); } );
$.get( this.href, function(data) { $.catface.open(data); } );
} catch(e) { alert(e); }
}
return false;
Expand All @@ -101,8 +102,8 @@
* The init function is a one-time setup which preloads vital images
* and other niceities.
*/
$.catface_init = function(settings) {
if($.catface.settings.inited && typeof settings == 'undefined');
$.catface.init = function(settings) {
if($.catface.settings.inited && typeof settings == 'undefined')
return true;

$.catface.settings.inited = true;
Expand All @@ -115,7 +116,7 @@
if(typeof $.catface.running == "undefined")
$.catface.running = false;

if($("#catface") && $("#catface").length > 0)
if($("#catface") && $("#catface").length)
return true;

$.catface.settings.ie6 = (!window.XMLHttpRequest);
Expand Down Expand Up @@ -147,21 +148,21 @@
$('#catface .close_image').attr('src', $.catface.settings.close_image);
};

$.catface_loading = function() {
if ($('#catface .loading:visible').length == 1) return true;
$.catface.loading = function() {
if ($('#catface .loading:visible').length) return true;
$(document).unbind('.catface');
$('#catface .content').empty().hide();
$('#catface .loading').show();
$('#catface').slideDown('slow');

$(document).bind('keydown.catface', function(e) {
if (e.keyCode == 27) $.catface_close();
if (e.keyCode == 27) $.catface.close();
});
};

$.catface_open = function(data, settings, extra_setup) {
$.catface.open = function(data, settings, extra_setup) {
// return if no data
if(!data.match(/\S/)) return $.catface_close();
if(!data.match(/\S/)) return $.catface.close();
// deal with the settings
var $s = $.catface.settings; $.extend($s, (settings || {}));
$('#catface .content').append(data);
Expand All @@ -179,19 +180,19 @@
!$.catface.timing ? ($.catface.timing = true) : ($.catface.running = true);
setTimeout(function(){
if(!$.catface.running && !$.catface.loading()){
$.catface_close(); $.catface.timing = false;
$.catface.close(); $.catface.timing = false;
} else $.catface.running = false ;
}, $s.time * 1000);
} else { $.catface.running = true; }

// finally we bind close events
$('#catface .close').
bind('click.catface',$.catface_close);
bind('click.catface',$.catface.close);
$('#catface .submit').
bind('click.catface',function(){$.catface_close(true);});
bind('click.catface',function(){$.catface.close(true);});
};

$.catface_close = function(rtn) {
$.catface.close = function(rtn) {
if(typeof rtn != "boolean") rtn = false;
$(document).unbind('.catface');
$('#catface').slideUp(function(){
Expand Down

0 comments on commit 15d261f

Please sign in to comment.