Skip to content

Commit

Permalink
[#665] JS for the buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
afuna committed Oct 7, 2014
1 parent 2822c83 commit d94059e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 4 deletions.
46 changes: 46 additions & 0 deletions htdocs/js/pages/entry/new.js
Expand Up @@ -4,6 +4,51 @@ var postForm = (function($) {
$form.fancySelect();
};

var initButtons = function($form, $crosspost, strings) {
function openPreview(e) {
var form = e.target.form;
var action = form.action;
var target = form.target;

var $password = $(form).find( "input[type='password']:enabled" );
$password.prop( "disabled", true );

form.action = "/entry/preview";
form.target = 'preview';
window.open( '',
'preview',
'width=760,height=600,resizable=yes,status=yes,toolbar=no,location=no,menubar=no,scrollbars=yes'
);
form.submit();

form.action = action;
form.target = target;
$password.prop( "disabled", false );
e.preventDefault();
}

function handleSpellcheck(e) {
$(this.form).data( "skipchecks", "spellcheck" );
}

function handleDelete(e) {
$(this.form).data( "skipchecks", "delete" );

var do_delete = confirm( strings.delete_confirm );
if ( do_delete ) {
do_delete = $crosspost.crosspost( "confirmDelete", strings.delete_xposts_confirm );
}

if ( ! do_delete ) {
e.preventDefault();
}
}

$("#js-preview-button").click(openPreview);
$("#js-spellcheck-button").click(handleSpellcheck);
$("#js-delete-button").click(handleDelete);
};

var initCommunitySection = function($form) {
$form.bind("journalselect-full", function(e, journal) {
if ( journal.name && journal.isremote ) {
Expand Down Expand Up @@ -499,6 +544,7 @@ var postForm = (function($) {
var entryForm = $("#js-post-entry");

initMainForm(entryForm);
initButtons(entryForm, $( ".crosspost-component" ), formData.strings);
initCommunitySection(entryForm);

initCurrents(entryForm, formData.moodpics);
Expand Down
7 changes: 3 additions & 4 deletions views/entry/form.tt
Expand Up @@ -261,15 +261,15 @@ postFormInitData.did_spellcheck = [% spellcheck.did_spellcheck ? "true" : "false
<ul class="button-group right">
<li>[%- form.submit( value = dw.ml('talk.btn.preview')
name = "action:preview"
id = "preview_button"
id = "js-preview-button"
class = "small secondary button"
)
-%]</li>

[%- IF can_spellcheck %]
<li>[% form.submit( value = dw.ml('entryform.spellcheck')
name = "action:spellcheck"
id = "spellcheck_button"
id = "js-spellcheck-button"
class = "small secondary button"
);
%]</li>
Expand Down Expand Up @@ -331,15 +331,14 @@ postFormInitData.did_spellcheck = [% spellcheck.did_spellcheck ? "true" : "false
<div class="button-bar">
[%- form.submit( value = dw.ml(action.edit ? '.button.edit' : '.button.post')
name = "action:post"
id = "submit_entry_large"
class = "button left"
)
-%]

[% IF action.edit %]
[%- form.submit( value = dw.ml( '.button.delete' )
name = "action:delete"
id = "delete_entry"
id = "js-delete-button"
class = "button secondary right"
)
-%]
Expand Down

0 comments on commit d94059e

Please sign in to comment.