This project is archived and is in readonly mode.

#919 ✓wontfix
AHHP

Suggesting 2 methods: Number.between() & Element.getFullSize()

Reported by AHHP | June 1st, 2010 @ 11:23 AM

Hi,
I've created two methods below for my works because are very handy for me and may help others.
These are not general and perfect, and should develop.

/
 * Check for a number to be between of two numbers
 *
 * @param number min Minimum number
 * @param number max Maximum number
 * @param mixed equals Set to includes min, max in checking
 * @return boolean
/
Number.implement({
 between: function(min, max, equals) {
  return equals ? (this >= min && this <= max) : (this > min && this < max);
 }
});
/
 Usage
/
var year = new Date().getFullYear();
if(year.between(2009, 2011, '=')) {
 // do something nice
}
/
 * Get outer width/height of an element
 *
 * @param string property ['height'|'width'] to return specified property. Default to 'width'.
 * @return integer
/
Element.implement({
 getFullSize: function(property) {
  var property = (property == 'height' || property == 'width')  ? property : 'width';
  var styles = {
   width: ['width', 'margin-left', 'margin-right', 'padding-left', 'padding-right', 'border-left-width', 'border-right-width'],
   height: ['height', 'margin-top', 'margin-bottom', 'padding-top', 'padding-bottom', 'border-top-width', 'border-bottom-width']
  };
  var size = 0;
  styles[property].each(function(style){
   size += this.getComputedStyle(style).toInt();
  }, this);
  return size;
 }
});
/
 Usage
/
var maxHeight = document.id('element').getFullSize('height');
var minHeight = document.id('element').getFullSize('width');

Cheeers,
AHHP

Comments and changes to this ticket

  • AHHP

    AHHP June 1st, 2010 @ 11:57 AM

    • Title changed from “Suggest two methods: Number.between() & Element.getFullSize()” to “Suggesting 2 methods: Number.between() & Element.getFullSize()”
  • Christoph Pojer

    Christoph Pojer June 3rd, 2010 @ 01:51 PM

    • State changed from “new” to “wontfix”

    Hello,

    MooTools makes it easy for you to extend the native types in JavaScript to create a custom methods. The goal of MooTools Core is to stay lightweight and to only provide the most important features. Feel free to create a plugin and add it to the Forge ( http://mootools.net/forge ).

    Also note that your proposed "Number.between" method already exists in MooTools Core under the name "limit" (see http://mootools.net/docs/core/Native/Number#Number:limit )

  • Sebastian Markbåge

    Sebastian Markbåge June 3rd, 2010 @ 02:06 PM

    No, the proposed Number.between checks whether a value is within a range resulting in a Boolean. The existing Number.limit results in a Number within the range.

    IMO, getFullSize should be implemented in 2.0 (if it isn't already, can't remember). Although with the plain syntax: element.getStyle('width', 'px'). It may already work in kamicane's personal branch.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Shared Ticket Bins

Pages