Add local default icon + implements files search cache
This commit is contained in:
@ -3,6 +3,7 @@ var Util = require('../util');
|
||||
var LazyLoad = require('./mixins/lazy-load');
|
||||
|
||||
var LOADING_ICON = 'img/hourglass.svg';
|
||||
var DEFAULT_ICON = 'img/default-icon.svg';
|
||||
|
||||
module.exports = React.createClass({
|
||||
|
||||
@ -53,7 +54,6 @@ module.exports = React.createClass({
|
||||
_findIcon: function(iconPath, theme) {
|
||||
|
||||
var self = this;
|
||||
var DEFAULT_ICON = 'application-default-icon';
|
||||
|
||||
console.log('Search icon %s:%s', iconPath, theme);
|
||||
|
||||
|
@ -34,6 +34,10 @@ module.exports = React.createClass({
|
||||
);
|
||||
});
|
||||
|
||||
options.unshift(
|
||||
<option key="__none__"></option>
|
||||
);
|
||||
|
||||
return (
|
||||
<select value={selectedTheme} onChange={this.onChange}>
|
||||
{options}
|
||||
|
@ -1,5 +1,7 @@
|
||||
var React = require('react');
|
||||
|
||||
var _listeners = [];
|
||||
|
||||
module.exports = {
|
||||
|
||||
isInViewport: function() {
|
||||
@ -10,35 +12,54 @@ module.exports = {
|
||||
|
||||
var rect = el.getBoundingClientRect();
|
||||
|
||||
var viewportHeight = global.window.innerHeight || global.document.documentElement.clientHeight;
|
||||
var viewportWidth = global.window.innerWidth || global.document.documentElement.clientWidth;
|
||||
|
||||
return (
|
||||
rect.top >= 0 &&
|
||||
rect.left >= 0 &&
|
||||
rect.bottom <= (global.window.innerHeight || global.document.documentElement.clientHeight) && /*or $(window).height() */
|
||||
rect.right <= (global.window.innerWidth || global.document.documentElement.clientWidth) /*or $(window).width() */
|
||||
rect.bottom >= 0 &&
|
||||
rect.right >= 0 &&
|
||||
rect.top <= viewportHeight &&
|
||||
rect.left <= viewportWidth
|
||||
);
|
||||
|
||||
},
|
||||
|
||||
componentDidMount: function() {
|
||||
|
||||
function _onInViewport(){
|
||||
if(typeof this.onInViewport === 'function') {
|
||||
|
||||
_listeners.push(this);
|
||||
|
||||
if( this.isInViewport() ) {
|
||||
this.onInViewport();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
var el = React.findDOMNode(this);
|
||||
|
||||
if(typeof this.onInViewport === 'function') {
|
||||
window.document.addEventListener('scroll', debounce(_onInViewport.bind(this), 250), true);
|
||||
}
|
||||
|
||||
_onInViewport.call(this);
|
||||
},
|
||||
|
||||
componentWillUnmount: function() {
|
||||
var index = _listeners.indexOf(this);
|
||||
if(index !== -1) return _listeners.splice(index, 1);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
var computeComponentsVisibilityDebounced = debounce(computeComponentsVisibility, 250);
|
||||
|
||||
// Start listening for changes
|
||||
window.document.addEventListener('scroll', computeComponentsVisibilityDebounced, true);
|
||||
window.addEventListener('resize', computeComponentsVisibilityDebounced);
|
||||
|
||||
function computeComponentsVisibility() {
|
||||
_listeners.forEach(function(listener) {
|
||||
if( listener.isInViewport() ) {
|
||||
listener.onInViewport();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function debounce(func, wait, immediate) {
|
||||
var timeout;
|
||||
return function() {
|
||||
|
Reference in New Issue
Block a user