if mobile, go to /compose route #3090

v1.18.x
psychobunny 10 years ago
parent 117bb407b0
commit 55bed3464e

@ -321,117 +321,127 @@ define('composer', [
isAdminOrMod: app.user.isAdmin || postData.isMod isAdminOrMod: app.user.isAdmin || postData.isMod
}; };
parseAndTranslate('composer', data, function(composerTemplate) { if (data.isMobile) {
if ($('#cmp-uuid-' + post_uuid).length) { ajaxify.go('compose', function() {
return; renderComposer();
} });
composerTemplate = $(composerTemplate); } else {
renderComposer();
}
composerTemplate.attr('id', 'cmp-uuid-' + post_uuid); function renderComposer() {
parseAndTranslate('composer', data, function(composerTemplate) {
if ($('#cmp-uuid-' + post_uuid).length) {
return;
}
composerTemplate = $(composerTemplate);
$(document.body).append(composerTemplate); composerTemplate.attr('id', 'cmp-uuid-' + post_uuid);
var postContainer = $(composerTemplate[0]), $(document.body).append(composerTemplate);
bodyEl = postContainer.find('textarea'),
draft = drafts.getDraft(postData.save_id),
submitBtn = postContainer.find('.composer-submit');
preview.handleToggler(postContainer); var postContainer = $(composerTemplate[0]),
tags.init(postContainer, composer.posts[post_uuid]); bodyEl = postContainer.find('textarea'),
categoryList.init(postContainer, composer.posts[post_uuid]); draft = drafts.getDraft(postData.save_id),
submitBtn = postContainer.find('.composer-submit');
activate(post_uuid); preview.handleToggler(postContainer);
resize.reposition(postContainer); tags.init(postContainer, composer.posts[post_uuid]);
categoryList.init(postContainer, composer.posts[post_uuid]);
if (config.allowFileUploads || config.hasImageUploadPlugin) { activate(post_uuid);
uploads.initialize(post_uuid); resize.reposition(postContainer);
}
formatting.addHandler(postContainer); if (config.allowFileUploads || config.hasImageUploadPlugin) {
uploads.initialize(post_uuid);
}
if (allowTopicsThumbnail) { formatting.addHandler(postContainer);
uploads.toggleThumbEls(postContainer, composer.posts[post_uuid].topic_thumb || '');
}
postContainer.on('change', 'input, textarea', function() { if (allowTopicsThumbnail) {
composer.posts[post_uuid].modified = true; uploads.toggleThumbEls(postContainer, composer.posts[post_uuid].topic_thumb || '');
}); }
submitBtn.on('click', function() { postContainer.on('change', 'input, textarea', function() {
var action = $(this).attr('data-action'); composer.posts[post_uuid].modified = true;
});
switch(action) { submitBtn.on('click', function() {
case 'post-lock': var action = $(this).attr('data-action');
$(this).attr('disabled', true);
post(post_uuid, {lock: true});
break;
case 'post': // intentional fall-through switch(action) {
default: case 'post-lock':
$(this).attr('disabled', true); $(this).attr('disabled', true);
post(post_uuid); post(post_uuid, {lock: true});
break; break;
}
});
postContainer.on('click', 'a[data-switch-action]', function() { case 'post': // intentional fall-through
var action = $(this).attr('data-switch-action'), default:
label = $(this).html(); $(this).attr('disabled', true);
post(post_uuid);
break;
}
});
submitBtn.attr('data-action', action).html(label); postContainer.on('click', 'a[data-switch-action]', function() {
}); var action = $(this).attr('data-switch-action'),
label = $(this).html();
postContainer.find('.composer-discard').on('click', function() { submitBtn.attr('data-action', action).html(label);
if (!composer.posts[post_uuid].modified) { });
removeComposerHistory();
discard(post_uuid); postContainer.find('.composer-discard').on('click', function() {
return; if (!composer.posts[post_uuid].modified) {
} removeComposerHistory();
var btn = $(this).prop('disabled', true); discard(post_uuid);
translator.translate('[[modules:composer.discard]]', function(translated) { return;
bootbox.confirm(translated, function(confirm) { }
if (confirm) { var btn = $(this).prop('disabled', true);
removeComposerHistory(); translator.translate('[[modules:composer.discard]]', function(translated) {
discard(post_uuid); bootbox.confirm(translated, function(confirm) {
} if (confirm) {
btn.prop('disabled', false); removeComposerHistory();
discard(post_uuid);
}
btn.prop('disabled', false);
});
}); });
}); });
});
postContainer.on('click', function() { postContainer.on('click', function() {
if (!taskbar.isActive(post_uuid)) { if (!taskbar.isActive(post_uuid)) {
taskbar.updateActive(post_uuid); taskbar.updateActive(post_uuid);
} }
}); });
bodyEl.on('input propertychange', function() { bodyEl.on('input propertychange', function() {
preview.render(postContainer); preview.render(postContainer);
}); });
bodyEl.on('scroll', function() { bodyEl.on('scroll', function() {
preview.matchScroll(postContainer); preview.matchScroll(postContainer);
}); });
bodyEl.val(draft ? draft : postData.body); bodyEl.val(draft ? draft : postData.body);
preview.render(postContainer, function() { preview.render(postContainer, function() {
preview.matchScroll(postContainer); preview.matchScroll(postContainer);
}); });
drafts.init(postContainer, postData); drafts.init(postContainer, postData);
resize.handleResize(postContainer); resize.handleResize(postContainer);
handleHelp(postContainer); handleHelp(postContainer);
$(window).trigger('action:composer.loaded', { $(window).trigger('action:composer.loaded', {
post_uuid: post_uuid post_uuid: post_uuid
}); });
formatting.addComposerButtons(); formatting.addComposerButtons();
focusElements(postContainer); focusElements(postContainer);
}); });
}
} }
function parseAndTranslate(template, data, callback) { function parseAndTranslate(template, data, callback) {

Loading…
Cancel
Save