This repository has been archived by the owner on Jan 10, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from fofr/attachments-2
Allow insertion of attachments
- Loading branch information
Showing
8 changed files
with
158 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
;(function (global) { | ||
'use strict' | ||
|
||
var GOVUK = global.GOVUK || {} | ||
GOVUK.Modules = GOVUK.Modules || {} | ||
|
||
GOVUK.Modules.AttachmentInsert = function () { | ||
this.start = function (element) { | ||
element.on('click', '.js-attachment', insertAttachment); | ||
element.on('click', '.js-upload-attachment', showForm); | ||
element.on('click', '.js-upload-close', hideForm); | ||
|
||
// https://stackoverflow.com/questions/11076975 | ||
function insertAttachment(evt) { | ||
evt.preventDefault(); | ||
var markdown = $(this).data('markdown'); | ||
var cursorPos = $('#body').prop('selectionStart'); | ||
|
||
if (cursorPos === 0 && $('#body').val().length > 0) { | ||
cursorPos = $('#body').val().length; | ||
} | ||
|
||
var v = $('#body').val(); | ||
var textBefore = v.substring(0, cursorPos); | ||
var textAfter = v.substring(cursorPos, v.length); | ||
$('#body').val(textBefore + '\n' + markdown + textAfter).focus(); | ||
} | ||
|
||
function showForm(evt) { | ||
evt.preventDefault(); | ||
element.find('.js-upload-form').show(); | ||
element.find('.js-select-form').hide(); | ||
} | ||
|
||
function hideForm(evt) { | ||
evt.preventDefault(); | ||
element.find('.js-upload-form').hide(); | ||
element.find('.js-select-form').show(); | ||
} | ||
} | ||
} | ||
|
||
global.GOVUK = GOVUK | ||
})(window) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{% extends "layout.html" %} | ||
{% block page_title %}Attachment added{% endblock %} | ||
|
||
{% block content %} | ||
|
||
<a href="/document-tasks" class="govuk-c-back-link">Back</a> | ||
<main role="main" class="govuk-o-main-wrapper"> | ||
<div class="govuk-o-grid"> | ||
<div class="govuk-o-grid__item govuk-o-grid__item--two-thirds"> | ||
<h1 class="form-title govuk-heading-xl"> | ||
You’ve added an attachment | ||
</h1> | ||
|
||
<p class="govuk-body">Now you can insert it in the copy:</p> | ||
<a href="/title-summary-body#body-label" class="govuk-c-button">Insert in the copy</a> | ||
<p class="govuk-body"> | ||
<a href="/document-tasks">Go back to draft</a> | ||
</p> | ||
</div> | ||
</div> | ||
</main> | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% if attachment_count > 0 %} | ||
<div style="clear: both"> | ||
<ul class="govuk-!-mt-r6 govuk-list"> | ||
{% for i in range(0, attachment_count) %} | ||
<li> | ||
<h4 class="govuk-heading-s govuk-!-mb-r0"> | ||
<a class="govuk-link js-attachment js-dialog-close" data-markdown="[InlineAttachment:{{ data[ (i + 1) + '-attachment-filename'] }}]" href="/attachment/{{ i + 1 }}"> | ||
{{ data[ (i + 1) + '-attachment-title'] }} (<span class="">{{ data[ (i + 1) + '-attachment-filename'] }}</span>) | ||
</a> | ||
</h4> | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
{% endif %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters