Now I need to figure out how to get the Feature.ready code to run
This commit is contained in:
parent
b87825e558
commit
c47b14f0bf
@ -821,7 +821,7 @@
|
|||||||
var cb, name;
|
var cb, name;
|
||||||
name = _arg.name, cb = _arg.cb;
|
name = _arg.name, cb = _arg.cb;
|
||||||
if (this[name]) {
|
if (this[name]) {
|
||||||
this[name].connect();
|
this.connect(name);
|
||||||
}
|
}
|
||||||
if (!this[name]) {
|
if (!this[name]) {
|
||||||
this.keys.push(name);
|
this.keys.push(name);
|
||||||
@ -829,15 +829,6 @@
|
|||||||
return this[name] = cb;
|
return this[name] = cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
Callbacks.prototype.clean = function() {
|
|
||||||
var name, _i, _len, _ref;
|
|
||||||
_ref = this.keys;
|
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
||||||
name = _ref[_i];
|
|
||||||
this.rm(name);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Callbacks.prototype.connect = function(name) {
|
Callbacks.prototype.connect = function(name) {
|
||||||
if (this[name]) {
|
if (this[name]) {
|
||||||
return delete this[name].disconnected;
|
return delete this[name].disconnected;
|
||||||
@ -1571,7 +1562,9 @@
|
|||||||
root.next = item;
|
root.next = item;
|
||||||
item.prev = root;
|
item.prev = root;
|
||||||
item.next = next;
|
item.next = next;
|
||||||
return next.prev = item;
|
if (next) {
|
||||||
|
return next.prev = item;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
RandomAccessList.prototype.prepend = function(item) {
|
RandomAccessList.prototype.prepend = function(item) {
|
||||||
@ -8769,14 +8762,11 @@
|
|||||||
|
|
||||||
ThreadUpdater = {
|
ThreadUpdater = {
|
||||||
init: function() {
|
init: function() {
|
||||||
|
var checked, conf, el, input, name, sc, subEntries, _ref,
|
||||||
|
_this = this;
|
||||||
if (g.VIEW !== 'thread' || !Conf['Thread Updater']) {
|
if (g.VIEW !== 'thread' || !Conf['Thread Updater']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return ThreadUpdater.connect.call(this);
|
|
||||||
},
|
|
||||||
connect: function() {
|
|
||||||
var checked, conf, el, input, name, sc, subEntries, _ref,
|
|
||||||
_this = this;
|
|
||||||
if (Conf['Updater and Stats in Header']) {
|
if (Conf['Updater and Stats in Header']) {
|
||||||
this.dialog = sc = $.el('span', {
|
this.dialog = sc = $.el('span', {
|
||||||
innerHTML: "<span id=update-status></span><span id=update-timer title='Update now'></span>",
|
innerHTML: "<span id=update-status></span><span id=update-timer title='Update now'></span>",
|
||||||
@ -9672,9 +9662,6 @@
|
|||||||
if (g.VIEW !== 'thread' || !Conf['Unread Count'] && !Conf['Unread Favicon'] && !Conf['Desktop Notifications']) {
|
if (g.VIEW !== 'thread' || !Conf['Unread Count'] && !Conf['Unread Favicon'] && !Conf['Desktop Notifications']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return Unread.connect.call(this);
|
|
||||||
},
|
|
||||||
connect: function() {
|
|
||||||
this.db = new DataBoard('lastReadPosts', this.sync);
|
this.db = new DataBoard('lastReadPosts', this.sync);
|
||||||
this.hr = $.el('hr', {
|
this.hr = $.el('hr', {
|
||||||
id: 'unread-line'
|
id: 'unread-line'
|
||||||
@ -11863,13 +11850,14 @@
|
|||||||
g.BOARD.threads = {};
|
g.BOARD.threads = {};
|
||||||
return $.rmAll($('.board'));
|
return $.rmAll($('.board'));
|
||||||
},
|
},
|
||||||
|
threadFeatures: [['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater]],
|
||||||
disconnect: function() {
|
disconnect: function() {
|
||||||
var err, errors, feature, features, name, _i, _len, _ref;
|
var err, errors, feature, features, name, _i, _len, _ref;
|
||||||
features = g.VIEW === 'thread' ? [['Thread Updater', ThreadUpdater], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats]] : [];
|
features = g.VIEW === 'thread' ? Navigate.threadFeatures : [];
|
||||||
for (_i = 0, _len = features.length; _i < _len; _i++) {
|
for (_i = 0, _len = features.length; _i < _len; _i++) {
|
||||||
_ref = features[_i], name = _ref[0], feature = _ref[1];
|
_ref = features[_i], name = _ref[0], feature = _ref[1];
|
||||||
try {
|
try {
|
||||||
feature.disconnect.call(feature);
|
feature.disconnect();
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
err = _error;
|
err = _error;
|
||||||
if (!errors) {
|
if (!errors) {
|
||||||
@ -11885,6 +11873,28 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
reconnect: function() {
|
||||||
|
var err, errors, feature, features, name, _i, _len, _ref;
|
||||||
|
features = g.VIEW === 'thread' ? Navigate.threadFeatures : [];
|
||||||
|
for (_i = 0, _len = features.length; _i < _len; _i++) {
|
||||||
|
_ref = features[_i], name = _ref[0], feature = _ref[1];
|
||||||
|
try {
|
||||||
|
feature.init();
|
||||||
|
} catch (_error) {
|
||||||
|
err = _error;
|
||||||
|
if (!errors) {
|
||||||
|
errors = [];
|
||||||
|
}
|
||||||
|
errors.push({
|
||||||
|
message: "Failed to reconnect feature " + name + ".",
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (errors) {
|
||||||
|
Main.handleErrors(errors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
updateContext: function(view) {
|
updateContext: function(view) {
|
||||||
$.rmClass(doc, g.VIEW);
|
$.rmClass(doc, g.VIEW);
|
||||||
$.addClass(doc, view);
|
$.addClass(doc, view);
|
||||||
@ -11915,6 +11925,7 @@
|
|||||||
Navigate.disconnect();
|
Navigate.disconnect();
|
||||||
Navigate.clean();
|
Navigate.clean();
|
||||||
Navigate.updateContext(view);
|
Navigate.updateContext(view);
|
||||||
|
Navigate.reconnect();
|
||||||
}
|
}
|
||||||
if (view === 'index') {
|
if (view === 'index') {
|
||||||
if (boardID !== g.BOARD.ID) {
|
if (boardID !== g.BOARD.ID) {
|
||||||
@ -11944,6 +11955,8 @@
|
|||||||
try {
|
try {
|
||||||
if (req.status === 200) {
|
if (req.status === 200) {
|
||||||
Navigate.parse(JSON.parse(req.response).posts);
|
Navigate.parse(JSON.parse(req.response).posts);
|
||||||
|
$.on(d, '4chanXInitFinished', Navigate.finish);
|
||||||
|
return $.event('4chanXInitFinished');
|
||||||
}
|
}
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
err = _error;
|
err = _error;
|
||||||
@ -11956,8 +11969,10 @@
|
|||||||
} else {
|
} else {
|
||||||
new Notice('error', 'Navigation Failed.', 2);
|
new Notice('error', 'Navigation Failed.', 2);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
finish: function() {
|
||||||
|
$.off(d, '4chanXInitFinished', Navigate.finish);
|
||||||
Navigate.buildThread();
|
Navigate.buildThread();
|
||||||
return Header.scrollToIfNeeded($('.board'));
|
return Header.scrollToIfNeeded($('.board'));
|
||||||
},
|
},
|
||||||
|
|||||||
@ -826,7 +826,7 @@
|
|||||||
var cb, name;
|
var cb, name;
|
||||||
name = _arg.name, cb = _arg.cb;
|
name = _arg.name, cb = _arg.cb;
|
||||||
if (this[name]) {
|
if (this[name]) {
|
||||||
this[name].connect();
|
this.connect(name);
|
||||||
}
|
}
|
||||||
if (!this[name]) {
|
if (!this[name]) {
|
||||||
this.keys.push(name);
|
this.keys.push(name);
|
||||||
@ -834,15 +834,6 @@
|
|||||||
return this[name] = cb;
|
return this[name] = cb;
|
||||||
};
|
};
|
||||||
|
|
||||||
Callbacks.prototype.clean = function() {
|
|
||||||
var name, _i, _len, _ref;
|
|
||||||
_ref = this.keys;
|
|
||||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
|
||||||
name = _ref[_i];
|
|
||||||
this.rm(name);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
Callbacks.prototype.connect = function(name) {
|
Callbacks.prototype.connect = function(name) {
|
||||||
if (this[name]) {
|
if (this[name]) {
|
||||||
return delete this[name].disconnected;
|
return delete this[name].disconnected;
|
||||||
@ -1577,7 +1568,9 @@
|
|||||||
root.next = item;
|
root.next = item;
|
||||||
item.prev = root;
|
item.prev = root;
|
||||||
item.next = next;
|
item.next = next;
|
||||||
return next.prev = item;
|
if (next) {
|
||||||
|
return next.prev = item;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
RandomAccessList.prototype.prepend = function(item) {
|
RandomAccessList.prototype.prepend = function(item) {
|
||||||
@ -8752,14 +8745,11 @@
|
|||||||
|
|
||||||
ThreadUpdater = {
|
ThreadUpdater = {
|
||||||
init: function() {
|
init: function() {
|
||||||
|
var checked, conf, el, input, name, sc, subEntries, _ref,
|
||||||
|
_this = this;
|
||||||
if (g.VIEW !== 'thread' || !Conf['Thread Updater']) {
|
if (g.VIEW !== 'thread' || !Conf['Thread Updater']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return ThreadUpdater.connect.call(this);
|
|
||||||
},
|
|
||||||
connect: function() {
|
|
||||||
var checked, conf, el, input, name, sc, subEntries, _ref,
|
|
||||||
_this = this;
|
|
||||||
if (Conf['Updater and Stats in Header']) {
|
if (Conf['Updater and Stats in Header']) {
|
||||||
this.dialog = sc = $.el('span', {
|
this.dialog = sc = $.el('span', {
|
||||||
innerHTML: "<span id=update-status></span><span id=update-timer title='Update now'></span>",
|
innerHTML: "<span id=update-status></span><span id=update-timer title='Update now'></span>",
|
||||||
@ -9655,9 +9645,6 @@
|
|||||||
if (g.VIEW !== 'thread' || !Conf['Unread Count'] && !Conf['Unread Favicon'] && !Conf['Desktop Notifications']) {
|
if (g.VIEW !== 'thread' || !Conf['Unread Count'] && !Conf['Unread Favicon'] && !Conf['Desktop Notifications']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
return Unread.connect.call(this);
|
|
||||||
},
|
|
||||||
connect: function() {
|
|
||||||
this.db = new DataBoard('lastReadPosts', this.sync);
|
this.db = new DataBoard('lastReadPosts', this.sync);
|
||||||
this.hr = $.el('hr', {
|
this.hr = $.el('hr', {
|
||||||
id: 'unread-line'
|
id: 'unread-line'
|
||||||
@ -11852,13 +11839,14 @@
|
|||||||
g.BOARD.threads = {};
|
g.BOARD.threads = {};
|
||||||
return $.rmAll($('.board'));
|
return $.rmAll($('.board'));
|
||||||
},
|
},
|
||||||
|
threadFeatures: [['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats], ['Thread Updater', ThreadUpdater]],
|
||||||
disconnect: function() {
|
disconnect: function() {
|
||||||
var err, errors, feature, features, name, _i, _len, _ref;
|
var err, errors, feature, features, name, _i, _len, _ref;
|
||||||
features = g.VIEW === 'thread' ? [['Thread Updater', ThreadUpdater], ['Unread Count', Unread], ['Quote Threading', QuoteThreading], ['Thread Stats', ThreadStats]] : [];
|
features = g.VIEW === 'thread' ? Navigate.threadFeatures : [];
|
||||||
for (_i = 0, _len = features.length; _i < _len; _i++) {
|
for (_i = 0, _len = features.length; _i < _len; _i++) {
|
||||||
_ref = features[_i], name = _ref[0], feature = _ref[1];
|
_ref = features[_i], name = _ref[0], feature = _ref[1];
|
||||||
try {
|
try {
|
||||||
feature.disconnect.call(feature);
|
feature.disconnect();
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
err = _error;
|
err = _error;
|
||||||
if (!errors) {
|
if (!errors) {
|
||||||
@ -11874,6 +11862,28 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
reconnect: function() {
|
||||||
|
var err, errors, feature, features, name, _i, _len, _ref;
|
||||||
|
features = g.VIEW === 'thread' ? Navigate.threadFeatures : [];
|
||||||
|
for (_i = 0, _len = features.length; _i < _len; _i++) {
|
||||||
|
_ref = features[_i], name = _ref[0], feature = _ref[1];
|
||||||
|
try {
|
||||||
|
feature.init();
|
||||||
|
} catch (_error) {
|
||||||
|
err = _error;
|
||||||
|
if (!errors) {
|
||||||
|
errors = [];
|
||||||
|
}
|
||||||
|
errors.push({
|
||||||
|
message: "Failed to reconnect feature " + name + ".",
|
||||||
|
error: err
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (errors) {
|
||||||
|
Main.handleErrors(errors);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
updateContext: function(view) {
|
updateContext: function(view) {
|
||||||
$.rmClass(doc, g.VIEW);
|
$.rmClass(doc, g.VIEW);
|
||||||
$.addClass(doc, view);
|
$.addClass(doc, view);
|
||||||
@ -11904,6 +11914,7 @@
|
|||||||
Navigate.disconnect();
|
Navigate.disconnect();
|
||||||
Navigate.clean();
|
Navigate.clean();
|
||||||
Navigate.updateContext(view);
|
Navigate.updateContext(view);
|
||||||
|
Navigate.reconnect();
|
||||||
}
|
}
|
||||||
if (view === 'index') {
|
if (view === 'index') {
|
||||||
if (boardID !== g.BOARD.ID) {
|
if (boardID !== g.BOARD.ID) {
|
||||||
@ -11933,6 +11944,8 @@
|
|||||||
try {
|
try {
|
||||||
if (req.status === 200) {
|
if (req.status === 200) {
|
||||||
Navigate.parse(JSON.parse(req.response).posts);
|
Navigate.parse(JSON.parse(req.response).posts);
|
||||||
|
$.on(d, '4chanXInitFinished', Navigate.finish);
|
||||||
|
return $.event('4chanXInitFinished');
|
||||||
}
|
}
|
||||||
} catch (_error) {
|
} catch (_error) {
|
||||||
err = _error;
|
err = _error;
|
||||||
@ -11945,8 +11958,10 @@
|
|||||||
} else {
|
} else {
|
||||||
new Notice('error', 'Navigation Failed.', 2);
|
new Notice('error', 'Navigation Failed.', 2);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
finish: function() {
|
||||||
|
$.off(d, '4chanXInitFinished', Navigate.finish);
|
||||||
Navigate.buildThread();
|
Navigate.buildThread();
|
||||||
return Header.scrollToIfNeeded($('.board'));
|
return Header.scrollToIfNeeded($('.board'));
|
||||||
},
|
},
|
||||||
|
|||||||
@ -34,20 +34,22 @@ Navigate =
|
|||||||
# Delete nodes
|
# Delete nodes
|
||||||
$.rmAll $ '.board'
|
$.rmAll $ '.board'
|
||||||
|
|
||||||
|
threadFeatures: [
|
||||||
|
['Unread Count', Unread]
|
||||||
|
['Quote Threading', QuoteThreading]
|
||||||
|
['Thread Stats', ThreadStats]
|
||||||
|
['Thread Updater', ThreadUpdater]
|
||||||
|
]
|
||||||
|
|
||||||
disconnect: ->
|
disconnect: ->
|
||||||
features = if g.VIEW is 'thread'
|
features = if g.VIEW is 'thread'
|
||||||
[
|
Navigate.threadFeatures
|
||||||
['Thread Updater', ThreadUpdater]
|
|
||||||
['Unread Count', Unread]
|
|
||||||
['Quote Threading', QuoteThreading]
|
|
||||||
['Thread Stats', ThreadStats]
|
|
||||||
]
|
|
||||||
else
|
else
|
||||||
[]
|
[]
|
||||||
|
|
||||||
for [name, feature] in features
|
for [name, feature] in features
|
||||||
try
|
try
|
||||||
feature.disconnect.call feature
|
feature.disconnect()
|
||||||
catch err
|
catch err
|
||||||
errors = [] unless errors
|
errors = [] unless errors
|
||||||
errors.push
|
errors.push
|
||||||
@ -58,6 +60,25 @@ Navigate =
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
reconnect: ->
|
||||||
|
features = if g.VIEW is 'thread'
|
||||||
|
Navigate.threadFeatures
|
||||||
|
else
|
||||||
|
[]
|
||||||
|
|
||||||
|
for [name, feature] in features
|
||||||
|
try
|
||||||
|
feature.init()
|
||||||
|
catch err
|
||||||
|
errors = [] unless errors
|
||||||
|
errors.push
|
||||||
|
message: "Failed to reconnect feature #{name}."
|
||||||
|
error: err
|
||||||
|
|
||||||
|
Main.handleErrors errors if errors
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
updateContext: (view) ->
|
updateContext: (view) ->
|
||||||
$.rmClass doc, g.VIEW
|
$.rmClass doc, g.VIEW
|
||||||
$.addClass doc, view
|
$.addClass doc, view
|
||||||
@ -85,6 +106,7 @@ Navigate =
|
|||||||
Navigate.disconnect()
|
Navigate.disconnect()
|
||||||
Navigate.clean()
|
Navigate.clean()
|
||||||
Navigate.updateContext view
|
Navigate.updateContext view
|
||||||
|
Navigate.reconnect()
|
||||||
|
|
||||||
if view is 'index'
|
if view is 'index'
|
||||||
Navigate.updateBoard boardID unless boardID is g.BOARD.ID
|
Navigate.updateBoard boardID unless boardID is g.BOARD.ID
|
||||||
@ -112,6 +134,8 @@ Navigate =
|
|||||||
try
|
try
|
||||||
if req.status is 200
|
if req.status is 200
|
||||||
Navigate.parse JSON.parse(req.response).posts
|
Navigate.parse JSON.parse(req.response).posts
|
||||||
|
$.on d, '4chanXInitFinished', Navigate.finish
|
||||||
|
$.event '4chanXInitFinished'
|
||||||
catch err
|
catch err
|
||||||
console.error 'Navigate failure:'
|
console.error 'Navigate failure:'
|
||||||
console.log err
|
console.log err
|
||||||
@ -124,8 +148,9 @@ Navigate =
|
|||||||
new Notice 'error', 'Navigation Failed.', 2
|
new Notice 'error', 'Navigation Failed.', 2
|
||||||
return
|
return
|
||||||
|
|
||||||
|
finish: ->
|
||||||
|
$.off d, '4chanXInitFinished', Navigate.finish
|
||||||
Navigate.buildThread()
|
Navigate.buildThread()
|
||||||
|
|
||||||
Header.scrollToIfNeeded $ '.board'
|
Header.scrollToIfNeeded $ '.board'
|
||||||
|
|
||||||
parse: (data) ->
|
parse: (data) ->
|
||||||
|
|||||||
@ -3,14 +3,10 @@ class Callbacks
|
|||||||
@keys = []
|
@keys = []
|
||||||
|
|
||||||
push: ({name, cb}) ->
|
push: ({name, cb}) ->
|
||||||
@[name].connect() if @[name]
|
@connect name if @[name]
|
||||||
@keys.push name unless @[name]
|
@keys.push name unless @[name]
|
||||||
@[name] = cb
|
@[name] = cb
|
||||||
|
|
||||||
clean: ->
|
|
||||||
@rm name for name in @keys
|
|
||||||
return
|
|
||||||
|
|
||||||
connect: (name) -> delete @[name].disconnected if @[name]
|
connect: (name) -> delete @[name].disconnected if @[name]
|
||||||
disconnect: (name) -> @[name].disconnected = true if @[name]
|
disconnect: (name) -> @[name].disconnected = true if @[name]
|
||||||
|
|
||||||
|
|||||||
@ -23,7 +23,7 @@ class RandomAccessList
|
|||||||
root.next = item
|
root.next = item
|
||||||
item.prev = root
|
item.prev = root
|
||||||
item.next = next
|
item.next = next
|
||||||
next.prev = item
|
next.prev = item if next
|
||||||
|
|
||||||
prepend: (item) ->
|
prepend: (item) ->
|
||||||
{first} = @
|
{first} = @
|
||||||
|
|||||||
@ -2,9 +2,6 @@ ThreadUpdater =
|
|||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW isnt 'thread' or !Conf['Thread Updater']
|
return if g.VIEW isnt 'thread' or !Conf['Thread Updater']
|
||||||
|
|
||||||
ThreadUpdater.connect.call @
|
|
||||||
|
|
||||||
connect: ->
|
|
||||||
if Conf['Updater and Stats in Header']
|
if Conf['Updater and Stats in Header']
|
||||||
@dialog = sc = $.el 'span',
|
@dialog = sc = $.el 'span',
|
||||||
innerHTML: "<span id=update-status></span><span id=update-timer title='Update now'></span>"
|
innerHTML: "<span id=update-status></span><span id=update-timer title='Update now'></span>"
|
||||||
|
|||||||
@ -2,9 +2,6 @@ Unread =
|
|||||||
init: ->
|
init: ->
|
||||||
return if g.VIEW isnt 'thread' or !Conf['Unread Count'] and !Conf['Unread Favicon'] and !Conf['Desktop Notifications']
|
return if g.VIEW isnt 'thread' or !Conf['Unread Count'] and !Conf['Unread Favicon'] and !Conf['Desktop Notifications']
|
||||||
|
|
||||||
Unread.connect.call this
|
|
||||||
|
|
||||||
connect: ->
|
|
||||||
@db = new DataBoard 'lastReadPosts', @sync
|
@db = new DataBoard 'lastReadPosts', @sync
|
||||||
@hr = $.el 'hr',
|
@hr = $.el 'hr',
|
||||||
id: 'unread-line'
|
id: 'unread-line'
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user