Skip to content

Commit

Permalink
Add more stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
rstacruz committed Dec 8, 2012
1 parent 32f6283 commit d93eaee
Show file tree
Hide file tree
Showing 5 changed files with 221 additions and 6 deletions.
5 changes: 4 additions & 1 deletion README.textile
Expand Up @@ -11,10 +11,13 @@ These plugins make great 'starting points' for whatever you'll need. Take them a
| "Ajax Submit"://github.com/rstacruz/jquery-stuff/tree/master/ajaxsubmit | Submits a form via AJAX instead of a page load |
| "Anchorjump"://github.com/rstacruz/jquery-stuff/tree/master/anchorjump | Make anchor links scroll smoothly |
| "Autogrow"://github.com/rstacruz/jquery-stuff/tree/master/autogrow | Automatically makes text fields vertically grow in size |
| "ButtonLoading"://github.com/rstacruz/jquery-stuff/tree/master/buttonloading | Show 'loading...' text on buttons |
| "Cycler"://github.com/rstacruz/jquery-stuff/tree/master/cycler * | Cycles through a list (lightweight carousel/slideshow) |
| "Console Shim"://github.com/rstacruz/jquery-stuff/tree/master/console-shim * | Makes `console.log()` silently fail if the browser doesn't support it |
| "Ellipsify"://github.com/rstacruz/jquery-stuff/tree/master/ellipsify | Truncates text with ellipses |
| "Ensurevisible"://github.com/rstacruz/jquery-stuff/tree/master/ensurevisible | Scrolls a pane to reveal a given item. |
| "Ensurevisible"://github.com/rstacruz/jquery-stuff/tree/master/ensurevisible | Scrolls a pane to reveal a given item |
| "Fadeonload"://github.com/rstacruz/jquery-stuff/tree/master/fadeonload | Fades images in on load |
| "Fillsize"://github.com/rstacruz/jquery-stuff/tree/master/fillsize | Makes an element fill up its container |
| "Growl"://github.com/rstacruz/jquery-stuff/tree/master/growl | Lightweight notification library |
| "Instance"://github.com/rstacruz/jquery-stuff/tree/master/instance | Lightweight views |
| "Placeholder"://github.com/rstacruz/jquery-stuff/tree/master/placeholder | Input text placeholders, fork of Vadim Sitel's work |
Expand Down
91 changes: 91 additions & 0 deletions buttonloading/jquery.buttonloading.js
@@ -0,0 +1,91 @@
/*! jQuery.buttonLoading (c) 2012, Rico Sta. Cruz. MIT License.
* https://github.com/rstacruz/jquery-stuff/tree/master/buttonloading */

// Show 'loading...' text on buttons.
//
// Quick setup
// -----------
//
// Add a `data-loading-text` attribute to your buttons:
//
// <button type='submit' data-loading-text='Saving...'>Save</button>
//
// Now toggle the state using:
//
// $('button').showButtonLoading();
// $('button').hideButtonLoading();
//
// Recommended usage
// -----------------
//
// You can activate this automatically:
//
// $('form').on('submit', function() {
// this.find(':submit').showButtonLoading();
// });
//
// How it works
// ------------
//
// This swaps the text with the given loading text, disables the button, and
// adds a the `loading` class.

