code
stringlengths 24
2.07M
| docstring
stringlengths 25
85.3k
| func_name
stringlengths 1
92
| language
stringclasses 1
value | repo
stringlengths 5
64
| path
stringlengths 4
172
| url
stringlengths 44
218
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
static init(classDef, els, options) {
let instances = null;
if (els instanceof Element) {
instances = new classDef(els, options);
} else if (!!els && (els.jquery || els.cash || els instanceof NodeList)) {
let instancesArr = [];
for (let i = 0; i < els.length; i++) {
instancesArr.push(new classDef(els[i], options));
}
instances = instancesArr;
}
return instances;
} | Initializes components
@param {class} classDef
@param {Element | NodeList | jQuery} els
@param {Object} options | init | javascript | Dogfalo/materialize | js/component.js | https://github.com/Dogfalo/materialize/blob/master/js/component.js | MIT |
constructor(el, options) {
super(Datepicker, el, options);
this.el.M_Datepicker = this;
this.options = $.extend({}, Datepicker.defaults, options);
// make sure i18n defaults are not lost when only few i18n option properties are passed
if (!!options && options.hasOwnProperty('i18n') && typeof options.i18n === 'object') {
this.options.i18n = $.extend({}, Datepicker.defaults.i18n, options.i18n);
}
// Remove time component from minDate and maxDate options
if (this.options.minDate) this.options.minDate.setHours(0, 0, 0, 0);
if (this.options.maxDate) this.options.maxDate.setHours(0, 0, 0, 0);
this.id = M.guid();
this._setupVariables();
this._insertHTMLIntoDOM();
this._setupModal();
this._setupEventHandlers();
if (!this.options.defaultDate) {
this.options.defaultDate = new Date(Date.parse(this.el.value));
}
let defDate = this.options.defaultDate;
if (Datepicker._isDate(defDate)) {
if (this.options.setDefaultDate) {
this.setDate(defDate, true);
this.setInputValue();
} else {
this.gotoDate(defDate);
}
} else {
this.gotoDate(new Date());
}
/**
* Describes open/close state of datepicker
* @type {Boolean}
*/
this.isOpen = false;
} | Construct Datepicker instance and set up overlay
@constructor
@param {Element} el
@param {Object} options | constructor | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
static get defaults() {
return _defaults;
} | Describes open/close state of datepicker
@type {Boolean} | defaults | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Describes open/close state of datepicker
@type {Boolean} | init | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
static _isDate(obj) {
return /Date/.test(Object.prototype.toString.call(obj)) && !isNaN(obj.getTime());
} | Describes open/close state of datepicker
@type {Boolean} | _isDate | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
static _isWeekend(date) {
let day = date.getDay();
return day === 0 || day === 6;
} | Describes open/close state of datepicker
@type {Boolean} | _isWeekend | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
static _setToStartOfDay(date) {
if (Datepicker._isDate(date)) date.setHours(0, 0, 0, 0);
} | Describes open/close state of datepicker
@type {Boolean} | _setToStartOfDay | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
static _getDaysInMonth(year, month) {
return [31, Datepicker._isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31][
month
];
} | Describes open/close state of datepicker
@type {Boolean} | _getDaysInMonth | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
static _isLeapYear(year) {
// solution by Matti Virkkunen: http://stackoverflow.com/a/4881951
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
} | Describes open/close state of datepicker
@type {Boolean} | _isLeapYear | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
static _compareDates(a, b) {
// weak date comparison (use setToStartOfDay(date) to ensure correct result)
return a.getTime() === b.getTime();
} | Describes open/close state of datepicker
@type {Boolean} | _compareDates | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
static _setToStartOfDay(date) {
if (Datepicker._isDate(date)) date.setHours(0, 0, 0, 0);
} | Describes open/close state of datepicker
@type {Boolean} | _setToStartOfDay | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
gotoMonth(month) {
if (!isNaN(month)) {
this.calendars[0].month = parseInt(month, 10);
this.adjustCalendars();
}
} | change view to a specific month (zero-index, e.g. 0: January) | gotoMonth | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
gotoYear(year) {
if (!isNaN(year)) {
this.calendars[0].year = parseInt(year, 10);
this.adjustCalendars();
}
} | change view to a specific full year (e.g. "2012") | gotoYear | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
_handleInputChange(e) {
let date;
// Prevent change event from being fired when triggered by the plugin
if (e.firedBy === this) {
return;
}
if (this.options.parse) {
date = this.options.parse(this.el.value, this.options.format);
} else {
date = new Date(Date.parse(this.el.value));
}
if (Datepicker._isDate(date)) {
this.setDate(date);
}
} | change view to a specific full year (e.g. "2012") | _handleInputChange | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
renderDayName(opts, day, abbr) {
day += opts.firstDay;
while (day >= 7) {
day -= 7;
}
return abbr ? opts.i18n.weekdaysAbbrev[day] : opts.i18n.weekdays[day];
} | change view to a specific full year (e.g. "2012") | renderDayName | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
_finishSelection() {
this.setInputValue();
this.close();
} | Set input value to the selected date and close Datepicker | _finishSelection | javascript | Dogfalo/materialize | js/datepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/datepicker.js | MIT |
static get defaults() {
return _defaults;
} | Describes if touch moving on dropdown content
@type {Boolean} | defaults | javascript | Dogfalo/materialize | js/dropdown.js | https://github.com/Dogfalo/materialize/blob/master/js/dropdown.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Describes if touch moving on dropdown content
@type {Boolean} | init | javascript | Dogfalo/materialize | js/dropdown.js | https://github.com/Dogfalo/materialize/blob/master/js/dropdown.js | MIT |
function s4() {
return Math.floor((1 + Math.random()) * 0x10000)
.toString(16)
.substring(1);
} | Generate approximated selector string for a jQuery object
@param {jQuery} obj jQuery object to be parsed
@returns {string} | s4 | javascript | Dogfalo/materialize | js/global.js | https://github.com/Dogfalo/materialize/blob/master/js/global.js | MIT |
constructor(el, options) {
super(Materialbox, el, options);
this.el.M_Materialbox = this;
/**
* Options for the modal
* @member Materialbox#options
* @prop {Number} [inDuration=275] - Length in ms of enter transition
* @prop {Number} [outDuration=200] - Length in ms of exit transition
* @prop {Function} onOpenStart - Callback function called before materialbox is opened
* @prop {Function} onOpenEnd - Callback function called after materialbox is opened
* @prop {Function} onCloseStart - Callback function called before materialbox is closed
* @prop {Function} onCloseEnd - Callback function called after materialbox is closed
*/
this.options = $.extend({}, Materialbox.defaults, options);
this.overlayActive = false;
this.doneAnimating = true;
this.placeholder = $('<div></div>').addClass('material-placeholder');
this.originalWidth = 0;
this.originalHeight = 0;
this.originInlineStyles = this.$el.attr('style');
this.caption = this.el.getAttribute('data-caption') || '';
// Wrap
this.$el.before(this.placeholder);
this.placeholder.append(this.$el);
this._setupEventHandlers();
} | Construct Materialbox instance
@constructor
@param {Element} el
@param {Object} options | constructor | javascript | Dogfalo/materialize | js/materialbox.js | https://github.com/Dogfalo/materialize/blob/master/js/materialbox.js | MIT |
static get defaults() {
return _defaults;
} | Options for the modal
@member Materialbox#options
@prop {Number} [inDuration=275] - Length in ms of enter transition
@prop {Number} [outDuration=200] - Length in ms of exit transition
@prop {Function} onOpenStart - Callback function called before materialbox is opened
@prop {Function} onOpenEnd - Callback function called after materialbox is opened
@prop {Function} onCloseStart - Callback function called before materialbox is closed
@prop {Function} onCloseEnd - Callback function called after materialbox is closed | defaults | javascript | Dogfalo/materialize | js/materialbox.js | https://github.com/Dogfalo/materialize/blob/master/js/materialbox.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Options for the modal
@member Materialbox#options
@prop {Number} [inDuration=275] - Length in ms of enter transition
@prop {Number} [outDuration=200] - Length in ms of exit transition
@prop {Function} onOpenStart - Callback function called before materialbox is opened
@prop {Function} onOpenEnd - Callback function called after materialbox is opened
@prop {Function} onCloseStart - Callback function called before materialbox is closed
@prop {Function} onCloseEnd - Callback function called after materialbox is closed | init | javascript | Dogfalo/materialize | js/materialbox.js | https://github.com/Dogfalo/materialize/blob/master/js/materialbox.js | MIT |
_makeAncestorsOverflowVisible() {
this.ancestorsChanged = $();
let ancestor = this.placeholder[0].parentNode;
while (ancestor !== null && !$(ancestor).is(document)) {
let curr = $(ancestor);
if (curr.css('overflow') !== 'visible') {
curr.css('overflow', 'visible');
if (this.ancestorsChanged === undefined) {
this.ancestorsChanged = curr;
} else {
this.ancestorsChanged = this.ancestorsChanged.add(curr);
}
}
ancestor = ancestor.parentNode;
}
} | Find ancestors with overflow: hidden; and make visible | _makeAncestorsOverflowVisible | javascript | Dogfalo/materialize | js/materialbox.js | https://github.com/Dogfalo/materialize/blob/master/js/materialbox.js | MIT |
constructor(el, options) {
super(Modal, el, options);
this.el.M_Modal = this;
/**
* Options for the modal
* @member Modal#options
* @prop {Number} [opacity=0.5] - Opacity of the modal overlay
* @prop {Number} [inDuration=250] - Length in ms of enter transition
* @prop {Number} [outDuration=250] - Length in ms of exit transition
* @prop {Function} onOpenStart - Callback function called before modal is opened
* @prop {Function} onOpenEnd - Callback function called after modal is opened
* @prop {Function} onCloseStart - Callback function called before modal is closed
* @prop {Function} onCloseEnd - Callback function called after modal is closed
* @prop {Boolean} [dismissible=true] - Allow modal to be dismissed by keyboard or overlay click
* @prop {String} [startingTop='4%'] - startingTop
* @prop {String} [endingTop='10%'] - endingTop
*/
this.options = $.extend({}, Modal.defaults, options);
/**
* Describes open/close state of modal
* @type {Boolean}
*/
this.isOpen = false;
this.id = this.$el.attr('id');
this._openingTrigger = undefined;
this.$overlay = $('<div class="modal-overlay"></div>');
this.el.tabIndex = 0;
this._nthModalOpened = 0;
Modal._count++;
this._setupEventHandlers();
} | Construct Modal instance and set up overlay
@constructor
@param {Element} el
@param {Object} options | constructor | javascript | Dogfalo/materialize | js/modal.js | https://github.com/Dogfalo/materialize/blob/master/js/modal.js | MIT |
static get defaults() {
return _defaults;
} | Describes open/close state of modal
@type {Boolean} | defaults | javascript | Dogfalo/materialize | js/modal.js | https://github.com/Dogfalo/materialize/blob/master/js/modal.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Describes open/close state of modal
@type {Boolean} | init | javascript | Dogfalo/materialize | js/modal.js | https://github.com/Dogfalo/materialize/blob/master/js/modal.js | MIT |
_handleModalCloseClick(e) {
let $closeTrigger = $(e.target).closest('.modal-close');
if ($closeTrigger.length) {
this.close();
}
} | Handle Modal Close Click
@param {Event} e | _handleModalCloseClick | javascript | Dogfalo/materialize | js/modal.js | https://github.com/Dogfalo/materialize/blob/master/js/modal.js | MIT |
static get defaults() {
return _defaults;
} | Options for the Parallax
@member Parallax#options
@prop {Number} responsiveThreshold | defaults | javascript | Dogfalo/materialize | js/parallax.js | https://github.com/Dogfalo/materialize/blob/master/js/parallax.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Options for the Parallax
@member Parallax#options
@prop {Number} responsiveThreshold | init | javascript | Dogfalo/materialize | js/parallax.js | https://github.com/Dogfalo/materialize/blob/master/js/parallax.js | MIT |
constructor(el, options) {
super(Pushpin, el, options);
this.el.M_Pushpin = this;
/**
* Options for the modal
* @member Pushpin#options
*/
this.options = $.extend({}, Pushpin.defaults, options);
this.originalOffset = this.el.offsetTop;
Pushpin._pushpins.push(this);
this._setupEventHandlers();
this._updatePosition();
} | Construct Pushpin instance
@constructor
@param {Element} el
@param {Object} options | constructor | javascript | Dogfalo/materialize | js/pushpin.js | https://github.com/Dogfalo/materialize/blob/master/js/pushpin.js | MIT |
static get defaults() {
return _defaults;
} | Options for the modal
@member Pushpin#options | defaults | javascript | Dogfalo/materialize | js/pushpin.js | https://github.com/Dogfalo/materialize/blob/master/js/pushpin.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Options for the modal
@member Pushpin#options | init | javascript | Dogfalo/materialize | js/pushpin.js | https://github.com/Dogfalo/materialize/blob/master/js/pushpin.js | MIT |
constructor(el, options) {
super(Range, el, options);
this.el.M_Range = this;
/**
* Options for the range
* @member Range#options
*/
this.options = $.extend({}, Range.defaults, options);
this._mousedown = false;
// Setup
this._setupThumb();
this._setupEventHandlers();
} | Construct Range instance
@constructor
@param {Element} el
@param {Object} options | constructor | javascript | Dogfalo/materialize | js/range.js | https://github.com/Dogfalo/materialize/blob/master/js/range.js | MIT |
static get defaults() {
return _defaults;
} | Options for the range
@member Range#options | defaults | javascript | Dogfalo/materialize | js/range.js | https://github.com/Dogfalo/materialize/blob/master/js/range.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Options for the range
@member Range#options | init | javascript | Dogfalo/materialize | js/range.js | https://github.com/Dogfalo/materialize/blob/master/js/range.js | MIT |
_handleRangeMousedownTouchstart(e) {
// Set indicator value
$(this.value).html(this.$el.val());
this._mousedown = true;
this.$el.addClass('active');
if (!$(this.thumb).hasClass('active')) {
this._showRangeBubble();
}
if (e.type !== 'input') {
let offsetLeft = this._calcRangeOffset();
$(this.thumb)
.addClass('active')
.css('left', offsetLeft + 'px');
}
} | Handle Range Mousedown and Touchstart
@param {Event} e | _handleRangeMousedownTouchstart | javascript | Dogfalo/materialize | js/range.js | https://github.com/Dogfalo/materialize/blob/master/js/range.js | MIT |
_handleRangeInputMousemoveTouchmove() {
if (this._mousedown) {
if (!$(this.thumb).hasClass('active')) {
this._showRangeBubble();
}
let offsetLeft = this._calcRangeOffset();
$(this.thumb)
.addClass('active')
.css('left', offsetLeft + 'px');
$(this.value).html(this.$el.val());
}
} | Handle Range Input, Mousemove and Touchmove | _handleRangeInputMousemoveTouchmove | javascript | Dogfalo/materialize | js/range.js | https://github.com/Dogfalo/materialize/blob/master/js/range.js | MIT |
_handleRangeBlurMouseoutTouchleave() {
if (!this._mousedown) {
let paddingLeft = parseInt(this.$el.css('padding-left'));
let marginLeft = 7 + paddingLeft + 'px';
if ($(this.thumb).hasClass('active')) {
anim.remove(this.thumb);
anim({
targets: this.thumb,
height: 0,
width: 0,
top: 10,
easing: 'easeOutQuad',
marginLeft: marginLeft,
duration: 100
});
}
$(this.thumb).removeClass('active');
}
} | Handle Range Blur, Mouseout and Touchleave | _handleRangeBlurMouseoutTouchleave | javascript | Dogfalo/materialize | js/range.js | https://github.com/Dogfalo/materialize/blob/master/js/range.js | MIT |
_calcRangeOffset() {
let width = this.$el.width() - 15;
let max = parseFloat(this.$el.attr('max')) || 100; // Range default max
let min = parseFloat(this.$el.attr('min')) || 0; // Range default min
let percent = (parseFloat(this.$el.val()) - min) / (max - min);
return percent * width;
} | Calculate the offset of the thumb
@return {Number} offset in pixels | _calcRangeOffset | javascript | Dogfalo/materialize | js/range.js | https://github.com/Dogfalo/materialize/blob/master/js/range.js | MIT |
constructor(el, options) {
super(ScrollSpy, el, options);
this.el.M_ScrollSpy = this;
/**
* Options for the modal
* @member Modal#options
* @prop {Number} [throttle=100] - Throttle of scroll handler
* @prop {Number} [scrollOffset=200] - Offset for centering element when scrolled to
* @prop {String} [activeClass='active'] - Class applied to active elements
* @prop {Function} [getActiveElement] - Used to find active element
*/
this.options = $.extend({}, ScrollSpy.defaults, options);
// setup
ScrollSpy._elements.push(this);
ScrollSpy._count++;
ScrollSpy._increment++;
this.tickId = -1;
this.id = ScrollSpy._increment;
this._setupEventHandlers();
this._handleWindowScroll();
} | Construct ScrollSpy instance
@constructor
@param {Element} el
@param {Object} options | constructor | javascript | Dogfalo/materialize | js/scrollspy.js | https://github.com/Dogfalo/materialize/blob/master/js/scrollspy.js | MIT |
static get defaults() {
return _defaults;
} | Options for the modal
@member Modal#options
@prop {Number} [throttle=100] - Throttle of scroll handler
@prop {Number} [scrollOffset=200] - Offset for centering element when scrolled to
@prop {String} [activeClass='active'] - Class applied to active elements
@prop {Function} [getActiveElement] - Used to find active element | defaults | javascript | Dogfalo/materialize | js/scrollspy.js | https://github.com/Dogfalo/materialize/blob/master/js/scrollspy.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Options for the modal
@member Modal#options
@prop {Number} [throttle=100] - Throttle of scroll handler
@prop {Number} [scrollOffset=200] - Offset for centering element when scrolled to
@prop {String} [activeClass='active'] - Class applied to active elements
@prop {Function} [getActiveElement] - Used to find active element | init | javascript | Dogfalo/materialize | js/scrollspy.js | https://github.com/Dogfalo/materialize/blob/master/js/scrollspy.js | MIT |
static _findElements(top, right, bottom, left) {
let hits = [];
for (let i = 0; i < ScrollSpy._elements.length; i++) {
let scrollspy = ScrollSpy._elements[i];
let currTop = top + scrollspy.options.scrollOffset || 200;
if (scrollspy.$el.height() > 0) {
let elTop = scrollspy.$el.offset().top,
elLeft = scrollspy.$el.offset().left,
elRight = elLeft + scrollspy.$el.width(),
elBottom = elTop + scrollspy.$el.height();
let isIntersect = !(
elLeft > right ||
elRight < left ||
elTop > bottom ||
elBottom < currTop
);
if (isIntersect) {
hits.push(scrollspy);
}
}
}
return hits;
} | Find elements that are within the boundary
@param {number} top
@param {number} right
@param {number} bottom
@param {number} left
@return {Array.<ScrollSpy>} A collection of elements | _findElements | javascript | Dogfalo/materialize | js/scrollspy.js | https://github.com/Dogfalo/materialize/blob/master/js/scrollspy.js | MIT |
_enter() {
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(function(value) {
return value.height() != 0;
});
if (ScrollSpy._visibleElements[0]) {
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).removeClass(
this.options.activeClass
);
if (
ScrollSpy._visibleElements[0][0].M_ScrollSpy &&
this.id < ScrollSpy._visibleElements[0][0].M_ScrollSpy.id
) {
ScrollSpy._visibleElements.unshift(this.$el);
} else {
ScrollSpy._visibleElements.push(this.$el);
}
} else {
ScrollSpy._visibleElements.push(this.$el);
}
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).addClass(
this.options.activeClass
);
} | Find elements that are within the boundary
@param {number} top
@param {number} right
@param {number} bottom
@param {number} left
@return {Array.<ScrollSpy>} A collection of elements | _enter | javascript | Dogfalo/materialize | js/scrollspy.js | https://github.com/Dogfalo/materialize/blob/master/js/scrollspy.js | MIT |
_exit() {
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter(function(value) {
return value.height() != 0;
});
if (ScrollSpy._visibleElements[0]) {
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).removeClass(
this.options.activeClass
);
ScrollSpy._visibleElements = ScrollSpy._visibleElements.filter((el) => {
return el.attr('id') != this.$el.attr('id');
});
if (ScrollSpy._visibleElements[0]) {
// Check if empty
$(this.options.getActiveElement(ScrollSpy._visibleElements[0].attr('id'))).addClass(
this.options.activeClass
);
}
}
} | Find elements that are within the boundary
@param {number} top
@param {number} right
@param {number} bottom
@param {number} left
@return {Array.<ScrollSpy>} A collection of elements | _exit | javascript | Dogfalo/materialize | js/scrollspy.js | https://github.com/Dogfalo/materialize/blob/master/js/scrollspy.js | MIT |
constructor(el, options) {
super(FormSelect, el, options);
// Don't init if browser default version
if (this.$el.hasClass('browser-default')) {
return;
}
this.el.M_FormSelect = this;
/**
* Options for the select
* @member FormSelect#options
*/
this.options = $.extend({}, FormSelect.defaults, options);
this.isMultiple = this.$el.prop('multiple');
// Setup
this.el.tabIndex = -1;
this._keysSelected = {};
this._valueDict = {}; // Maps key to original and generated option element.
this._setupDropdown();
this._setupEventHandlers();
} | Construct FormSelect instance
@constructor
@param {Element} el
@param {Object} options | constructor | javascript | Dogfalo/materialize | js/select.js | https://github.com/Dogfalo/materialize/blob/master/js/select.js | MIT |
static get defaults() {
return _defaults;
} | Options for the select
@member FormSelect#options | defaults | javascript | Dogfalo/materialize | js/select.js | https://github.com/Dogfalo/materialize/blob/master/js/select.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Options for the select
@member FormSelect#options | init | javascript | Dogfalo/materialize | js/select.js | https://github.com/Dogfalo/materialize/blob/master/js/select.js | MIT |
_addOptionToValueDict(el, optionEl) {
let index = Object.keys(this._valueDict).length;
let key = this.dropdownOptions.id + index;
let obj = {};
optionEl.id = key;
obj.el = el;
obj.optionEl = optionEl;
this._valueDict[key] = obj;
} | Add option to value dict
@param {Element} el original option element
@param {Element} optionEl generated option element | _addOptionToValueDict | javascript | Dogfalo/materialize | js/select.js | https://github.com/Dogfalo/materialize/blob/master/js/select.js | MIT |
_appendOptionWithIcon(select, option, type) {
// Add disabled attr if disabled
let disabledClass = option.disabled ? 'disabled ' : '';
let optgroupClass = type === 'optgroup-option' ? 'optgroup-option ' : '';
let multipleCheckbox = this.isMultiple
? `<label><input type="checkbox"${disabledClass}"/><span>${option.innerHTML}</span></label>`
: option.innerHTML;
let liEl = $('<li></li>');
let spanEl = $('<span></span>');
spanEl.html(multipleCheckbox);
liEl.addClass(`${disabledClass} ${optgroupClass}`);
liEl.append(spanEl);
// add icons
let iconUrl = option.getAttribute('data-icon');
if (!!iconUrl) {
let imgEl = $(`<img alt="" src="${iconUrl}">`);
liEl.prepend(imgEl);
}
// Check for multiple type.
$(this.dropdownOptions).append(liEl[0]);
return liEl[0];
} | Setup dropdown
@param {Element} select select element
@param {Element} option option element from select
@param {String} type
@return {Element} option element added | _appendOptionWithIcon | javascript | Dogfalo/materialize | js/select.js | https://github.com/Dogfalo/materialize/blob/master/js/select.js | MIT |
_toggleEntryFromArray(key) {
let notAdded = !this._keysSelected.hasOwnProperty(key);
let $optionLi = $(this._valueDict[key].optionEl);
if (notAdded) {
this._keysSelected[key] = true;
} else {
delete this._keysSelected[key];
}
$optionLi.toggleClass('selected', notAdded);
// Set checkbox checked value
$optionLi.find('input[type="checkbox"]').prop('checked', notAdded);
// use notAdded instead of true (to detect if the option is selected or not)
$optionLi.prop('selected', notAdded);
return notAdded;
} | Toggle entry from option
@param {String} key Option key
@return {Boolean} if entry was added or removed | _toggleEntryFromArray | javascript | Dogfalo/materialize | js/select.js | https://github.com/Dogfalo/materialize/blob/master/js/select.js | MIT |
_setSelectedStates() {
this._keysSelected = {};
for (let key in this._valueDict) {
let option = this._valueDict[key];
let optionIsSelected = $(option.el).prop('selected');
$(option.optionEl)
.find('input[type="checkbox"]')
.prop('checked', optionIsSelected);
if (optionIsSelected) {
this._activateOption($(this.dropdownOptions), $(option.optionEl));
this._keysSelected[key] = true;
} else {
$(option.optionEl).removeClass('selected');
}
}
} | Set selected state of dropdown to match actual select element | _setSelectedStates | javascript | Dogfalo/materialize | js/select.js | https://github.com/Dogfalo/materialize/blob/master/js/select.js | MIT |
_activateOption(collection, newOption) {
if (newOption) {
if (!this.isMultiple) {
collection.find('li.selected').removeClass('selected');
}
let option = $(newOption);
option.addClass('selected');
}
} | Make option as selected and scroll to selected position
@param {jQuery} collection Select options jQuery element
@param {Element} newOption element of the new option | _activateOption | javascript | Dogfalo/materialize | js/select.js | https://github.com/Dogfalo/materialize/blob/master/js/select.js | MIT |
getSelectedValues() {
let selectedValues = [];
for (let key in this._keysSelected) {
selectedValues.push(this._valueDict[key].el.value);
}
return selectedValues;
} | Get Selected Values
@return {Array} Array of selected values | getSelectedValues | javascript | Dogfalo/materialize | js/select.js | https://github.com/Dogfalo/materialize/blob/master/js/select.js | MIT |
constructor(el, options) {
super(Sidenav, el, options);
this.el.M_Sidenav = this;
this.id = this.$el.attr('id');
/**
* Options for the Sidenav
* @member Sidenav#options
* @prop {String} [edge='left'] - Side of screen on which Sidenav appears
* @prop {Boolean} [draggable=true] - Allow swipe gestures to open/close Sidenav
* @prop {Number} [inDuration=250] - Length in ms of enter transition
* @prop {Number} [outDuration=200] - Length in ms of exit transition
* @prop {Function} onOpenStart - Function called when sidenav starts entering
* @prop {Function} onOpenEnd - Function called when sidenav finishes entering
* @prop {Function} onCloseStart - Function called when sidenav starts exiting
* @prop {Function} onCloseEnd - Function called when sidenav finishes exiting
*/
this.options = $.extend({}, Sidenav.defaults, options);
/**
* Describes open/close state of Sidenav
* @type {Boolean}
*/
this.isOpen = false;
/**
* Describes if Sidenav is fixed
* @type {Boolean}
*/
this.isFixed = this.el.classList.contains('sidenav-fixed');
/**
* Describes if Sidenav is being draggeed
* @type {Boolean}
*/
this.isDragged = false;
// Window size variables for window resize checks
this.lastWindowWidth = window.innerWidth;
this.lastWindowHeight = window.innerHeight;
this._createOverlay();
this._createDragTarget();
this._setupEventHandlers();
this._setupClasses();
this._setupFixed();
Sidenav._sidenavs.push(this);
} | Construct Sidenav instance and set up overlay
@constructor
@param {Element} el
@param {Object} options | constructor | javascript | Dogfalo/materialize | js/sidenav.js | https://github.com/Dogfalo/materialize/blob/master/js/sidenav.js | MIT |
static get defaults() {
return _defaults;
} | Describes if Sidenav is being draggeed
@type {Boolean} | defaults | javascript | Dogfalo/materialize | js/sidenav.js | https://github.com/Dogfalo/materialize/blob/master/js/sidenav.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Describes if Sidenav is being draggeed
@type {Boolean} | init | javascript | Dogfalo/materialize | js/sidenav.js | https://github.com/Dogfalo/materialize/blob/master/js/sidenav.js | MIT |
_startDrag(e) {
let clientX = e.targetTouches[0].clientX;
this.isDragged = true;
this._startingXpos = clientX;
this._xPos = this._startingXpos;
this._time = Date.now();
this._width = this.el.getBoundingClientRect().width;
this._overlay.style.display = 'block';
this._initialScrollTop = this.isOpen ? this.el.scrollTop : M.getDocumentScrollTop();
this._verticallyScrolling = false;
anim.remove(this.el);
anim.remove(this._overlay);
} | Set variables needed at the beggining of drag
and stop any current transition.
@param {Event} e | _startDrag | javascript | Dogfalo/materialize | js/sidenav.js | https://github.com/Dogfalo/materialize/blob/master/js/sidenav.js | MIT |
_dragMoveUpdate(e) {
let clientX = e.targetTouches[0].clientX;
let currentScrollTop = this.isOpen ? this.el.scrollTop : M.getDocumentScrollTop();
this.deltaX = Math.abs(this._xPos - clientX);
this._xPos = clientX;
this.velocityX = this.deltaX / (Date.now() - this._time);
this._time = Date.now();
if (this._initialScrollTop !== currentScrollTop) {
this._verticallyScrolling = true;
}
} | Set variables needed at each drag move update tick
@param {Event} e | _dragMoveUpdate | javascript | Dogfalo/materialize | js/sidenav.js | https://github.com/Dogfalo/materialize/blob/master/js/sidenav.js | MIT |
_handleDragTargetDrag(e) {
// Check if draggable
if (!this.options.draggable || this._isCurrentlyFixed() || this._verticallyScrolling) {
return;
}
// If not being dragged, set initial drag start variables
if (!this.isDragged) {
this._startDrag(e);
}
// Run touchmove updates
this._dragMoveUpdate(e);
// Calculate raw deltaX
let totalDeltaX = this._xPos - this._startingXpos;
// dragDirection is the attempted user drag direction
let dragDirection = totalDeltaX > 0 ? 'right' : 'left';
// Don't allow totalDeltaX to exceed Sidenav width or be dragged in the opposite direction
totalDeltaX = Math.min(this._width, Math.abs(totalDeltaX));
if (this.options.edge === dragDirection) {
totalDeltaX = 0;
}
/**
* transformX is the drag displacement
* transformPrefix is the initial transform placement
* Invert values if Sidenav is right edge
*/
let transformX = totalDeltaX;
let transformPrefix = 'translateX(-100%)';
if (this.options.edge === 'right') {
transformPrefix = 'translateX(100%)';
transformX = -transformX;
}
// Calculate open/close percentage of sidenav, with open = 1 and close = 0
this.percentOpen = Math.min(1, totalDeltaX / this._width);
// Set transform and opacity styles
this.el.style.transform = `${transformPrefix} translateX(${transformX}px)`;
this._overlay.style.opacity = this.percentOpen;
} | Handles Dragging of Sidenav
@param {Event} e | _handleDragTargetDrag | javascript | Dogfalo/materialize | js/sidenav.js | https://github.com/Dogfalo/materialize/blob/master/js/sidenav.js | MIT |
_handleCloseTriggerClick(e) {
let $closeTrigger = $(e.target).closest('.sidenav-close');
if ($closeTrigger.length && !this._isCurrentlyFixed()) {
this.close();
}
} | Handles closing of Sidenav when element with class .sidenav-close | _handleCloseTriggerClick | javascript | Dogfalo/materialize | js/sidenav.js | https://github.com/Dogfalo/materialize/blob/master/js/sidenav.js | MIT |
constructor(el, options) {
super(Slider, el, options);
this.el.M_Slider = this;
/**
* Options for the modal
* @member Slider#options
* @prop {Boolean} [indicators=true] - Show indicators
* @prop {Number} [height=400] - height of slider
* @prop {Number} [duration=500] - Length in ms of slide transition
* @prop {Number} [interval=6000] - Length in ms of slide interval
*/
this.options = $.extend({}, Slider.defaults, options);
// setup
this.$slider = this.$el.find('.slides');
this.$slides = this.$slider.children('li');
this.activeIndex = this.$slides
.filter(function(item) {
return $(item).hasClass('active');
})
.first()
.index();
if (this.activeIndex != -1) {
this.$active = this.$slides.eq(this.activeIndex);
}
this._setSliderHeight();
// Set initial positions of captions
this.$slides.find('.caption').each((el) => {
this._animateCaptionIn(el, 0);
});
// Move img src into background-image
this.$slides.find('img').each((el) => {
let placeholderBase64 =
'data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==';
if ($(el).attr('src') !== placeholderBase64) {
$(el).css('background-image', 'url("' + $(el).attr('src') + '")');
$(el).attr('src', placeholderBase64);
}
});
this._setupIndicators();
// Show active slide
if (this.$active) {
this.$active.css('display', 'block');
} else {
this.$slides.first().addClass('active');
anim({
targets: this.$slides.first()[0],
opacity: 1,
duration: this.options.duration,
easing: 'easeOutQuad'
});
this.activeIndex = 0;
this.$active = this.$slides.eq(this.activeIndex);
// Update indicators
if (this.options.indicators) {
this.$indicators.eq(this.activeIndex).addClass('active');
}
}
// Adjust height to current slide
this.$active.find('img').each((el) => {
anim({
targets: this.$active.find('.caption')[0],
opacity: 1,
translateX: 0,
translateY: 0,
duration: this.options.duration,
easing: 'easeOutQuad'
});
});
this._setupEventHandlers();
// auto scroll
this.start();
} | Construct Slider instance and set up overlay
@constructor
@param {Element} el
@param {Object} options | constructor | javascript | Dogfalo/materialize | js/slider.js | https://github.com/Dogfalo/materialize/blob/master/js/slider.js | MIT |
static get defaults() {
return _defaults;
} | Options for the modal
@member Slider#options
@prop {Boolean} [indicators=true] - Show indicators
@prop {Number} [height=400] - height of slider
@prop {Number} [duration=500] - Length in ms of slide transition
@prop {Number} [interval=6000] - Length in ms of slide interval | defaults | javascript | Dogfalo/materialize | js/slider.js | https://github.com/Dogfalo/materialize/blob/master/js/slider.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Options for the modal
@member Slider#options
@prop {Boolean} [indicators=true] - Show indicators
@prop {Number} [height=400] - height of slider
@prop {Number} [duration=500] - Length in ms of slide transition
@prop {Number} [interval=6000] - Length in ms of slide interval | init | javascript | Dogfalo/materialize | js/slider.js | https://github.com/Dogfalo/materialize/blob/master/js/slider.js | MIT |
_animateCaptionIn(caption, duration) {
let animOptions = {
targets: caption,
opacity: 0,
duration: duration,
easing: 'easeOutQuad'
};
if ($(caption).hasClass('center-align')) {
animOptions.translateY = -100;
} else if ($(caption).hasClass('right-align')) {
animOptions.translateX = 100;
} else if ($(caption).hasClass('left-align')) {
animOptions.translateX = -100;
}
anim(animOptions);
} | Animate in caption
@param {Element} caption
@param {Number} duration | _animateCaptionIn | javascript | Dogfalo/materialize | js/slider.js | https://github.com/Dogfalo/materialize/blob/master/js/slider.js | MIT |
set(index) {
// Wrap around indices.
if (index >= this.$slides.length) index = 0;
else if (index < 0) index = this.$slides.length - 1;
// Only do if index changes
if (this.activeIndex != index) {
this.$active = this.$slides.eq(this.activeIndex);
let $caption = this.$active.find('.caption');
this.$active.removeClass('active');
anim({
targets: this.$active[0],
opacity: 0,
duration: this.options.duration,
easing: 'easeOutQuad',
complete: () => {
this.$slides.not('.active').each((el) => {
anim({
targets: el,
opacity: 0,
translateX: 0,
translateY: 0,
duration: 0,
easing: 'easeOutQuad'
});
});
}
});
this._animateCaptionIn($caption[0], this.options.duration);
// Update indicators
if (this.options.indicators) {
this.$indicators.eq(this.activeIndex).removeClass('active');
this.$indicators.eq(index).addClass('active');
}
anim({
targets: this.$slides.eq(index)[0],
opacity: 1,
duration: this.options.duration,
easing: 'easeOutQuad'
});
anim({
targets: this.$slides.eq(index).find('.caption')[0],
opacity: 1,
translateX: 0,
translateY: 0,
duration: this.options.duration,
delay: this.options.duration,
easing: 'easeOutQuad'
});
this.$slides.eq(index).addClass('active');
this.activeIndex = index;
// Reset interval
this.start();
}
} | Cycle to nth item
@param {Number} index | set | javascript | Dogfalo/materialize | js/slider.js | https://github.com/Dogfalo/materialize/blob/master/js/slider.js | MIT |
constructor(el, options) {
super(Tabs, el, options);
this.el.M_Tabs = this;
/**
* Options for the Tabs
* @member Tabs#options
* @prop {Number} duration
* @prop {Function} onShow
* @prop {Boolean} swipeable
* @prop {Number} responsiveThreshold
*/
this.options = $.extend({}, Tabs.defaults, options);
// Setup
this.$tabLinks = this.$el.children('li.tab').children('a');
this.index = 0;
this._setupActiveTabLink();
// Setup tabs content
if (this.options.swipeable) {
this._setupSwipeableTabs();
} else {
this._setupNormalTabs();
}
// Setup tabs indicator after content to ensure accurate widths
this._setTabsAndTabWidth();
this._createIndicator();
this._setupEventHandlers();
} | Construct Tabs instance
@constructor
@param {Element} el
@param {Object} options | constructor | javascript | Dogfalo/materialize | js/tabs.js | https://github.com/Dogfalo/materialize/blob/master/js/tabs.js | MIT |
static get defaults() {
return _defaults;
} | Options for the Tabs
@member Tabs#options
@prop {Number} duration
@prop {Function} onShow
@prop {Boolean} swipeable
@prop {Number} responsiveThreshold | defaults | javascript | Dogfalo/materialize | js/tabs.js | https://github.com/Dogfalo/materialize/blob/master/js/tabs.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Options for the Tabs
@member Tabs#options
@prop {Number} duration
@prop {Function} onShow
@prop {Boolean} swipeable
@prop {Number} responsiveThreshold | init | javascript | Dogfalo/materialize | js/tabs.js | https://github.com/Dogfalo/materialize/blob/master/js/tabs.js | MIT |
_calcRightPos(el) {
return Math.ceil(this.tabsWidth - el.position().left - el[0].getBoundingClientRect().width);
} | Finds right attribute for indicator based on active tab.
@param {cash} el | _calcRightPos | javascript | Dogfalo/materialize | js/tabs.js | https://github.com/Dogfalo/materialize/blob/master/js/tabs.js | MIT |
_calcLeftPos(el) {
return Math.floor(el.position().left);
} | Finds left attribute for indicator based on active tab.
@param {cash} el | _calcLeftPos | javascript | Dogfalo/materialize | js/tabs.js | https://github.com/Dogfalo/materialize/blob/master/js/tabs.js | MIT |
updateTabIndicator() {
this._setTabsAndTabWidth();
this._animateIndicator(this.index);
} | Finds left attribute for indicator based on active tab.
@param {cash} el | updateTabIndicator | javascript | Dogfalo/materialize | js/tabs.js | https://github.com/Dogfalo/materialize/blob/master/js/tabs.js | MIT |
_animateIndicator(prevIndex) {
let leftDelay = 0,
rightDelay = 0;
if (this.index - prevIndex >= 0) {
leftDelay = 90;
} else {
rightDelay = 90;
}
// Animate
let animOptions = {
targets: this._indicator,
left: {
value: this._calcLeftPos(this.$activeTabLink),
delay: leftDelay
},
right: {
value: this._calcRightPos(this.$activeTabLink),
delay: rightDelay
},
duration: this.options.duration,
easing: 'easeOutQuad'
};
anim.remove(this._indicator);
anim(animOptions);
} | Animates Indicator to active tab.
@param {Number} prevIndex | _animateIndicator | javascript | Dogfalo/materialize | js/tabs.js | https://github.com/Dogfalo/materialize/blob/master/js/tabs.js | MIT |
constructor(el, options) {
super(TapTarget, el, options);
this.el.M_TapTarget = this;
/**
* Options for the select
* @member TapTarget#options
* @prop {Function} onOpen - Callback function called when feature discovery is opened
* @prop {Function} onClose - Callback function called when feature discovery is closed
*/
this.options = $.extend({}, TapTarget.defaults, options);
this.isOpen = false;
// setup
this.$origin = $('#' + this.$el.attr('data-target'));
this._setup();
this._calculatePositioning();
this._setupEventHandlers();
} | Construct TapTarget instance
@constructor
@param {Element} el
@param {Object} options | constructor | javascript | Dogfalo/materialize | js/tapTarget.js | https://github.com/Dogfalo/materialize/blob/master/js/tapTarget.js | MIT |
static get defaults() {
return _defaults;
} | Options for the select
@member TapTarget#options
@prop {Function} onOpen - Callback function called when feature discovery is opened
@prop {Function} onClose - Callback function called when feature discovery is closed | defaults | javascript | Dogfalo/materialize | js/tapTarget.js | https://github.com/Dogfalo/materialize/blob/master/js/tapTarget.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Options for the select
@member TapTarget#options
@prop {Function} onOpen - Callback function called when feature discovery is opened
@prop {Function} onClose - Callback function called when feature discovery is closed | init | javascript | Dogfalo/materialize | js/tapTarget.js | https://github.com/Dogfalo/materialize/blob/master/js/tapTarget.js | MIT |
static _Pos(e) {
if (e.targetTouches && e.targetTouches.length >= 1) {
return { x: e.targetTouches[0].clientX, y: e.targetTouches[0].clientY };
}
// mouse event
return { x: e.clientX, y: e.clientY };
} | Get x position of mouse or touch event
@param {Event} e
@return {Point} x and y location | _Pos | javascript | Dogfalo/materialize | js/timepicker.js | https://github.com/Dogfalo/materialize/blob/master/js/timepicker.js | MIT |
static get defaults() {
return _defaults;
} | Time remaining until toast is removed | defaults | javascript | Dogfalo/materialize | js/toasts.js | https://github.com/Dogfalo/materialize/blob/master/js/toasts.js | MIT |
static _createContainer() {
let container = document.createElement('div');
container.setAttribute('id', 'toast-container');
// Add event handler
container.addEventListener('touchstart', Toast._onDragStart);
container.addEventListener('touchmove', Toast._onDragMove);
container.addEventListener('touchend', Toast._onDragEnd);
container.addEventListener('mousedown', Toast._onDragStart);
document.addEventListener('mousemove', Toast._onDragMove);
document.addEventListener('mouseup', Toast._onDragEnd);
document.body.appendChild(container);
Toast._container = container;
} | Append toast container and add event handlers | _createContainer | javascript | Dogfalo/materialize | js/toasts.js | https://github.com/Dogfalo/materialize/blob/master/js/toasts.js | MIT |
static _removeContainer() {
// Add event handler
document.removeEventListener('mousemove', Toast._onDragMove);
document.removeEventListener('mouseup', Toast._onDragEnd);
$(Toast._container).remove();
Toast._container = null;
} | Remove toast container and event handlers | _removeContainer | javascript | Dogfalo/materialize | js/toasts.js | https://github.com/Dogfalo/materialize/blob/master/js/toasts.js | MIT |
static _xPos(e) {
if (e.targetTouches && e.targetTouches.length >= 1) {
return e.targetTouches[0].clientX;
}
// mouse event
return e.clientX;
} | Get x position of mouse or touch event
@param {Event} e | _xPos | javascript | Dogfalo/materialize | js/toasts.js | https://github.com/Dogfalo/materialize/blob/master/js/toasts.js | MIT |
_createToast() {
let toast = document.createElement('div');
toast.classList.add('toast');
// Add custom classes onto toast
if (!!this.options.classes.length) {
$(toast).addClass(this.options.classes);
}
// Set content
if (
typeof HTMLElement === 'object'
? this.message instanceof HTMLElement
: this.message &&
typeof this.message === 'object' &&
this.message !== null &&
this.message.nodeType === 1 &&
typeof this.message.nodeName === 'string'
) {
toast.appendChild(this.message);
// Check if it is jQuery object
} else if (!!this.message.jquery) {
$(toast).append(this.message[0]);
// Insert as html;
} else {
toast.innerHTML = this.message;
}
// Append toasft
Toast._container.appendChild(toast);
return toast;
} | Create toast and append it to toast container | _createToast | javascript | Dogfalo/materialize | js/toasts.js | https://github.com/Dogfalo/materialize/blob/master/js/toasts.js | MIT |
_setTimer() {
if (this.timeRemaining !== Infinity) {
this.counterInterval = setInterval(() => {
// If toast is not being dragged, decrease its time remaining
if (!this.panning) {
this.timeRemaining -= 20;
}
// Animate toast out
if (this.timeRemaining <= 0) {
this.dismiss();
}
}, 20);
}
} | Create setInterval which automatically removes toast when timeRemaining >= 0
has been reached | _setTimer | javascript | Dogfalo/materialize | js/toasts.js | https://github.com/Dogfalo/materialize/blob/master/js/toasts.js | MIT |
constructor(el, options) {
super(Tooltip, el, options);
this.el.M_Tooltip = this;
this.options = $.extend({}, Tooltip.defaults, options);
this.isOpen = false;
this.isHovered = false;
this.isFocused = false;
this._appendTooltipEl();
this._setupEventHandlers();
} | Construct Tooltip instance
@constructor
@param {Element} el
@param {Object} options | constructor | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
static get defaults() {
return _defaults;
} | Construct Tooltip instance
@constructor
@param {Element} el
@param {Object} options | defaults | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
static init(els, options) {
return super.init(this, els, options);
} | Construct Tooltip instance
@constructor
@param {Element} el
@param {Object} options | init | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
_setExitDelayTimeout() {
clearTimeout(this._exitDelayTimeout);
this._exitDelayTimeout = setTimeout(() => {
if (this.isHovered || this.isFocused) {
return;
}
this._animateOut();
}, this.options.exitDelay);
} | Create timeout which delays when the tooltip closes | _setExitDelayTimeout | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
_setEnterDelayTimeout(isManual) {
clearTimeout(this._enterDelayTimeout);
this._enterDelayTimeout = setTimeout(() => {
if (!this.isHovered && !this.isFocused && !isManual) {
return;
}
this._animateIn();
}, this.options.enterDelay);
} | Create timeout which delays when the toast closes | _setEnterDelayTimeout | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
_positionTooltip() {
let origin = this.el,
tooltip = this.tooltipEl,
originHeight = origin.offsetHeight,
originWidth = origin.offsetWidth,
tooltipHeight = tooltip.offsetHeight,
tooltipWidth = tooltip.offsetWidth,
newCoordinates,
margin = this.options.margin,
targetTop,
targetLeft;
(this.xMovement = 0), (this.yMovement = 0);
targetTop = origin.getBoundingClientRect().top + M.getDocumentScrollTop();
targetLeft = origin.getBoundingClientRect().left + M.getDocumentScrollLeft();
if (this.options.position === 'top') {
targetTop += -tooltipHeight - margin;
targetLeft += originWidth / 2 - tooltipWidth / 2;
this.yMovement = -this.options.transitionMovement;
} else if (this.options.position === 'right') {
targetTop += originHeight / 2 - tooltipHeight / 2;
targetLeft += originWidth + margin;
this.xMovement = this.options.transitionMovement;
} else if (this.options.position === 'left') {
targetTop += originHeight / 2 - tooltipHeight / 2;
targetLeft += -tooltipWidth - margin;
this.xMovement = -this.options.transitionMovement;
} else {
targetTop += originHeight + margin;
targetLeft += originWidth / 2 - tooltipWidth / 2;
this.yMovement = this.options.transitionMovement;
}
newCoordinates = this._repositionWithinScreen(
targetLeft,
targetTop,
tooltipWidth,
tooltipHeight
);
$(tooltip).css({
top: newCoordinates.y + 'px',
left: newCoordinates.x + 'px'
});
} | Create timeout which delays when the toast closes | _positionTooltip | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
_repositionWithinScreen(x, y, width, height) {
let scrollLeft = M.getDocumentScrollLeft();
let scrollTop = M.getDocumentScrollTop();
let newX = x - scrollLeft;
let newY = y - scrollTop;
let bounding = {
left: newX,
top: newY,
width: width,
height: height
};
let offset = this.options.margin + this.options.transitionMovement;
let edges = M.checkWithinContainer(document.body, bounding, offset);
if (edges.left) {
newX = offset;
} else if (edges.right) {
newX -= newX + width - window.innerWidth;
}
if (edges.top) {
newY = offset;
} else if (edges.bottom) {
newY -= newY + height - window.innerHeight;
}
return {
x: newX + scrollLeft,
y: newY + scrollTop
};
} | Create timeout which delays when the toast closes | _repositionWithinScreen | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
_animateIn() {
this._positionTooltip();
this.tooltipEl.style.visibility = 'visible';
anim.remove(this.tooltipEl);
anim({
targets: this.tooltipEl,
opacity: 1,
translateX: this.xMovement,
translateY: this.yMovement,
duration: this.options.inDuration,
easing: 'easeOutCubic'
});
} | Create timeout which delays when the toast closes | _animateIn | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
_animateOut() {
anim.remove(this.tooltipEl);
anim({
targets: this.tooltipEl,
opacity: 0,
translateX: 0,
translateY: 0,
duration: this.options.outDuration,
easing: 'easeOutCubic'
});
} | Create timeout which delays when the toast closes | _animateOut | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
_handleMouseEnter() {
this.isHovered = true;
this.isFocused = false; // Allows close of tooltip when opened by focus.
this.open(false);
} | Create timeout which delays when the toast closes | _handleMouseEnter | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
_handleMouseLeave() {
this.isHovered = false;
this.isFocused = false; // Allows close of tooltip when opened by focus.
this.close();
} | Create timeout which delays when the toast closes | _handleMouseLeave | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
_handleFocus() {
if (M.tabPressed) {
this.isFocused = true;
this.open(false);
}
} | Create timeout which delays when the toast closes | _handleFocus | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
_handleBlur() {
this.isFocused = false;
this.close();
} | Create timeout which delays when the toast closes | _handleBlur | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
_getAttributeOptions() {
let attributeOptions = {};
let tooltipTextOption = this.el.getAttribute('data-tooltip');
let positionOption = this.el.getAttribute('data-position');
if (tooltipTextOption) {
attributeOptions.html = tooltipTextOption;
}
if (positionOption) {
attributeOptions.position = positionOption;
}
return attributeOptions;
} | Create timeout which delays when the toast closes | _getAttributeOptions | javascript | Dogfalo/materialize | js/tooltip.js | https://github.com/Dogfalo/materialize/blob/master/js/tooltip.js | MIT |
function getWavesEffectElement(e) {
if (TouchHandler.allowEvent(e) === false) {
return null;
}
var element = null;
var target = e.target || e.srcElement;
while (target.parentNode !== null) {
if (!(target instanceof SVGElement) && target.className.indexOf('waves-effect') !== -1) {
element = target;
break;
}
target = target.parentNode;
}
return element;
} | Delegated click handler for .waves-effect element.
returns null when .waves-effect element not in "click tree" | getWavesEffectElement | javascript | Dogfalo/materialize | js/waves.js | https://github.com/Dogfalo/materialize/blob/master/js/waves.js | MIT |
function showEffect(e) {
var element = getWavesEffectElement(e);
if (element !== null) {
Effect.show(e, element);
if ('ontouchstart' in window) {
element.addEventListener('touchend', Effect.hide, false);
element.addEventListener('touchcancel', Effect.hide, false);
}
element.addEventListener('mouseup', Effect.hide, false);
element.addEventListener('mouseleave', Effect.hide, false);
element.addEventListener('dragend', Effect.hide, false);
}
} | Bubble the click and show effect if .waves-effect elem was found | showEffect | javascript | Dogfalo/materialize | js/waves.js | https://github.com/Dogfalo/materialize/blob/master/js/waves.js | MIT |
function compareBindingAndReference({ binding, refPath, stmts }) {
const state = {
binding: null,
reference: null
};
for (const [idx, stmt] of stmts.entries()) {
if (isAncestor(stmt, binding.path)) {
state.binding = { idx };
}
for (const ref of binding.referencePaths) {
if (ref === refPath && isAncestor(stmt, ref)) {
state.reference = {
idx,
scope: binding.path.scope === ref.scope ? "current" : "other"
};
break;
}
}
}
return state;
} | Handle when binding is created inside a parent block and
the corresponding parent is removed by other plugins
if (false) { var a } -> var a | compareBindingAndReference | javascript | babel/minify | packages/babel-helper-evaluate-path/src/index.js | https://github.com/babel/minify/blob/master/packages/babel-helper-evaluate-path/src/index.js | MIT |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.