Use Confs for image expansion settings.
This commit is contained in:
parent
76d352f972
commit
21b0c6a73b
@ -115,6 +115,12 @@
|
|||||||
'Mark Cross-thread Quotes': [true, 'Add \'(Cross-thread)\' to cross-threads quotes.']
|
'Mark Cross-thread Quotes': [true, 'Add \'(Cross-thread)\' to cross-threads quotes.']
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
imageExpansion: {
|
||||||
|
'Fit width': [true, null],
|
||||||
|
'Fit height': [false, null],
|
||||||
|
'Expand spoilers': [false, 'Expand all images along with spoilers.'],
|
||||||
|
'Expand from here': [true, 'Expand all images only from current position to thread end.']
|
||||||
|
},
|
||||||
filter: {
|
filter: {
|
||||||
name: ['# Filter any namefags:', '#/^(?!Anonymous$)/'].join('\n'),
|
name: ['# Filter any namefags:', '#/^(?!Anonymous$)/'].join('\n'),
|
||||||
uniqueID: ['# Filter a specific ID:', '#/Txhvk1Tl/'].join('\n'),
|
uniqueID: ['# Filter a specific ID:', '#/Txhvk1Tl/'].join('\n'),
|
||||||
@ -3477,7 +3483,7 @@
|
|||||||
if (!(file && file.isImage && doc.contains(post.nodes.root))) {
|
if (!(file && file.isImage && doc.contains(post.nodes.root))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (ImageExpand.on && (!ImageExpand.spoilers && file.isSpoiler || ImageExpand.fromPosition && file.thumb.getBoundingClientRect().top < 0)) {
|
if (ImageExpand.on && (!Conf['Expand spoilers'] && file.isSpoiler || Conf['Expand from here'] && file.thumb.getBoundingClientRect().top < 0)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
posts.push(post);
|
posts.push(post);
|
||||||
@ -3489,7 +3495,7 @@
|
|||||||
func(post);
|
func(post);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
updateFitness: function() {
|
setFitness: function() {
|
||||||
var checked;
|
var checked;
|
||||||
checked = this.checked;
|
checked = this.checked;
|
||||||
(checked ? $.addClass : $.rmClass)(doc, this.name.toLowerCase().replace(/\s+/g, '-'));
|
(checked ? $.addClass : $.rmClass)(doc, this.name.toLowerCase().replace(/\s+/g, '-'));
|
||||||
@ -3505,12 +3511,6 @@
|
|||||||
} else {
|
} else {
|
||||||
return $.off(window, 'resize', ImageExpand.resize);
|
return $.off(window, 'resize', ImageExpand.resize);
|
||||||
}
|
}
|
||||||
},
|
|
||||||
spoilers: function() {
|
|
||||||
return ImageExpand.spoilers = this.checked;
|
|
||||||
},
|
|
||||||
position: function() {
|
|
||||||
return ImageExpand.fromPosition = this.checked;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
toggle: function(post) {
|
toggle: function(post) {
|
||||||
@ -3605,26 +3605,21 @@
|
|||||||
},
|
},
|
||||||
menu: {
|
menu: {
|
||||||
init: function() {
|
init: function() {
|
||||||
var createSubEntry, el, subEntries;
|
var conf, createSubEntry, el, key, subEntries, _ref;
|
||||||
if (g.VIEW === 'catalog' || !Conf['Image Expansion']) {
|
if (g.VIEW === 'catalog' || !Conf['Image Expansion']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
el = $.el('span', {
|
el = $.el('span', {
|
||||||
textContent: 'Image Expansion'
|
textContent: 'Image Expansion'
|
||||||
});
|
});
|
||||||
ImageExpand.menu.config = $.get('ImageExpansionConfig', {
|
|
||||||
'Fit width': true,
|
|
||||||
'Fit height': false,
|
|
||||||
'Expand spoilers': false,
|
|
||||||
'Expand from here': true
|
|
||||||
});
|
|
||||||
createSubEntry = ImageExpand.menu.createSubEntry;
|
createSubEntry = ImageExpand.menu.createSubEntry;
|
||||||
subEntries = [];
|
subEntries = [];
|
||||||
subEntries.push(createSubEntry('Expand all'));
|
subEntries.push(createSubEntry('Expand all'));
|
||||||
subEntries.push(createSubEntry('Fit width', true));
|
_ref = Config.imageExpansion;
|
||||||
subEntries.push(createSubEntry('Fit height', true));
|
for (key in _ref) {
|
||||||
subEntries.push(createSubEntry('Expand spoilers', true));
|
conf = _ref[key];
|
||||||
subEntries.push(createSubEntry('Expand from here', true));
|
subEntries.push(createSubEntry(key, conf));
|
||||||
|
}
|
||||||
return $.event('AddMenuEntry', {
|
return $.event('AddMenuEntry', {
|
||||||
type: 'header',
|
type: 'header',
|
||||||
el: el,
|
el: el,
|
||||||
@ -3632,7 +3627,7 @@
|
|||||||
subEntries: subEntries
|
subEntries: subEntries
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
createSubEntry: function(type, hasConfig) {
|
createSubEntry: function(type, config) {
|
||||||
var input, label;
|
var input, label;
|
||||||
label = $.el('label', {
|
label = $.el('label', {
|
||||||
innerHTML: "<input type=checkbox name='" + type + "'> " + type
|
innerHTML: "<input type=checkbox name='" + type + "'> " + type
|
||||||
@ -3642,31 +3637,19 @@
|
|||||||
case 'Expand all':
|
case 'Expand all':
|
||||||
$.on(input, 'change', ImageExpand.cb.all);
|
$.on(input, 'change', ImageExpand.cb.all);
|
||||||
break;
|
break;
|
||||||
case 'Expand spoilers':
|
case 'Fit width':
|
||||||
label.title = 'Expand all images along with spoilers.';
|
case 'Fit height':
|
||||||
$.on(input, 'change', ImageExpand.cb.spoilers);
|
$.on(input, 'change', ImageExpand.cb.setFitness);
|
||||||
break;
|
|
||||||
case 'Expand from here':
|
|
||||||
label.title = 'Expand all images only from current position to thread end.';
|
|
||||||
$.on(input, 'change', ImageExpand.cb.position);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
$.on(input, 'change', ImageExpand.cb.updateFitness);
|
|
||||||
}
|
}
|
||||||
if (hasConfig) {
|
if (config) {
|
||||||
input.checked = ImageExpand.menu.config[type];
|
label.title = config[1];
|
||||||
|
input.checked = Conf[type];
|
||||||
$.event('change', null, input);
|
$.event('change', null, input);
|
||||||
$.on(input, 'change', ImageExpand.menu.saveConfig);
|
$.on(input, 'change', $.cb.checked);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
el: label
|
el: label
|
||||||
};
|
};
|
||||||
},
|
|
||||||
saveConfig: function() {
|
|
||||||
var config;
|
|
||||||
config = ImageExpand.menu.config;
|
|
||||||
config[this.name] = this.checked;
|
|
||||||
return $.set('ImageExpansionConfig', config);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
resize: function() {
|
resize: function() {
|
||||||
|
|||||||
@ -57,6 +57,11 @@ Config =
|
|||||||
'Resurrect Quotes': [true, 'Linkify dead quotes to archives.']
|
'Resurrect Quotes': [true, 'Linkify dead quotes to archives.']
|
||||||
'Mark OP Quotes': [true, 'Add \'(OP)\' to OP quotes.']
|
'Mark OP Quotes': [true, 'Add \'(OP)\' to OP quotes.']
|
||||||
'Mark Cross-thread Quotes': [true, 'Add \'(Cross-thread)\' to cross-threads quotes.']
|
'Mark Cross-thread Quotes': [true, 'Add \'(Cross-thread)\' to cross-threads quotes.']
|
||||||
|
imageExpansion:
|
||||||
|
'Fit width': [true, null]
|
||||||
|
'Fit height': [false, null]
|
||||||
|
'Expand spoilers': [false, 'Expand all images along with spoilers.']
|
||||||
|
'Expand from here': [true, 'Expand all images only from current position to thread end.']
|
||||||
filter:
|
filter:
|
||||||
name: [
|
name: [
|
||||||
'# Filter any namefags:'
|
'# Filter any namefags:'
|
||||||
|
|||||||
@ -2100,7 +2100,6 @@ ImageExpand =
|
|||||||
Post::callbacks.push
|
Post::callbacks.push
|
||||||
name: 'Image Expansion'
|
name: 'Image Expansion'
|
||||||
cb: @node
|
cb: @node
|
||||||
|
|
||||||
node: ->
|
node: ->
|
||||||
return unless @file and @file.isImage
|
return unless @file and @file.isImage
|
||||||
$.on @file.thumb.parentNode, 'click', ImageExpand.cb.toggle
|
$.on @file.thumb.parentNode, 'click', ImageExpand.cb.toggle
|
||||||
@ -2120,15 +2119,15 @@ ImageExpand =
|
|||||||
{file} = post
|
{file} = post
|
||||||
continue unless file and file.isImage and doc.contains post.nodes.root
|
continue unless file and file.isImage and doc.contains post.nodes.root
|
||||||
if ImageExpand.on and
|
if ImageExpand.on and
|
||||||
(!ImageExpand.spoilers and file.isSpoiler or
|
(!Conf['Expand spoilers'] and file.isSpoiler or
|
||||||
ImageExpand.fromPosition and file.thumb.getBoundingClientRect().top < 0)
|
Conf['Expand from here'] and file.thumb.getBoundingClientRect().top < 0)
|
||||||
continue
|
continue
|
||||||
posts.push post
|
posts.push post
|
||||||
func = if ImageExpand.on then ImageExpand.expand else ImageExpand.contract
|
func = if ImageExpand.on then ImageExpand.expand else ImageExpand.contract
|
||||||
for post in posts
|
for post in posts
|
||||||
func post
|
func post
|
||||||
return
|
return
|
||||||
updateFitness: ->
|
setFitness: ->
|
||||||
{checked} = @
|
{checked} = @
|
||||||
(if checked then $.addClass else $.rmClass) doc, @name.toLowerCase().replace /\s+/g, '-'
|
(if checked then $.addClass else $.rmClass) doc, @name.toLowerCase().replace /\s+/g, '-'
|
||||||
return unless @name is 'Fit height'
|
return unless @name is 'Fit height'
|
||||||
@ -2139,10 +2138,6 @@ ImageExpand =
|
|||||||
ImageExpand.resize()
|
ImageExpand.resize()
|
||||||
else
|
else
|
||||||
$.off window, 'resize', ImageExpand.resize
|
$.off window, 'resize', ImageExpand.resize
|
||||||
spoilers: ->
|
|
||||||
ImageExpand.spoilers = @checked
|
|
||||||
position: ->
|
|
||||||
ImageExpand.fromPosition = @checked
|
|
||||||
|
|
||||||
toggle: (post) ->
|
toggle: (post) ->
|
||||||
{thumb} = post.file
|
{thumb} = post.file
|
||||||
@ -2213,19 +2208,11 @@ ImageExpand =
|
|||||||
el = $.el 'span',
|
el = $.el 'span',
|
||||||
textContent: 'Image Expansion'
|
textContent: 'Image Expansion'
|
||||||
|
|
||||||
ImageExpand.menu.config = $.get 'ImageExpansionConfig',
|
|
||||||
'Fit width': true
|
|
||||||
'Fit height': false
|
|
||||||
'Expand spoilers': false
|
|
||||||
'Expand from here': true
|
|
||||||
|
|
||||||
{createSubEntry} = ImageExpand.menu
|
{createSubEntry} = ImageExpand.menu
|
||||||
subEntries = []
|
subEntries = []
|
||||||
subEntries.push createSubEntry 'Expand all'
|
subEntries.push createSubEntry 'Expand all'
|
||||||
subEntries.push createSubEntry 'Fit width', true
|
for key, conf of Config.imageExpansion
|
||||||
subEntries.push createSubEntry 'Fit height', true
|
subEntries.push createSubEntry key, conf
|
||||||
subEntries.push createSubEntry 'Expand spoilers', true
|
|
||||||
subEntries.push createSubEntry 'Expand from here', true
|
|
||||||
|
|
||||||
$.event 'AddMenuEntry',
|
$.event 'AddMenuEntry',
|
||||||
type: 'header'
|
type: 'header'
|
||||||
@ -2233,30 +2220,21 @@ ImageExpand =
|
|||||||
order: 20
|
order: 20
|
||||||
subEntries: subEntries
|
subEntries: subEntries
|
||||||
|
|
||||||
createSubEntry: (type, hasConfig) ->
|
createSubEntry: (type, config) ->
|
||||||
label = $.el 'label',
|
label = $.el 'label',
|
||||||
innerHTML: "<input type=checkbox name='#{type}'> #{type}"
|
innerHTML: "<input type=checkbox name='#{type}'> #{type}"
|
||||||
input = label.firstElementChild
|
input = label.firstElementChild
|
||||||
switch type
|
switch type
|
||||||
when 'Expand all'
|
when 'Expand all'
|
||||||
$.on input, 'change', ImageExpand.cb.all
|
$.on input, 'change', ImageExpand.cb.all
|
||||||
when 'Expand spoilers'
|
when 'Fit width', 'Fit height'
|
||||||
label.title = 'Expand all images along with spoilers.'
|
$.on input, 'change', ImageExpand.cb.setFitness
|
||||||
$.on input, 'change', ImageExpand.cb.spoilers
|
if config
|
||||||
when 'Expand from here'
|
label.title = config[1]
|
||||||
label.title = 'Expand all images only from current position to thread end.'
|
input.checked = Conf[type]
|
||||||
$.on input, 'change', ImageExpand.cb.position
|
|
||||||
else
|
|
||||||
$.on input, 'change', ImageExpand.cb.updateFitness
|
|
||||||
if hasConfig
|
|
||||||
input.checked = ImageExpand.menu.config[type]
|
|
||||||
$.event 'change', null, input
|
$.event 'change', null, input
|
||||||
$.on input, 'change', ImageExpand.menu.saveConfig
|
$.on input, 'change', $.cb.checked
|
||||||
el: label
|
el: label
|
||||||
saveConfig: ->
|
|
||||||
{config} = ImageExpand.menu
|
|
||||||
config[@name] = @checked
|
|
||||||
$.set 'ImageExpansionConfig', config
|
|
||||||
|
|
||||||
resize: ->
|
resize: ->
|
||||||
ImageExpand.style.textContent = ":root.fit-height .full-image {max-height:#{doc.clientHeight}px}"
|
ImageExpand.style.textContent = ":root.fit-height .full-image {max-height:#{doc.clientHeight}px}"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user