(function($) {
$.fn.toggleButtonLoading = function() {
return this.is(':disabled') ?
this.hideButtonLoading() :
this.showButtonLoading();
};

$.fn.showButtonLoading = function() {
var $button = this;
var label;

// Sanity check
if ($button.is(':disabled')) return;

// Get the alt label
var alt = $button.data('loadingText');

// Swap
if ($button.is('input')) {
label = $button.attr('value');
$button.attr('value', alt);
} else {
label = $button.html();
$button.html(alt);
}

// Save the old
$button.data('originalText', label);

// Attr
$button.attr('disabled', true);
$button.addClass('loading');

return this;
};

$.fn.hideButtonLoading = function() {
var $button = this;

// Sanity check
if (!$button.is(':disabled')) return;

// Get the alt label
var alt = $button.data('originalText');

// Swap
if ($button.is('input')) {
$button.attr('value', alt);
} else {
$button.html(alt);
}

// Attr
$button.removeAttr('disabled');
$button.removeClass('loading');

return this;
};
})(jQuery);
41 changes: 41 additions & 0 deletions fadeonload/jquery.fadeonload.js
@@ -0,0 +1,41 @@
// Fades an image in on load.
//
// $('.wallpaper img').fadeonload();
//
// The image doesn't have to be in the DOM at time of calling.
//
// It would be best if the image has `opacity: 0` in the CSS as well so there
// won't be a "flash of visible image".
//
(function($) {

$.fn.fadeonload = function() {
var $image = this;

$(function() {
$image.each(function() {
var $image = $(this);

if (this.complete) {
$image.trigger('load');
} else {
$image.css({ opacity: 0 });
}
});
});

this.on('load', function() {
var $image = $(this);

$image
.show()
.css({ opacity: 0 });

setTimeout(function() {
$image.css({ opacity: 1, transition: 'opacity 400ms linear' });
}, 25);
});

return this;
};
})(jQuery);
70 changes: 70 additions & 0 deletions fillsize/jquery.fillsize.js
@@ -0,0 +1,70 @@
/*! fillsize (c) 2012, Rico Sta. Cruz. MIT License.
* http://github.com/rstacruz/jquery-stuff/tree/master/fillsize */

// Makes an element fill up its container.
//
// $(".container").fillsize("> img");
//
// This binds a listener on window resizing to automatically scale down the
// child (`> img` in this example) just so that enough of it will be visible in
// the viewport of the container.
//
// This assumes that the container has `position: relative` (or any 'position',
// really), and `overflow: hidden`.

(function($) {
$.fn.fillsize = function(selector) {
var $parent = this;
var $img;

function resize() {
if (!$img) $img = $parent.find(selector);

var imageRatio = $img.width() / $img.height();
var containerRatio = $parent.width() / $parent.height();

// If image is wider than the container
if (imageRatio > containerRatio) {
$img.css({
'position': 'absolute',
'left': Math.round(($parent.width() - imageRatio * $parent.height()) / 2) + 'px',
'top': '0',
'right': 'auto',
'bottom': 'auto',
'width': 'auto',
'height': '100%'
});
}

// If the container is wider than the image
else {
$img.css({
'position': 'absolute',
'top': Math.round(($parent.height() - ($parent.width() / $img.width() * $img.height())) / 2) + 'px',
'left': '0',
'right': 'auto',
'bottom': 'auto',
'height': 'auto',
'width': '100%'
});
}
}

// Make it happen on window resize.
$(window).on('resize', resize);

// If the child is an image, fill it up when image's real dimensions are
// first determined.
$(selector, $parent).on('load', function() {
setTimeout(resize, 25);
});

// Allow manual invocation by doing `.trigger('fillsize')` on the container.
$parent.on('fillsize', resize);

// Resize on first load.
$(resize);

return this;
};
})(jQuery);
20 changes: 15 additions & 5 deletions uiscreen/jquery.uiscreen.js
@@ -1,11 +1,17 @@
// Usage:
//
// /* Full */
// $("body").screen();
//
// /* Single element */
// $("#element").screen();
// $("#element").unscreen();
//
// $.unscreen(); // remove all screens
//
;(function($) {
function resetPosition($screen, $el) {
if ($el.is('body')) return;
$screen
.css({
'top': $el.position().top + parseInt($el.css('margin-top'), 10),
Expand All @@ -23,9 +29,8 @@
$screens: [],

// Options
background: '#555555',
opacity: 0.5,
screen_template: "<div class='uiscreen'><div class='uiscreen-spinner'></div></div>",
opacity: 1.0,
screen_template: "<div class='uiscreen'><div class='uiscreen-screen'></div><div class='uiscreen-spinner'></div></div>",
z_index: 10010,
fadein_time: 250,
fadeout_time: 0,
Expand All @@ -46,6 +51,7 @@
resetPosition($screen, $el);

$el.offsetParent().append($screen);

$screen
.data('parent', $el)
.attr('id', id)
Expand Down Expand Up @@ -100,8 +106,12 @@
})
.hide();

if (this.background)
{ $screen.css({ 'background': this.background }); }
// Fullscreen if body
if ($el.is('body')) {
$screen.css({ 'position': 'fixed',
top: 0, left: 0, width: 'auto', height: 'auto',
right: 0, bottom: 0 });
}

$(document.body).append($screen);
this.$screens.push($screen);
Expand Down

0 comments on commit d93eaee

Please sign in to comment.