fixed memory leaks, updated libs, switched to jquery

This commit is contained in:
Antelle 2016-02-07 12:16:24 +03:00
parent 8119c75412
commit 1df736d85b
13 changed files with 44 additions and 63 deletions

View File

@ -172,7 +172,7 @@ module.exports = function(grunt) {
js: {
entry: {
app: 'app',
vendor: ['zepto', 'jquery', 'underscore', 'backbone', 'kdbxweb', 'baron', 'dropbox', 'pikaday', 'filesaver']
vendor: ['jquery', 'underscore', 'backbone', 'kdbxweb', 'baron', 'dropbox', 'pikaday', 'filesaver']
},
output: {
path: 'tmp/js',
@ -191,8 +191,7 @@ module.exports = function(grunt) {
backbone: 'backbone/backbone-min.js',
underscore: 'underscore/underscore-min.js',
_: 'underscore/underscore-min.js',
zepto: 'zepto/zepto.min.js',
jquery: 'zepto/zepto.min.js',
jquery: 'jquery/dist/jquery.min.js',
hbs: 'handlebars/runtime.js',
kdbxweb: 'kdbxweb/dist/kdbxweb.js',
dropbox: 'dropbox/lib/dropbox.min.js',
@ -213,7 +212,6 @@ module.exports = function(grunt) {
{ pattern: /@@DATE/g, replacement: function() { return dt; } },
{ pattern: /@@COMMIT/g, replacement: function() { return grunt.config.get('gitinfo.local.branch.current.shortSHA'); } }
]})},
{ test: /zepto(\.min)?\.js$/, loader: 'exports?Zepto; delete window.$; delete window.Zepto;' },
{ test: /baron(\.min)?\.js$/, loader: 'exports?baron; delete window.baron;' },
{ test: /pikadat\.js$/, loader: 'uglify' },
{ test: /handlebars/, loader: 'strip-sourcemap-loader' }

View File

@ -9,7 +9,11 @@ var isEnabled = FeatureDetector.isDesktop();
var Scrollable = {
createScroll: function(opts) {
opts.$ = Backbone.$;
//opts.cssGuru = true;
if (isEnabled) {
if (this.scroll) {
this.removeScroll();
}
this.scroll = baron(opts);
}
this.scroller = this.$el.find('.scroller');
@ -17,6 +21,18 @@ var Scrollable = {
this.scrollerBarWrapper = this.$el.find('.scroller__bar-wrapper');
},
removeScroll: function() {
if (this.scroll) {
this.scroll.dispose();
// TODO: remove once the bug in custom scrollbar is resolved
var ix = baron._instances.indexOf(this.scroll[0]);
if (ix >= 0) {
baron._instances.splice(ix, 1);
}
this.scroll = null;
}
},
pageResized: function() {
// TODO: check size on window resize
//if (this.checkSize && (!e || e.source === 'window')) {

View File

@ -42,18 +42,22 @@ _.extend(Backbone.View.prototype, {
},
renderTemplate: function(model, replace) {
if (replace) {
this.$el.html('');
}
var el = $(this.template(model));
if (!this._elAppended || replace) {
this.$el.append(el);
this._elAppended = true;
if (replace && replace.plain) {
this.$el.html(this.template(model));
} else {
this.$el.replaceWith(el);
if (replace) {
this.$el.html('');
}
var el = $(this.template(model));
if (!this._elAppended || replace) {
this.$el.append(el);
this._elAppended = true;
} else {
this.$el.replaceWith(el);
}
this.setElement(el);
}
this.setElement(el);
Tip.createTips(el);
Tip.createTips(this.$el);
},
_parentRemove: Backbone.View.prototype.remove,

View File

@ -138,11 +138,8 @@ Tip.createTips = function(container) {
return;
}
container.find('[title]').each(function(ix, el) {
if (!el._tip) {
var tip = new Tip($(el));
tip.init();
el._tip = tip;
}
var tip = new Tip($(el));
tip.init();
});
};

View File

@ -78,6 +78,7 @@ var DetailsView = Backbone.View.extend({
},
render: function () {
this.removeScroll();
this.removeFieldViews();
if (this.views.sub) {
this.views.sub.remove();

View File

@ -4,7 +4,6 @@ var Backbone = require('backbone'),
Keys = require('../const/keys'),
KeyHandler = require('../comp/key-handler'),
GeneratorView = require('./generator-view'),
Tip = require('../util/tip'),
UpdateModel = require('../models/update-model');
var FooterView = Backbone.View.extend({
@ -33,11 +32,10 @@ var FooterView = Backbone.View.extend({
},
render: function () {
this.$el.html(this.template({
this.renderTemplate({
files: this.model.files,
updateAvailable: ['ready', 'found'].indexOf(UpdateModel.instance.get('updateStatus')) >= 0
}));
Tip.createTips(this.$el);
}, { plain: true });
return this;
},

View File

@ -2,8 +2,7 @@
var Backbone = require('backbone'),
Scrollable = require('../mixins/scrollable'),
IconSelectView = require('./icon-select-view'),
Tip = require('../util/tip');
IconSelectView = require('./icon-select-view');
var GrpView = Backbone.View.extend({
template: require('templates/grp.hbs'),
@ -23,14 +22,13 @@ var GrpView = Backbone.View.extend({
render: function() {
this.removeSubView();
if (this.model) {
this.$el.html(this.template({
this.renderTemplate({
title: this.model.get('title'),
icon: this.model.get('icon') || 'folder',
customIcon: this.model.get('customIcon'),
enableSearching: this.model.get('enableSearching') !== false,
readonly: this.model.get('top')
}));
Tip.createTips(this.$el);
}, { plain: true });
if (!this.model.get('title')) {
this.$el.find('#grp__field-title').focus();
}

View File

@ -132,10 +132,6 @@
@include flex-wrap(wrap);
overflow-x: hidden;
padding-top: 3px;
@include scrollbar-full-width-hack();
@-moz-document url-prefix() { @include scrollbar-padding-hack(); }
@at-root { _:-ms-lang(x), .details__body>.scroller { @include scrollbar-padding-hack(); } }
@media screen and (-webkit-min-device-pixel-ratio:0) { width: 100% !important; }
}

View File

@ -21,11 +21,6 @@
@include flex(1);
@include align-self(stretch);
position: relative;
.app__list-wrap--table & {
@include scrollbar-full-width-hack();
@-moz-document url-prefix() { @include scrollbar-padding-hack(); }
@at-root { _:-ms-lang(x), .app__list-wrap--table .list__items>.scroller { @include scrollbar-padding-hack(); } }
}
@include mobile {
width: 100% !important;
max-width: 100% !important;

View File

@ -12,9 +12,6 @@
>.scroller {
@include flex(1 0 0);
@include scrollbar-full-width-hack();
@-moz-document url-prefix() { @include scrollbar-padding-hack(); }
@at-root { _:-ms-lang(x), .settings>.scroller { @include scrollbar-padding-hack(); } }
}
h2,h3 {

View File

@ -1,24 +1,6 @@
@mixin scrollbar-padding-hack {
// workaround for bugs in custom scrollbar component (baron)
// https://github.com/Diokuz/baron/issues/91
// https://github.com/Diokuz/baron/issues/93
margin-right: -30px !important;
padding-right: 30px !important;
}
@mixin scrollbar-full-width-hack {
// workaround for bugs in custom scrollbar component (baron)
width: auto !important;
min-width: 0 !important;
max-width: none !important;
}
.scroller {
overflow-y: scroll;
height: 100%;
@-moz-document url-prefix() {
@include scrollbar-padding-hack();
}
&::-webkit-scrollbar {
width: 0;
}

View File

@ -9,8 +9,7 @@
<li><a href="http://electron.atom.io/" target="_blank">electron</a><span class="muted-color">, cross-platform desktop apps framework</span></li>
<li><a href="http://backbonejs.org/" target="_blank">backbone</a><span class="muted-color">, JavaScript framework</span></li>
<li><a href="http://underscorejs.org/" target="_blank">underscore</a><span class="muted-color">, utility-belt library for JavaScript</span></li>
<li><a href="http://zeptojs.com/" target="_blank">zepto.js</a><span class="muted-color">, a minimalist JavaScript library for modern browsers,
with a jQuery-compatible API</span></li>
<li><a href="https://jquery.com/" target="_blank">jQuery</a><span class="muted-color">, fast, small, and feature-rich JavaScript library</span></li>
<li><a href="http://handlebarsjs.com/" target="_blank">handlebars</a><span class="muted-color">, semantic templates</span></li>
<li><a href="https://github.com/dropbox/dropbox-js" target="_blank">dropbox-js</a><span class="muted-color">, unofficial JavaScript library for
the Dropbox Core API</span></li>

View File

@ -24,7 +24,7 @@
"private": true,
"dependencies": {
"backbone": "~1.2.3",
"baron": "~1.0.1",
"baron": "~2.0.1",
"bourbon": "~4.2.5",
"dropbox": "antelle/dropbox-js#0.10.6",
"font-awesome": "~4.4.0",
@ -32,7 +32,7 @@
"kdbxweb": "~0.3.3",
"normalize.css": "~3.0.3",
"pikaday": "~1.3.3",
"zepto": "~1.1.6",
"FileSaver.js": "eligrey/FileSaver.js"
"FileSaver.js": "eligrey/FileSaver.js",
"jquery": "~2.2.0"
}
}