element-utils.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. module.exports = function(options) {
  3. var getState = options.stateHandler.getState;
  4. /**
  5. * Tells if the element has been made detectable and ready to be listened for resize events.
  6. * @public
  7. * @param {element} The element to check.
  8. * @returns {boolean} True or false depending on if the element is detectable or not.
  9. */
  10. function isDetectable(element) {
  11. var state = getState(element);
  12. return state && !!state.isDetectable;
  13. }
  14. /**
  15. * Marks the element that it has been made detectable and ready to be listened for resize events.
  16. * @public
  17. * @param {element} The element to mark.
  18. */
  19. function markAsDetectable(element) {
  20. getState(element).isDetectable = true;
  21. }
  22. /**
  23. * Tells if the element is busy or not.
  24. * @public
  25. * @param {element} The element to check.
  26. * @returns {boolean} True or false depending on if the element is busy or not.
  27. */
  28. function isBusy(element) {
  29. return !!getState(element).busy;
  30. }
  31. /**
  32. * Marks the object is busy and should not be made detectable.
  33. * @public
  34. * @param {element} element The element to mark.
  35. * @param {boolean} busy If the element is busy or not.
  36. */
  37. function markBusy(element, busy) {
  38. getState(element).busy = !!busy;
  39. }
  40. return {
  41. isDetectable: isDetectable,
  42. markAsDetectable: markAsDetectable,
  43. isBusy: isBusy,
  44. markBusy: markBusy
  45. };
  46. };