editor: only restore state for dirty widgets; restore scroll state
manager: list scrolling widgets
This commit is contained in:
parent
04a322dda1
commit
7e87970e23
3 changed files with 59 additions and 7 deletions
|
|
@ -23,8 +23,22 @@ var updateDom = function(container,data, remote) {
|
|||
|
||||
// save state
|
||||
var scroll = $('#sidepanel').scrollTop(),
|
||||
state = actions.stateGet(),
|
||||
purge = container[0].abstract.hashes || [container[0].abstract.hash]
|
||||
oldWidgets = container[0].abstract.hashes || [container[0].abstract.hash],
|
||||
wState = {},
|
||||
wScroll = {}
|
||||
|
||||
for (let h of oldWidgets) {
|
||||
if (widgetManager.widgets[h]) {
|
||||
wState[widgetManager.widgets[h].getProp('id')] = widgetManager.widgets[h].getValue()
|
||||
}
|
||||
}
|
||||
|
||||
// save scroll states
|
||||
for (let h of widgetManager.scrollingWidgets) {
|
||||
if (widgetManager.widgets[h] && widgetManager.widgets[h].scroll) {
|
||||
wScroll[widgetManager.widgets[h].getProp('id')] = widgetManager.widgets[h].scroll()
|
||||
}
|
||||
}
|
||||
|
||||
// widget
|
||||
var newContainer = parsewidgets([data], container[0].abstract.parentNode, container[0].abstract.parent)
|
||||
|
|
@ -37,10 +51,22 @@ var updateDom = function(container,data, remote) {
|
|||
|
||||
newContainer.trigger('resize')
|
||||
|
||||
purgeStores(purge)
|
||||
purgeStores(oldWidgets)
|
||||
|
||||
|
||||
// restore state
|
||||
actions.stateSet(state,false)
|
||||
for (let id in wState) {
|
||||
for (let w of widgetManager.getWidgetById(id)) {
|
||||
if (w.setValue) w.setValue(wState[id])
|
||||
}
|
||||
}
|
||||
|
||||
// restore scroll states
|
||||
for (let id in wScroll) {
|
||||
for (let w of widgetManager.getWidgetById(id)) {
|
||||
if (w.scroll) w.scroll(wScroll[id])
|
||||
}
|
||||
}
|
||||
|
||||
if (!remote) {
|
||||
editObject(newContainer,data,true)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ var WidgetManager = function(){
|
|||
this.idRoute = {}
|
||||
this.linkIdRoute = {}
|
||||
|
||||
this.scrollingWidgets = []
|
||||
|
||||
this.preArgsSeparator = '||||'
|
||||
|
||||
$(document).ready(()=>{
|
||||
|
|
@ -75,7 +77,8 @@ WidgetManager.prototype.addWidget = function(widget) {
|
|||
var hash = widget.hash,
|
||||
address = this.createAddressRef(widget),
|
||||
id = widget.getProp('id'),
|
||||
linkId = widget.getProp('linkId')
|
||||
linkId = widget.getProp('linkId'),
|
||||
scroll = widget.getProp('scroll')
|
||||
|
||||
|
||||
this.widgets[hash] = widget
|
||||
|
|
@ -93,6 +96,10 @@ WidgetManager.prototype.addWidget = function(widget) {
|
|||
this.linkIdRoute[linkId].push(hash)
|
||||
}
|
||||
|
||||
if (scroll) {
|
||||
this.scrollingWidgets.push(hash)
|
||||
}
|
||||
|
||||
widget.widget.abstract = widget
|
||||
if (widget.container) widget.container[0].abstract = widget
|
||||
|
||||
|
|
@ -114,7 +121,8 @@ WidgetManager.prototype.removeWidget = function(hash) {
|
|||
var widget = this.widgets[hash],
|
||||
address = this.createAddressRef(widget),
|
||||
linkId = widget.getProp('linkId'),
|
||||
id = widget.getProp('id')
|
||||
id = widget.getProp('id'),
|
||||
scroll = widget.getProp('scroll')
|
||||
|
||||
if (this.widgets[hash]) {
|
||||
if (this.widgets[hash].onRemove) this.widgets[hash].onRemove()
|
||||
|
|
@ -127,6 +135,7 @@ WidgetManager.prototype.removeWidget = function(hash) {
|
|||
if (id && this.idRoute[id].indexOf(hash) != -1) this.idRoute[id].splice(this.idRoute[id].indexOf(hash), 1)
|
||||
if (linkId && this.linkIdRoute[linkId].indexOf(hash) != -1) this.linkIdRoute[linkId].splice(this.linkIdRoute[linkId].indexOf(hash), 1)
|
||||
if (address && this.addressRoute[address].indexOf(hash) != -1) this.addressRoute[address].splice(this.addressRoute[address].indexOf(hash), 1)
|
||||
if (scroll && this.scrollingWidgets.indexOf(hash) != -1) this.scrollingWidgets.splice(this.scrollingWidgets.indexOf(hash), 1)
|
||||
}
|
||||
|
||||
WidgetManager.prototype.purge = function() {
|
||||
|
|
@ -142,6 +151,12 @@ WidgetManager.prototype.purge = function() {
|
|||
}
|
||||
}
|
||||
|
||||
for (let i in this.scrollingWidgets) {
|
||||
if (!this.widgets[this.scrollingWidgets[i]]) {
|
||||
this.scrollingWidgets.splice(i, 1)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
WidgetManager.prototype.reset = function() {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ module.exports = class Panel extends _widgets_base {
|
|||
if (this.getProp('tabs') && this.getProp('tabs').length) this.widget.addClass('has-tabs')
|
||||
|
||||
|
||||
this.value = 0
|
||||
this.value = this.getProp('value') || 0
|
||||
this.tabs = []
|
||||
|
||||
var parsers = require('../../parser'),
|
||||
|
|
@ -189,4 +189,15 @@ module.exports = class Panel extends _widgets_base {
|
|||
}
|
||||
}
|
||||
|
||||
scroll(s) {
|
||||
|
||||
if (!s) {
|
||||
return [this.widget.scrollLeft(), this.widget.scrollTop()]
|
||||
} else {
|
||||
this.widget.scrollLeft(s[0])
|
||||
this.widget.scrollTop(s[1])
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue