move to let/const syntax in custom dojo modules

This commit is contained in:
Andrew Dolgov 2018-11-29 21:21:06 +03:00
parent 9dc5524df1
commit 0267212454
6 changed files with 108 additions and 108 deletions

View File

@ -4,7 +4,7 @@ define(["dojo/_base/declare", "dijit/tree/ForestStoreModel"], function (declare)
getItemsInCategory: function (id) {
if (!this.store._itemsByIdentity) return undefined;
cat = this.store._itemsByIdentity['CAT:' + id];
let cat = this.store._itemsByIdentity['CAT:' + id];
if (cat && cat.items)
return cat.items;
@ -30,7 +30,7 @@ define(["dojo/_base/declare", "dijit/tree/ForestStoreModel"], function (declare)
return this.getFeedValue(feed, is_cat, 'name');
},
getFeedUnread: function (feed, is_cat) {
var unread = parseInt(this.getFeedValue(feed, is_cat, 'unread'));
const unread = parseInt(this.getFeedValue(feed, is_cat, 'unread'));
return (isNaN(unread)) ? 0 : unread;
},
setFeedUnread: function (feed, is_cat, unread) {
@ -58,14 +58,14 @@ define(["dojo/_base/declare", "dijit/tree/ForestStoreModel"], function (declare)
treeItem = this.store._itemsByIdentity['FEED:' + feed];
}
items = this.store._arrayOfAllItems;
let items = this.store._arrayOfAllItems;
for (var i = 0; i < items.length; i++) {
for (let i = 0; i < items.length; i++) {
if (items[i] == treeItem) {
for (var j = i + 1; j < items.length; j++) {
var unread = this.store.getValue(items[j], 'unread');
var id = this.store.getValue(items[j], 'id');
let unread = this.store.getValue(items[j], 'unread');
let id = this.store.getValue(items[j], 'id');
if (unread > 0 && ((is_cat && id.match("CAT:")) || (!is_cat && id.match("FEED:")))) {
if (!is_cat || !(this.store.hasAttribute(items[j], 'parent_id') && this.store.getValue(items[j], 'parent_id') == feed)) return items[j];
@ -73,8 +73,8 @@ define(["dojo/_base/declare", "dijit/tree/ForestStoreModel"], function (declare)
}
for (var j = 0; j < i; j++) {
var unread = this.store.getValue(items[j], 'unread');
var id = this.store.getValue(items[j], 'id');
let unread = this.store.getValue(items[j], 'unread');
let id = this.store.getValue(items[j], 'id');
if (unread > 0 && ((is_cat && id.match("CAT:")) || (!is_cat && id.match("FEED:")))) {
if (!is_cat || !(this.store.hasAttribute(items[j], 'parent_id') && this.store.getValue(items[j], 'parent_id') == feed)) return items[j];

View File

@ -1,3 +1,4 @@
/* global dijit */
define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"], function (declare, domConstruct) {
return declare("fox.FeedTree", dijit.Tree, {
@ -5,9 +6,9 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
return; // Stop dijit.Tree from interpreting keystrokes
},
_createTreeNode: function(args) {
var tnode = new dijit._TreeNode(args);
const tnode = new dijit._TreeNode(args);
var icon = dojo.doc.createElement('img');
const icon = dojo.doc.createElement('img');
if (args.item.icon && args.item.icon[0]) {
icon.src = args.item.icon[0];
} else {
@ -16,13 +17,13 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
icon.className = 'tinyFeedIcon';
domConstruct.place(icon, tnode.iconNode, 'only');
var id = args.item.id[0];
var bare_id = parseInt(id.substr(id.indexOf(':')+1));
const id = args.item.id[0];
const bare_id = parseInt(id.substr(id.indexOf(':')+1));
if (bare_id < _label_base_index) {
var span = dojo.doc.createElement('span');
var fg_color = args.item.fg_color[0];
var bg_color = args.item.bg_color[0];
const span = dojo.doc.createElement('span');
const fg_color = args.item.fg_color[0];
const bg_color = args.item.bg_color[0];
span.innerHTML = "&alpha;";
span.className = 'labelColorIndicator';
@ -34,7 +35,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
}
if (id.match("FEED:")) {
var menu = new dijit.Menu();
let menu = new dijit.Menu();
menu.row_id = bare_id;
menu.addChild(new dijit.MenuItem({
@ -62,7 +63,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
}
if (id.match("CAT:") && bare_id >= 0) {
var menu = new dijit.Menu();
let menu = new dijit.Menu();
menu.row_id = bare_id;
menu.addChild(new dijit.MenuItem({
@ -90,7 +91,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
}
if (id.match("CAT:") && bare_id == -1) {
var menu = new dijit.Menu();
let menu = new dijit.Menu();
menu.row_id = bare_id;
menu.addChild(new dijit.MenuItem({
@ -128,11 +129,11 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
this.inherited(arguments);
},
updateCounter: function (item) {
var tree = this;
const tree = this;
//console.log("updateCounter: " + item.id[0] + " " + item.unread + " " + tree);
var node = tree._itemNodesMap[item.id];
let node = tree._itemNodesMap[item.id];
if (node) {
node = node[0];
@ -166,7 +167,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
return (item.unread == 0) ? "dijitTreeLabel" : "dijitTreeLabel Unread";
},
getRowClass: function (item, opened) {
var rc = (!item.error || item.error == '') ? "dijitTreeRow" :
let rc = (!item.error || item.error == '') ? "dijitTreeRow" :
"dijitTreeRow Error";
if (item.unread > 0) rc += " Unread";
@ -175,7 +176,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
return rc;
},
getLabel: function(item) {
var name = String(item.name);
let name = String(item.name);
/* Horrible */
name = name.replace(/&quot;/g, "\"");
@ -196,9 +197,9 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
},
expandParentNodes: function(feed, is_cat, list) {
try {
for (var i = 0; i < list.length; i++) {
var id = String(list[i].id);
var item = this._itemNodesMap[id];
for (let i = 0; i < list.length; i++) {
const id = String(list[i].id);
let item = this._itemNodesMap[id];
if (item) {
item = item[0];
@ -213,37 +214,33 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
// expands all parents of specified feed to properly mark it as active
// my fav thing about frameworks is doing everything myself
try {
var test_id = is_cat ? 'CAT:' + feed : 'FEED:' + feed;
const test_id = is_cat ? 'CAT:' + feed : 'FEED:' + feed;
if (!root) {
if (!this.model || !this.model.store) return false;
var items = this.model.store._arrayOfTopLevelItems;
const items = this.model.store._arrayOfTopLevelItems;
for (var i = 0; i < items.length; i++) {
for (let i = 0; i < items.length; i++) {
if (String(items[i].id) == test_id) {
this.expandParentNodes(feed, is_cat, parents);
} else {
this.findNodeParentsAndExpandThem(feed, is_cat, items[i], []);
}
}
} else {
if (root.items) {
} else if (root.items) {
parents.push(root);
for (var i = 0; i < root.items.length; i++) {
for (let i = 0; i < root.items.length; i++) {
if (String(root.items[i].id) == test_id) {
this.expandParentNodes(feed, is_cat, parents);
} else {
this.findNodeParentsAndExpandThem(feed, is_cat, root.items[i], parents.slice(0));
}
}
} else {
if (String(root.id) == test_id) {
} else if (String(root.id) == test_id) {
this.expandParentNodes(feed, is_cat, parents.slice(0));
}
}
}
} catch (e) {
exception_error(e);
}
@ -276,7 +273,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
if (treeNode) {
treeNode = treeNode[0];
var icon = dojo.doc.createElement('img');
const icon = dojo.doc.createElement('img');
icon.src = src;
icon.className = 'tinyFeedIcon';
domConstruct.place(icon, treeNode.iconNode, 'only');
@ -296,7 +293,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
treeNode.loadingNode.src = src;
return true;
} else {
var icon = dojo.doc.createElement('img');
const icon = dojo.doc.createElement('img');
icon.src = src;
icon.className = 'loadingExpando';
domConstruct.place(icon, treeNode.expandoNode, 'only');
@ -311,17 +308,17 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
},
hideReadCat: function (cat, hide, show_special) {
if (this.hasCats()) {
var tree = this;
const tree = this;
if (cat && cat.items) {
var cat_unread = tree.hideReadFeeds(cat.items, hide, show_special);
let cat_unread = tree.hideReadFeeds(cat.items, hide, show_special);
var id = String(cat.id);
var node = tree._itemNodesMap[id];
var bare_id = parseInt(id.substr(id.indexOf(":")+1));
const id = String(cat.id);
const node = tree._itemNodesMap[id];
const bare_id = parseInt(id.substr(id.indexOf(":")+1));
if (node) {
var check_unread = tree.model.getFeedUnread(bare_id, true);
const check_unread = tree.model.getFeedUnread(bare_id, true);
if (hide && cat_unread == 0 && check_unread == 0 && (id != "CAT:-1" || !show_special)) {
Effect.Fade(node[0].rowNode, {duration : 0.3,
@ -337,8 +334,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
hideRead: function (hide, show_special) {
if (this.hasCats()) {
var tree = this;
var cats = this.model.store._arrayOfTopLevelItems;
const tree = this;
const cats = this.model.store._arrayOfTopLevelItems;
cats.each(function(cat) {
tree.hideReadCat(cat, hide, show_special);
@ -350,21 +347,21 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
}
},
hideReadFeeds: function (items, hide, show_special) {
var tree = this;
var cat_unread = 0;
const tree = this;
let cat_unread = 0;
items.each(function(feed) {
var id = String(feed.id);
const id = String(feed.id);
// it's a subcategory
if (feed.items) {
tree.hideReadCat(feed, hide, show_special);
} else { // it's a feed
var bare_id = parseInt(feed.bare_id);;
const bare_id = parseInt(feed.bare_id);
var unread = feed.unread[0];
var has_error = feed.error[0] != '';
var node = tree._itemNodesMap[id];
const unread = feed.unread[0];
const has_error = feed.error[0] != '';
const node = tree._itemNodesMap[id];
if (node) {
if (hide && unread == 0 && !has_error && (bare_id > 0 || bare_id < _label_base_index || !show_special)) {
@ -383,10 +380,10 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
collapseCat: function(id) {
if (!this.model.hasCats()) return;
var tree = this;
const tree = this;
var node = tree._itemNodesMap['CAT:' + id][0];
var item = tree.model.store._itemsByIdentity['CAT:' + id];
const node = tree._itemNodesMap['CAT:' + id][0];
const item = tree.model.store._itemsByIdentity['CAT:' + id];
if (node && item) {
if (!node.isExpanded)
@ -397,16 +394,16 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
}
},
getVisibleUnreadFeeds: function() {
var items = this.model.store._arrayOfAllItems;
var rv = [];
const items = this.model.store._arrayOfAllItems;
const rv = [];
for (var i = 0; i < items.length; i++) {
var id = String(items[i].id);
var box = this._itemNodesMap[id];
for (let i = 0; i < items.length; i++) {
const id = String(items[i].id);
const box = this._itemNodesMap[id];
if (box) {
var row = box[0].rowNode;
var cat = false;
const row = box[0].rowNode;
let cat = false;
try {
cat = box[0].rowNode.parentNode.parentNode;
@ -414,9 +411,9 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
if (row) {
if (Element.visible(row) && (!cat || Element.visible(cat))) {
var feed_id = String(items[i].bare_id);
var is_cat = !id.match('FEED:');
var unread = this.model.getFeedUnread(feed_id, is_cat);
const feed_id = String(items[i].bare_id);
const is_cat = !id.match('FEED:');
const unread = this.model.getFeedUnread(feed_id, is_cat);
if (unread > 0)
rv.push([feed_id, is_cat]);
@ -435,19 +432,19 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
treeItem = this.model.store._itemsByIdentity['FEED:' + feed];
}
items = this.model.store._arrayOfAllItems;
var item = items[0];
const items = this.model.store._arrayOfAllItems;
let item = items[0];
for (var i = 0; i < items.length; i++) {
for (let i = 0; i < items.length; i++) {
if (items[i] == treeItem) {
for (var j = i+1; j < items.length; j++) {
var id = String(items[j].id);
var box = this._itemNodesMap[id];
for (let j = i+1; j < items.length; j++) {
const id = String(items[j].id);
const box = this._itemNodesMap[id];
if (box) {
var row = box[0].rowNode;
var cat = box[0].rowNode.parentNode.parentNode;
const row = box[0].rowNode;
const cat = box[0].rowNode.parentNode.parentNode;
if (Element.visible(cat) && Element.visible(row)) {
item = items[j];
@ -473,19 +470,19 @@ define(["dojo/_base/declare", "dojo/dom-construct", "dijit/Tree", "dijit/Menu"],
treeItem = this.model.store._itemsByIdentity['FEED:' + feed];
}
items = this.model.store._arrayOfAllItems;
var item = items[0] == treeItem ? items[items.length-1] : items[0];
const items = this.model.store._arrayOfAllItems;
let item = items[0] == treeItem ? items[items.length-1] : items[0];
for (var i = 0; i < items.length; i++) {
for (let i = 0; i < items.length; i++) {
if (items[i] == treeItem) {
for (var j = i-1; j > 0; j--) {
var id = String(items[j].id);
var box = this._itemNodesMap[id];
for (let j = i-1; j > 0; j--) {
const id = String(items[j].id);
const box = this._itemNodesMap[id];
if (box) {
var row = box[0].rowNode;
var cat = box[0].rowNode.parentNode.parentNode;
const row = box[0].rowNode;
const cat = box[0].rowNode.parentNode.parentNode;
if (Element.visible(cat) && Element.visible(row)) {
item = items[j];

View File

@ -1,6 +1,6 @@
// based on http://www.velvetcache.org/2010/08/19/a-simple-javascript-hooks-system
var PluginHost = {
const PluginHost = {
HOOK_ARTICLE_RENDERED: 1,
HOOK_ARTICLE_RENDERED_CDM: 2,
HOOK_ARTICLE_SET_ACTIVE: 3,

View File

@ -1,10 +1,11 @@
/* global lib,dijit */
define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], function (declare, domConstruct) {
return declare("fox.PrefFeedTree", lib.CheckBoxTree, {
_createTreeNode: function(args) {
var tnode = this.inherited(arguments);
const tnode = this.inherited(arguments);
var icon = dojo.doc.createElement('img');
const icon = dojo.doc.createElement('img');
if (args.item.icon && args.item.icon[0]) {
icon.src = args.item.icon[0];
} else {
@ -13,7 +14,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
icon.className = 'tinyFeedIcon';
domConstruct.place(icon, tnode.iconNode, 'only');
var param = this.model.store.getValue(args.item, 'param');
let param = this.model.store.getValue(args.item, 'param');
if (param) {
param = dojo.doc.createElement('span');
@ -23,8 +24,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
domConstruct.place(param, tnode.rowNode, 'first');
}
var id = args.item.id[0];
var bare_id = parseInt(id.substr(id.indexOf(':')+1));
const id = args.item.id[0];
const bare_id = parseInt(id.substr(id.indexOf(':')+1));
if (id.match("CAT:") && bare_id > 0) {
var menu = new dijit.Menu();
@ -82,12 +83,12 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
return (!item || this.model.store.getValue(item, 'type') == 'category') ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon";
},
checkItemAcceptance: function(target, source, position) {
var item = dijit.getEnclosingWidget(target).item;
const item = dijit.getEnclosingWidget(target).item;
// disable copying items
source.copyState = function() { return false; };
var source_item = false;
let source_item = false;
source.forInSelectedItems(function(node) {
source_item = node.data.item;
@ -95,8 +96,8 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
if (!source_item || !item) return false;
var id = this.tree.model.store.getValue(item, 'id');
var source_id = source.tree.model.store.getValue(source_item, 'id');
const id = this.tree.model.store.getValue(item, 'id');
const source_id = source.tree.model.store.getValue(source_item, 'id');
//console.log(id + " " + position + " " + source_id);

View File

@ -1,12 +1,13 @@
/* global dijit,lib */
define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], function (declare, domConstruct) {
return declare("fox.PrefFilterTree", lib.CheckBoxTree, {
_createTreeNode: function(args) {
var tnode = this.inherited(arguments);
const tnode = this.inherited(arguments);
var enabled = this.model.store.getValue(args.item, 'enabled');
var param = this.model.store.getValue(args.item, 'param');
var rules = this.model.store.getValue(args.item, 'rules');
const enabled = this.model.store.getValue(args.item, 'enabled');
let param = this.model.store.getValue(args.item, 'param');
const rules = this.model.store.getValue(args.item, 'rules');
if (param) {
param = dojo.doc.createElement('span');
@ -23,7 +24,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
}
if (this.model.store.getValue(args.item, 'id') != 'root') {
var img = dojo.doc.createElement('img');
const img = dojo.doc.createElement('img');
img.src ='images/filter.png';
img.className = 'markedPic';
tnode._filterIconNode = img;
@ -34,10 +35,10 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
},
getLabel: function(item) {
var label = item.name;
let label = item.name;
var feed = this.model.store.getValue(item, 'feed');
var inverse = this.model.store.getValue(item, 'inverse');
const feed = this.model.store.getValue(item, 'feed');
const inverse = this.model.store.getValue(item, 'inverse');
if (feed)
label += " (" + __("in") + " " + feed + ")";
@ -55,7 +56,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "invisible";
},
getLabelClass: function (item, opened) {
var enabled = this.model.store.getValue(item, 'enabled');
const enabled = this.model.store.getValue(item, 'enabled');
return (enabled != false) ? "dijitTreeLabel labelFixedLength" : "dijitTreeLabel labelFixedLength filterDisabled";
},
getRowClass: function (item, opened) {
@ -63,7 +64,7 @@ define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], functio
"dijitTreeRow Error";
},
checkItemAcceptance: function(target, source, position) {
var item = dijit.getEnclosingWidget(target).item;
const item = dijit.getEnclosingWidget(target).item;
// disable copying items
source.copyState = function() { return false; };

View File

@ -1,23 +1,24 @@
/* global lib,dijit */
define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dijit/form/DropDownButton"], function (declare, domConstruct) {
return declare("fox.PrefLabelTree", lib.CheckBoxTree, {
setNameById: function (id, name) {
var item = this.model.store._itemsByIdentity['LABEL:' + id];
const item = this.model.store._itemsByIdentity['LABEL:' + id];
if (item)
this.model.store.setValue(item, 'name', name);
},
_createTreeNode: function(args) {
var tnode = this.inherited(arguments);
const tnode = this.inherited(arguments);
var fg_color = this.model.store.getValue(args.item, 'fg_color');
var bg_color = this.model.store.getValue(args.item, 'bg_color');
var type = this.model.store.getValue(args.item, 'type');
var bare_id = this.model.store.getValue(args.item, 'bare_id');
const fg_color = this.model.store.getValue(args.item, 'fg_color');
const bg_color = this.model.store.getValue(args.item, 'bg_color');
const type = this.model.store.getValue(args.item, 'type');
const bare_id = this.model.store.getValue(args.item, 'bare_id');
if (type == 'label') {
var span = dojo.doc.createElement('span');
const span = dojo.doc.createElement('span');
span.innerHTML = '&alpha;';
span.className = 'labelColorIndicator';
span.id = 'LICID-' + bare_id;