"use strict";
var DropZone = require('dropzone');
+var markdown = require('marked');
var toggleSwitchTemplate = require('./components/toggle-switch.html');
var imagePickerTemplate = require('./components/image-picker.html');
scope: {
uploadUrl: '@',
eventSuccess: '=',
- eventError: '='
+ eventError: '=',
+ uploadedTo: '@'
},
link: function (scope, element, attrs) {
var dropZone = new DropZone(element[0].querySelector('.dropzone-container'), {
dz.on('sending', function (file, xhr, data) {
var token = window.document.querySelector('meta[name=token]').getAttribute('content');
data.append('_token', token);
+ var uploadedTo = typeof scope.uploadedTo === 'undefined' ? 0 : scope.uploadedTo;
+ data.append('uploaded_to', uploadedTo);
});
if (typeof scope.eventSuccess !== 'undefined') dz.on('success', scope.eventSuccess);
dz.on('success', function (file, data) {
};
}]);
+ ngApp.directive('tinymce', ['$timeout', function($timeout) {
+ return {
+ restrict: 'A',
+ scope: {
+ tinymce: '=',
+ mceModel: '=',
+ mceChange: '='
+ },
+ link: function (scope, element, attrs) {
+
+ function tinyMceSetup(editor) {
+ editor.on('ExecCommand change NodeChange ObjectResized', (e) => {
+ var content = editor.getContent();
+ $timeout(() => {
+ scope.mceModel = content;
+ });
+ scope.mceChange(content);
+ });
+
+ editor.on('init', (e) => {
+ scope.mceModel = editor.getContent();
+ });
+
+ scope.$on('html-update', (event, value) => {
+ editor.setContent(value);
+ editor.selection.select(editor.getBody(), true);
+ editor.selection.collapse(false);
+ scope.mceModel = editor.getContent();
+ });
+ }
+
+ scope.tinymce.extraSetups.push(tinyMceSetup);
+ tinymce.init(scope.tinymce);
+ }
+ }
+ }]);
+
+ ngApp.directive('markdownInput', ['$timeout', function($timeout) {
+ return {
+ restrict: 'A',
+ scope: {
+ mdModel: '=',
+ mdChange: '='
+ },
+ link: function (scope, element, attrs) {
+
+ // Set initial model content
+ var content = element.val();
+ scope.mdModel = content;
+ scope.mdChange(markdown(content));
+
+ element.on('change input', (e) => {
+ content = element.val();
+ $timeout(() => {
+ scope.mdModel = content;
+ scope.mdChange(markdown(content));
+ });
+ });
+
+ scope.$on('markdown-update', (event, value) => {
+ element.val(value);
+ scope.mdModel= value;
+ scope.mdChange(markdown(value));
+ });
+
+ }
+ }
+ }]);
+
+ ngApp.directive('markdownEditor', ['$timeout', function($timeout) {
+ return {
+ restrict: 'A',
+ link: function (scope, element, attrs) {
+
+ // Elements
+ var input = element.find('textarea[markdown-input]');
+ var insertImage = element.find('button[data-action="insertImage"]');
+
+ var currentCaretPos = 0;
+
+ input.blur((event) => {
+ currentCaretPos = input[0].selectionStart;
+ });
+
+ // Insert image shortcut
+ input.keydown((event) => {
+ if (event.which === 73 && event.ctrlKey && event.shiftKey) {
+ event.preventDefault();
+ var caretPos = input[0].selectionStart;
+ var currentContent = input.val();
+ var mdImageText = "";
+ input.val(currentContent.substring(0, caretPos) + mdImageText + currentContent.substring(caretPos));
+ input.focus();
+ input[0].selectionStart = caretPos + (";
+ input[0].selectionEnd = caretPos + (';
+ }
+ });
+
+ // Insert image from image manager
+ insertImage.click((event) => {
+ window.ImageManager.showExternal((image) => {
+ var caretPos = currentCaretPos;
+ var currentContent = input.val();
+ var mdImageText = "";
+ input.val(currentContent.substring(0, caretPos) + mdImageText + currentContent.substring(caretPos));
+ input.change();
+ });
+ });
+
+ }
+ }
+ }])
};
\ No newline at end of file