Split cycle fit mode button to 1 for each fit mode

This commit is contained in:
rr- 2015-07-19 12:26:11 +02:00
parent 5ad854e38a
commit 362087ee63
4 changed files with 42 additions and 13 deletions

View file

@ -118,6 +118,13 @@
line-height: 150%; line-height: 150%;
} }
#sidebar .fit-mode a {
opacity: .25;
}
#sidebar .fit-mode a.active {
opacity: 1;
}
#sidebar .essential { #sidebar .essential {
display: -webkit-flex; display: -webkit-flex;
-webkit-justify-content: space-around; -webkit-justify-content: space-around;

View file

@ -36,19 +36,24 @@ App.Presenters.PostContentPresenter = function(
var ratio = originalWidth / originalHeight; var ratio = originalWidth / originalHeight;
var height = jQuery(window).height() - $wrapper.offset().top; var height = jQuery(window).height() - $wrapper.offset().top;
var width = (height - 10) * ratio; var width = (height - 10) * ratio;
$wrapper.css({maxWidth: width + 'px'}); $wrapper.css({maxWidth: width + 'px', width: ''});
}, },
'fit-width': function($wrapper) { 'fit-width': function($wrapper) {
var originalWidth = $wrapper.attr('data-width'); var originalWidth = $wrapper.attr('data-width');
$wrapper.css({maxWidth: originalWidth + 'px', width: 'auto'}); $wrapper.css({maxWidth: originalWidth + 'px', width: ''});
}, },
'original': function($wrapper) { 'original': function($wrapper) {
var originalWidth = $wrapper.attr('data-width'); var originalWidth = $wrapper.attr('data-width');
$wrapper.css({maxWidth: null, width: originalWidth + 'px'}); $wrapper.css({maxWidth: '', width: originalWidth + 'px'});
} }
}; };
var fitterNames = Object.keys(fitters); var fitterNames = Object.keys(fitters);
function getFitMode() {
var $wrapper = $target.find('.object-wrapper');
return $wrapper.data('current-fit');
}
function changeFitMode(mode) { function changeFitMode(mode) {
var $wrapper = $target.find('.object-wrapper'); var $wrapper = $target.find('.object-wrapper');
@ -58,8 +63,8 @@ App.Presenters.PostContentPresenter = function(
function cycleFitMode() { function cycleFitMode() {
var $wrapper = $target.find('.object-wrapper'); var $wrapper = $target.find('.object-wrapper');
var mode = $wrapper.data('current-fit'); var oldMode = getFitMode();
var newMode = fitterNames[(fitterNames.indexOf(mode) + 1) % fitterNames.length]; var newMode = fitterNames[(fitterNames.indexOf(oldMode) + 1) % fitterNames.length];
$wrapper.data('current-fit', newMode); $wrapper.data('current-fit', newMode);
fitters[$wrapper.data('current-fit')]($wrapper); fitters[$wrapper.data('current-fit')]($wrapper);
updatePostNotesSize(); updatePostNotesSize();
@ -105,6 +110,11 @@ App.Presenters.PostContentPresenter = function(
render: render, render: render,
addNewPostNote: addNewPostNote, addNewPostNote: addNewPostNote,
updatePostNotesSize: updatePostNotesSize, updatePostNotesSize: updatePostNotesSize,
fitWidth: function() { changeFitMode('fit-width'); },
fitHeight: function() { changeFitMode('fit-height'); },
fitOriginal: function() { changeFitMode('original'); },
getFitMode: getFitMode,
changeFitMode: changeFitMode,
cycleFitMode: cycleFitMode, cycleFitMode: cycleFitMode,
}; };
}; };

View file

@ -72,7 +72,9 @@ App.Presenters.PostPresenter = function(
[postContentPresenter, {post: post, $target: $el.find('#post-content-target')}], [postContentPresenter, {post: post, $target: $el.find('#post-content-target')}],
[postEditPresenter, {post: post, $target: $el.find('#post-edit-target'), updateCallback: postEdited}], [postEditPresenter, {post: post, $target: $el.find('#post-edit-target'), updateCallback: postEdited}],
[commentListPresenter, {post: post, $target: $el.find('#post-comments-target')}]], [commentListPresenter, {post: post, $target: $el.find('#post-comments-target')}]],
function() { }); function() {
syncFitModeButtons();
});
}).fail(function() { }).fail(function() {
console.log(arguments); console.log(arguments);
@ -178,7 +180,7 @@ App.Presenters.PostPresenter = function(
function attachSidebarEvents() { function attachSidebarEvents() {
$el.find('#sidebar .delete').click(deleteButtonClicked); $el.find('#sidebar .delete').click(deleteButtonClicked);
$el.find('#sidebar .feature').click(featureButtonClicked); $el.find('#sidebar .feature').click(featureButtonClicked);
$el.find('#sidebar .fit-mode').click(fitModeButtonClicked); $el.find('#sidebar .fit-mode a').click(fitModeButtonsClicked);
$el.find('#sidebar .edit').click(editButtonClicked); $el.find('#sidebar .edit').click(editButtonClicked);
$el.find('#sidebar .history').click(historyButtonClicked); $el.find('#sidebar .history').click(historyButtonClicked);
$el.find('#sidebar .add-favorite').click(addFavoriteButtonClicked); $el.find('#sidebar .add-favorite').click(addFavoriteButtonClicked);
@ -208,6 +210,14 @@ App.Presenters.PostPresenter = function(
}).fail(showGenericError); }).fail(showGenericError);
} }
function syncFitModeButtons() {
var fitMode = postContentPresenter.getFitMode();
$el.find('#sidebar .fit-mode a').each(function(i, item) {
var $item = jQuery(item);
$item.toggleClass('active', $item.attr('data-fit-mode') === fitMode);
});
}
function featureButtonClicked(e) { function featureButtonClicked(e) {
e.preventDefault(); e.preventDefault();
messagePresenter.hideMessages($messages); messagePresenter.hideMessages($messages);
@ -216,9 +226,10 @@ App.Presenters.PostPresenter = function(
} }
} }
function fitModeButtonClicked(e) { function fitModeButtonsClicked(e) {
e.preventDefault(); e.preventDefault();
postContentPresenter.cycleFitMode(); postContentPresenter.changeFitMode(jQuery(e.target).attr('data-fit-mode'));
syncFitModeButtons();
} }
function featurePost() { function featurePost() {

View file

@ -268,10 +268,11 @@ if (forceHttpInPermalinks > 0) {
</li> </li>
<% } %> <% } %>
<li> <li class="fit-mode">
<a class="fit-mode" href="#"> Fit:
Cycle fit mode <a data-fit-mode="fit-width" href="#">width</a>,
</a> <a data-fit-mode="fit-height" href="#">height</a>,
<a data-fit-mode="original" href="#">original</a>
</li> </li>
</ul> </ul>
<% } %> <% } %>