benjaminvr

Untitled

Jan 18th, 2024
1,013
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /* eslint-disable no-extend-native */
  2.  
  3. // Dienen geschreven te worden middels function(){} syntax om de correcte "this" te kunnen gebruiken
  4. // Bij een arrow function zal "this" anders wijzen naar window
  5. const LoadExtensionMethods = () => {
  6.     Array.prototype.last = function(){
  7.         return this[this.length - 1];
  8.     }
  9.  
  10.     Element.prototype.getInclusiveHeight = function(extraHeight=0){
  11.         const list = [
  12.             'margin-top',
  13.             'margin-bottom',
  14.             'border-top',
  15.             'border-bottom',
  16.             'padding-top',
  17.             'padding-bottom',
  18.             'height'
  19.         ]
  20.    
  21.         const style = window.getComputedStyle(this)
  22.         return list.map(k => parseInt(style.getPropertyValue(k), 10))
  23.                    .reduce((prev, cur) => prev + cur)
  24.                    + extraHeight;
  25.     }
  26. }
  27.  
  28. export default LoadExtensionMethods;
Advertisement
Add Comment
Please, Sign In to add comment