2009-04-29 04:52:18 +02:00
|
|
|
/**
|
2010-04-12 23:54:41 +02:00
|
|
|
* Functions for HtmlEditorFields in the back end.
|
|
|
|
* Includes the JS for the ImageUpload forms.
|
|
|
|
*
|
|
|
|
* Relies on the jquery.form.js plugin to power the
|
|
|
|
* ajax / iframe submissions
|
2009-04-29 04:52:18 +02:00
|
|
|
*/
|
|
|
|
|
2012-12-08 12:20:20 +01:00
|
|
|
var ss = ss || {};
|
2012-02-09 17:17:39 +01:00
|
|
|
/**
|
|
|
|
* Wrapper for HTML WYSIWYG libraries, which abstracts library internals
|
|
|
|
* from interface concerns like inserting and editing links.
|
|
|
|
* Caution: Incomplete and unstable API.
|
|
|
|
*/
|
2012-12-08 12:20:20 +01:00
|
|
|
ss.editorWrappers = {};
|
|
|
|
ss.editorWrappers.tinyMCE = (function() {
|
2013-06-14 11:25:06 +02:00
|
|
|
|
|
|
|
var instance;
|
|
|
|
|
2012-02-09 17:17:39 +01:00
|
|
|
return {
|
2012-04-18 17:38:24 +02:00
|
|
|
init: function(config) {
|
|
|
|
if(!ss.editorWrappers.tinyMCE.initialized) {
|
|
|
|
tinyMCE.init(config);
|
2013-08-20 05:49:04 +02:00
|
|
|
|
2012-04-18 17:38:24 +02:00
|
|
|
ss.editorWrappers.tinyMCE.initialized = true;
|
|
|
|
}
|
|
|
|
},
|
2010-04-13 01:05:23 +02:00
|
|
|
/**
|
2012-02-09 17:17:39 +01:00
|
|
|
* @return Mixed Implementation specific object
|
2010-04-13 01:05:23 +02:00
|
|
|
*/
|
2012-02-09 17:17:39 +01:00
|
|
|
getInstance: function() {
|
2013-06-14 11:25:06 +02:00
|
|
|
return this.instance;
|
2012-02-09 17:17:39 +01:00
|
|
|
},
|
2010-04-13 01:05:23 +02:00
|
|
|
/**
|
2012-02-09 17:17:39 +01:00
|
|
|
* Invoked when a content-modifying UI is opened.
|
2010-04-13 01:05:23 +02:00
|
|
|
*/
|
2012-02-09 17:17:39 +01:00
|
|
|
onopen: function() {
|
|
|
|
},
|
2010-04-13 01:05:23 +02:00
|
|
|
/**
|
2012-02-09 17:17:39 +01:00
|
|
|
* Invoked when a content-modifying UI is closed.
|
2010-04-13 01:05:23 +02:00
|
|
|
*/
|
2012-02-09 17:17:39 +01:00
|
|
|
onclose: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Write the HTML back to the original text area field.
|
|
|
|
*/
|
|
|
|
save: function() {
|
|
|
|
tinyMCE.triggerSave();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Create a new instance based on a textarea field.
|
|
|
|
*
|
2012-11-07 03:55:20 +01:00
|
|
|
* Please proxy the events from your editor implementation into JS events
|
|
|
|
* on the textarea field. For events that do not map directly, use the
|
|
|
|
* following naming scheme: editor<event>.
|
|
|
|
*
|
2012-02-09 17:17:39 +01:00
|
|
|
* @param String
|
|
|
|
* @param Object Implementation specific configuration
|
|
|
|
* @param Function
|
|
|
|
*/
|
2012-11-07 03:55:20 +01:00
|
|
|
create: function(domID, config) {
|
2013-06-14 11:25:06 +02:00
|
|
|
this.instance = new tinymce.Editor(domID, config);
|
2012-11-07 03:55:20 +01:00
|
|
|
|
|
|
|
// Patch TinyMCE events into underlying textarea field.
|
2013-06-14 11:25:06 +02:00
|
|
|
this.instance.onInit.add(function(ed) {
|
2013-08-20 05:49:04 +02:00
|
|
|
if(!ss.editorWrappers.tinyMCE.patched) {
|
|
|
|
// Not ideal, but there's a memory leak we need to patch
|
|
|
|
var originalDestroy = tinymce.themes.AdvancedTheme.prototype.destroy;
|
|
|
|
|
|
|
|
tinymce.themes.AdvancedTheme.prototype.destroy = function() {
|
|
|
|
originalDestroy.apply(this, arguments);
|
|
|
|
|
|
|
|
if (this.statusKeyboardNavigation) {
|
|
|
|
this.statusKeyboardNavigation.destroy();
|
|
|
|
this.statusKeyboardNavigation = null;
|
|
|
|
}
|
2014-07-30 00:59:13 +02:00
|
|
|
};
|
2013-08-20 05:49:04 +02:00
|
|
|
|
|
|
|
ss.editorWrappers.tinyMCE.patched = true;
|
|
|
|
}
|
|
|
|
|
2012-11-07 03:55:20 +01:00
|
|
|
jQuery(ed.getElement()).trigger('editorinit');
|
2013-06-03 13:32:43 +02:00
|
|
|
|
2013-08-20 05:49:04 +02:00
|
|
|
// Periodically check for inline changes when focused,
|
2013-06-03 13:32:43 +02:00
|
|
|
// since TinyMCE's onChange only fires on certain actions
|
|
|
|
// like inserting a new paragraph, as opposed to any user input.
|
|
|
|
// This also works around an issue where the "save" button
|
|
|
|
// wouldn't trigger if the click is the cause of a "blur" event
|
|
|
|
// after an (undetected) inline change. This "blur" causes onChange
|
|
|
|
// to trigger, which will change the button markup to show "alternative" styles,
|
|
|
|
// effectively cancelling the original click event.
|
2014-07-28 03:29:44 +02:00
|
|
|
if(ed.settings.update_interval) {
|
|
|
|
var interval;
|
|
|
|
jQuery(ed.getBody()).on('focus', function() {
|
|
|
|
interval = setInterval(function() {
|
|
|
|
// Update underlying element as necessary
|
|
|
|
var element = jQuery(ed.getElement());
|
|
|
|
if(ed.isDirty()) {
|
|
|
|
// Set content without triggering editor content cleanup
|
|
|
|
element.val(ed.getContent({format : 'raw', no_events : 1}));
|
|
|
|
}
|
|
|
|
}, ed.settings.update_interval);
|
|
|
|
});
|
|
|
|
jQuery(ed.getBody()).on('blur', function() {
|
|
|
|
clearInterval(interval);
|
|
|
|
});
|
|
|
|
}
|
2012-11-07 03:55:20 +01:00
|
|
|
});
|
2013-06-14 11:25:06 +02:00
|
|
|
this.instance.onChange.add(function(ed, l) {
|
2012-11-07 03:55:20 +01:00
|
|
|
// Update underlying textarea on every change, so external handlers
|
|
|
|
// such as changetracker have a chance to trigger properly.
|
|
|
|
ed.save();
|
|
|
|
jQuery(ed.getElement()).trigger('change');
|
|
|
|
});
|
|
|
|
// Add more events here as needed.
|
|
|
|
|
2013-06-14 11:25:06 +02:00
|
|
|
this.instance.render();
|
2012-02-09 17:17:39 +01:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Redraw the editor contents
|
|
|
|
*/
|
|
|
|
repaint: function() {
|
|
|
|
tinyMCE.execCommand("mceRepaint");
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* @return boolean
|
|
|
|
*/
|
|
|
|
isDirty: function() {
|
|
|
|
return this.getInstance().isDirty();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* HTML representation of the edited content.
|
|
|
|
*
|
|
|
|
* Returns: {String}
|
|
|
|
*/
|
|
|
|
getContent: function() {
|
|
|
|
return this.getInstance().getContent();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* DOM tree of the edited content
|
|
|
|
*
|
|
|
|
* Returns: DOMElement
|
|
|
|
*/
|
|
|
|
getDOM: function() {
|
|
|
|
return this.getInstance().dom;
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Returns: DOMElement
|
|
|
|
*/
|
|
|
|
getContainer: function() {
|
|
|
|
return this.getInstance().getContainer();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Get the closest node matching the current selection.
|
|
|
|
*
|
|
|
|
* Returns: {jQuery} DOMElement
|
|
|
|
*/
|
|
|
|
getSelectedNode: function() {
|
|
|
|
return this.getInstance().selection.getNode();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Select the given node within the editor DOM
|
|
|
|
*
|
|
|
|
* Parameters: {DOMElement}
|
|
|
|
*/
|
|
|
|
selectNode: function(node) {
|
2012-02-22 11:15:54 +01:00
|
|
|
this.getInstance().selection.select(node);
|
2012-02-09 17:17:39 +01:00
|
|
|
},
|
2012-12-10 15:36:14 +01:00
|
|
|
/**
|
|
|
|
* Replace entire content
|
|
|
|
*
|
|
|
|
* @param String HTML
|
|
|
|
* @param Object opts
|
|
|
|
*/
|
|
|
|
setContent: function(html, opts) {
|
|
|
|
this.getInstance().execCommand('mceSetContent', false, html, opts);
|
|
|
|
},
|
2012-02-09 17:17:39 +01:00
|
|
|
/**
|
2012-02-22 17:53:37 +01:00
|
|
|
* Insert content at the current caret position
|
|
|
|
*
|
2012-02-09 17:17:39 +01:00
|
|
|
* @param String HTML
|
|
|
|
*/
|
2012-02-22 17:53:37 +01:00
|
|
|
insertContent: function(html, opts) {
|
|
|
|
this.getInstance().execCommand('mceInsertContent', false, html, opts);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Replace currently selected content
|
|
|
|
*
|
|
|
|
* @param {String} html
|
|
|
|
*/
|
|
|
|
replaceContent: function(html, opts) {
|
|
|
|
this.getInstance().execCommand('mceReplaceContent', false, html, opts);
|
2012-02-09 17:17:39 +01:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Insert or update a link in the content area (based on current editor selection)
|
|
|
|
*
|
|
|
|
* Parameters: {Object} attrs
|
|
|
|
*/
|
2012-02-22 17:53:37 +01:00
|
|
|
insertLink: function(attrs, opts) {
|
|
|
|
this.getInstance().execCommand("mceInsertLink", false, attrs, opts);
|
2012-02-09 17:17:39 +01:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Remove the link from the currently selected node (if any).
|
|
|
|
*/
|
|
|
|
removeLink: function() {
|
|
|
|
this.getInstance().execCommand('unlink', false);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Strip any editor-specific notation from link in order to make it presentable in the UI.
|
|
|
|
*
|
|
|
|
* Parameters:
|
|
|
|
* {Object}
|
|
|
|
* {DOMElement}
|
|
|
|
*/
|
|
|
|
cleanLink: function(href, node) {
|
|
|
|
var cb = tinyMCE.settings['urlconverter_callback'];
|
|
|
|
if(cb) href = eval(cb + "(href, node, true);");
|
|
|
|
|
|
|
|
// Turn into relative
|
|
|
|
if(href.match(new RegExp('^' + tinyMCE.settings['document_base_url'] + '(.*)$'))) {
|
|
|
|
href = RegExp.$1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get rid of TinyMCE's temporary URLs
|
|
|
|
if(href.match(/^javascript:\s*mctmp/)) href = '';
|
|
|
|
|
|
|
|
return href;
|
2012-02-22 17:53:37 +01:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Creates a bookmark for the currently selected range,
|
|
|
|
* which can be used to reselect this range at a later point.
|
|
|
|
* @return {mixed}
|
|
|
|
*/
|
|
|
|
createBookmark: function() {
|
|
|
|
return this.getInstance().selection.getBookmark();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Selects a bookmarked range previously saved through createBookmark().
|
|
|
|
* @param {mixed} bookmark
|
|
|
|
*/
|
|
|
|
moveToBookmark: function(bookmark) {
|
|
|
|
this.getInstance().selection.moveToBookmark(bookmark);
|
2012-06-20 05:27:56 +02:00
|
|
|
this.getInstance().focus();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Removes any selection & de-focuses this editor
|
|
|
|
*/
|
|
|
|
blur: function() {
|
|
|
|
this.getInstance().selection.collapse();
|
2012-02-22 17:53:37 +01:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Add new undo point with the current DOM content.
|
|
|
|
*/
|
|
|
|
addUndo: function() {
|
|
|
|
this.getInstance().undoManager.add();
|
2010-04-13 01:05:23 +02:00
|
|
|
}
|
2012-02-22 11:15:54 +01:00
|
|
|
};
|
2012-02-09 17:17:39 +01:00
|
|
|
});
|
|
|
|
// Override this to switch editor wrappers
|
|
|
|
ss.editorWrappers['default'] = ss.editorWrappers.tinyMCE;
|
2012-01-04 17:48:54 +01:00
|
|
|
|
2012-01-05 00:37:51 +01:00
|
|
|
|
2012-02-09 17:17:39 +01:00
|
|
|
(function($) {
|
|
|
|
|
|
|
|
$.entwine('ss', function($) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class: textarea.htmleditor
|
|
|
|
*
|
|
|
|
* Add tinymce to HtmlEditorFields within the CMS. Works in combination
|
|
|
|
* with a TinyMCE.init() call which is prepopulated with the used HTMLEditorConfig settings,
|
|
|
|
* and included in the page as an inline <script> tag.
|
|
|
|
*/
|
|
|
|
$('textarea.htmleditor').entwine({
|
|
|
|
|
|
|
|
Editor: null,
|
2012-06-12 12:48:08 +02:00
|
|
|
|
2012-01-05 00:37:51 +01:00
|
|
|
/**
|
2012-02-09 17:17:39 +01:00
|
|
|
* Constructor: onmatch
|
2012-01-05 00:37:51 +01:00
|
|
|
*/
|
2012-06-12 12:48:08 +02:00
|
|
|
onadd: function() {
|
2013-06-14 11:25:06 +02:00
|
|
|
var edClass = this.data('editor') || 'default', ed = ss.editorWrappers[edClass]();
|
2012-02-09 17:17:39 +01:00
|
|
|
this.setEditor(ed);
|
|
|
|
|
2012-04-10 21:08:31 +02:00
|
|
|
// Using a global config (generated through HTMLEditorConfig PHP logic).
|
|
|
|
// Depending on browser cache load behaviour, entwine's DOMMaybeChanged
|
|
|
|
// can be called before the bottom-most inline script tag is executed,
|
|
|
|
// which defines the global. If that's the case, wait for the window load.
|
2012-06-12 12:48:08 +02:00
|
|
|
if(typeof ssTinyMceConfig != 'undefined') this.redraw();
|
2012-02-09 17:17:39 +01:00
|
|
|
|
|
|
|
this._super();
|
2012-01-05 00:37:51 +01:00
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
onremove: function() {
|
|
|
|
var ed = tinyMCE.get(this.attr('id'));
|
2012-06-14 04:33:50 +02:00
|
|
|
if (ed) {
|
2015-04-23 00:08:33 +02:00
|
|
|
try {
|
|
|
|
ed.remove();
|
|
|
|
} catch(ex) {}
|
|
|
|
try {
|
|
|
|
ed.destroy();
|
|
|
|
} catch(ex) {}
|
|
|
|
|
|
|
|
// Remove any residual tinyMCE editor element
|
|
|
|
this.next('.mceEditor').remove();
|
2012-06-14 04:33:50 +02:00
|
|
|
|
|
|
|
// TinyMCE leaves behind events. We should really fix TinyMCE, but lets brute force it for now
|
|
|
|
$.each(jQuery.cache, function(){
|
|
|
|
var source = this.handle && this.handle.elem;
|
|
|
|
if (!source) return;
|
|
|
|
|
|
|
|
var parent = source;
|
2013-07-03 07:55:40 +02:00
|
|
|
try {
|
|
|
|
while (parent && parent.nodeType == 1) parent = parent.parentNode;
|
|
|
|
}
|
|
|
|
catch(err) {}
|
2012-06-14 04:33:50 +02:00
|
|
|
|
|
|
|
if (!parent) $(source).unbind().remove();
|
2012-06-14 23:18:25 +02:00
|
|
|
});
|
2012-06-14 04:33:50 +02:00
|
|
|
}
|
|
|
|
|
2012-05-14 01:43:36 +02:00
|
|
|
this._super();
|
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
|
|
|
|
getContainingForm: function(){
|
|
|
|
return this.closest('form');
|
|
|
|
},
|
|
|
|
|
|
|
|
fromWindow: {
|
|
|
|
onload: function(){
|
|
|
|
this.redraw();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-09 17:17:39 +01:00
|
|
|
redraw: function() {
|
2015-06-09 02:01:21 +02:00
|
|
|
// Using textarea config ID from global config object (generated through HTMLEditorConfig PHP logic)
|
|
|
|
var config = ssTinyMceConfig[this.data('config')], self = this, ed = this.getEditor();
|
2012-02-09 17:17:39 +01:00
|
|
|
|
2012-04-18 17:38:24 +02:00
|
|
|
ed.init(config);
|
2012-04-10 21:08:31 +02:00
|
|
|
|
2012-02-09 17:17:39 +01:00
|
|
|
// Create editor instance and render it.
|
|
|
|
// Similar logic to adapter/jquery/jquery.tinymce.js, but doesn't rely on monkey-patching
|
|
|
|
// jQuery methods, and avoids replicate the script lazyloading which is already in place with jQuery.ondemand.
|
2012-11-07 03:55:20 +01:00
|
|
|
ed.create(this.attr('id'), config);
|
2012-11-04 23:24:46 +01:00
|
|
|
|
2012-02-09 17:17:39 +01:00
|
|
|
this._super();
|
2012-01-05 00:37:51 +01:00
|
|
|
},
|
2012-06-12 12:48:08 +02:00
|
|
|
|
2013-01-29 04:57:07 +01:00
|
|
|
/**
|
|
|
|
* Make sure the editor has flushed all it's buffers before the form is submitted.
|
|
|
|
*/
|
|
|
|
'from .cms-edit-form': {
|
|
|
|
onbeforesubmitform: function(e) {
|
|
|
|
this.getEditor().save();
|
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-11-07 03:55:20 +01:00
|
|
|
oneditorinit: function() {
|
|
|
|
// Delayed show because TinyMCE calls hide() via setTimeout on removing an element,
|
|
|
|
// which is called in quick succession with adding a new editor after ajax loading new markup
|
|
|
|
|
|
|
|
//storing the container object before setting timeout
|
|
|
|
var redrawObj = $(this.getEditor().getInstance().getContainer());
|
|
|
|
setTimeout(function() {
|
|
|
|
redrawObj.show();
|
|
|
|
}, 10);
|
|
|
|
},
|
|
|
|
|
2012-06-12 12:48:08 +02:00
|
|
|
'from .cms-container': {
|
|
|
|
onbeforestatechange: function(){
|
|
|
|
this.css('visibility', 'hidden');
|
|
|
|
|
2012-07-16 23:33:22 +02:00
|
|
|
var ed = this.getEditor(), container = (ed && ed.getInstance()) ? ed.getContainer() : null;
|
2012-06-12 12:48:08 +02:00
|
|
|
if(container && container.length) container.remove();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-09 17:17:39 +01:00
|
|
|
isChanged: function() {
|
|
|
|
var ed = this.getEditor();
|
2012-02-22 17:53:37 +01:00
|
|
|
return (ed && ed.getInstance() && ed.isDirty());
|
2012-01-05 00:37:51 +01:00
|
|
|
},
|
2012-02-09 17:17:39 +01:00
|
|
|
resetChanged: function() {
|
|
|
|
var ed = this.getEditor();
|
|
|
|
if(typeof tinyMCE == 'undefined') return;
|
|
|
|
|
|
|
|
// TODO Abstraction layer
|
|
|
|
var inst = tinyMCE.getInstanceById(this.attr('id'));
|
|
|
|
if (inst) inst.startContent = tinymce.trim(inst.getContent({format : 'raw', no_events : 1}));
|
2012-01-05 00:37:51 +01:00
|
|
|
},
|
2012-04-12 22:28:00 +02:00
|
|
|
openLinkDialog: function() {
|
|
|
|
this.openDialog('link');
|
|
|
|
},
|
|
|
|
openMediaDialog: function() {
|
2012-05-14 01:43:36 +02:00
|
|
|
this.openDialog('media');
|
2012-04-12 22:28:00 +02:00
|
|
|
},
|
|
|
|
openDialog: function(type) {
|
|
|
|
var capitalize = function(text) {
|
2012-05-14 01:43:36 +02:00
|
|
|
return text.charAt(0).toUpperCase() + text.slice(1).toLowerCase();
|
2012-04-12 22:28:00 +02:00
|
|
|
};
|
|
|
|
|
2013-06-14 11:25:06 +02:00
|
|
|
var self = this, url = $('#cms-editor-dialogs').data('url' + capitalize(type) + 'form'),
|
2012-04-12 22:28:00 +02:00
|
|
|
dialog = $('.htmleditorfield-' + type + 'dialog');
|
2012-01-05 00:37:51 +01:00
|
|
|
|
2012-04-12 22:28:00 +02:00
|
|
|
if(dialog.length) {
|
2013-06-14 11:25:06 +02:00
|
|
|
dialog.getForm().setElement(this);
|
2012-04-12 22:28:00 +02:00
|
|
|
dialog.open();
|
|
|
|
} else {
|
|
|
|
// Show a placeholder for instant feedback. Will be replaced with actual
|
|
|
|
// form dialog once its loaded.
|
|
|
|
dialog = $('<div class="htmleditorfield-dialog htmleditorfield-' + type + 'dialog loading">');
|
2015-09-21 00:00:05 +02:00
|
|
|
|
2012-04-12 22:28:00 +02:00
|
|
|
$('body').append(dialog);
|
|
|
|
$.ajax({
|
|
|
|
url: url,
|
2013-06-13 19:57:18 +02:00
|
|
|
complete: function() {
|
|
|
|
dialog.removeClass('loading');
|
|
|
|
},
|
2012-04-12 22:28:00 +02:00
|
|
|
success: function(html) {
|
|
|
|
dialog.html(html);
|
2013-06-14 11:25:06 +02:00
|
|
|
dialog.getForm().setElement(self);
|
2013-06-24 18:58:46 +02:00
|
|
|
dialog.trigger('ssdialogopen');
|
2012-04-12 22:28:00 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2012-01-05 00:37:51 +01:00
|
|
|
}
|
2012-02-09 17:17:39 +01:00
|
|
|
});
|
2012-01-04 17:48:54 +01:00
|
|
|
|
2012-04-12 22:28:00 +02:00
|
|
|
$('.htmleditorfield-dialog').entwine({
|
2012-06-20 05:27:56 +02:00
|
|
|
onadd: function() {
|
2015-10-01 03:16:07 +02:00
|
|
|
|
2012-04-12 22:28:00 +02:00
|
|
|
// Create jQuery dialog
|
2013-06-13 19:57:18 +02:00
|
|
|
if (!this.is('.ui-dialog-content')) {
|
2015-10-01 03:16:07 +02:00
|
|
|
this.ssdialog({
|
|
|
|
autoOpen: true,
|
|
|
|
buttons: {
|
|
|
|
'insert': {
|
|
|
|
text: ss.i18n._t(
|
|
|
|
'HtmlEditorField.INSERT',
|
|
|
|
'Insert'
|
|
|
|
),
|
|
|
|
'data-icon': 'accept',
|
|
|
|
class: 'ss-ui-action-constructive media-insert',
|
|
|
|
click: function() {
|
|
|
|
$(this).find('form').submit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2013-06-13 19:57:18 +02:00
|
|
|
}
|
2012-04-12 22:28:00 +02:00
|
|
|
|
|
|
|
this._super();
|
|
|
|
},
|
2012-06-20 05:27:56 +02:00
|
|
|
|
2012-04-12 22:28:00 +02:00
|
|
|
getForm: function() {
|
|
|
|
return this.find('form');
|
|
|
|
},
|
|
|
|
open: function() {
|
2013-06-13 19:57:18 +02:00
|
|
|
this.ssdialog('open');
|
2012-04-12 22:28:00 +02:00
|
|
|
},
|
|
|
|
close: function() {
|
2013-06-13 19:57:18 +02:00
|
|
|
this.ssdialog('close');
|
2012-04-12 22:28:00 +02:00
|
|
|
},
|
|
|
|
toggle: function(bool) {
|
|
|
|
if(this.is(':visible')) this.close();
|
|
|
|
else this.open();
|
2015-09-21 00:00:05 +02:00
|
|
|
},
|
|
|
|
onscroll: function () {
|
|
|
|
this.animate({
|
|
|
|
scrollTop: this.find('form').height()
|
|
|
|
}, 500);
|
2012-04-12 22:28:00 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-02-09 17:17:39 +01:00
|
|
|
/**
|
|
|
|
* Base form implementation for interactions with an editor instance,
|
|
|
|
* mostly geared towards modification and insertion of content.
|
|
|
|
*/
|
2012-01-04 17:48:54 +01:00
|
|
|
$('form.htmleditorfield-form').entwine({
|
2012-06-20 05:27:56 +02:00
|
|
|
Selection: null,
|
2013-06-14 11:25:06 +02:00
|
|
|
|
|
|
|
// Implementation-dependent serialization of the current editor selection state
|
2012-06-20 05:27:56 +02:00
|
|
|
Bookmark: null,
|
2013-06-14 11:25:06 +02:00
|
|
|
|
|
|
|
// DOMElement pointing to the currently active textarea
|
|
|
|
Element: null,
|
2012-06-20 05:27:56 +02:00
|
|
|
|
|
|
|
setSelection: function(node) {
|
|
|
|
return this._super($(node));
|
|
|
|
},
|
2012-01-04 23:31:40 +01:00
|
|
|
|
2012-06-20 05:27:56 +02:00
|
|
|
onadd: function() {
|
2012-01-04 17:48:54 +01:00
|
|
|
// Move title from headline to (jQuery compatible) title attribute
|
|
|
|
var titleEl = this.find(':header:first');
|
2012-04-12 22:28:00 +02:00
|
|
|
this.getDialog().attr('title', titleEl.text());
|
2012-01-04 17:48:54 +01:00
|
|
|
|
2012-05-11 06:07:07 +02:00
|
|
|
this._super();
|
2012-01-04 17:48:54 +01:00
|
|
|
},
|
2012-06-20 05:27:56 +02:00
|
|
|
onremove: function() {
|
|
|
|
this.setSelection(null);
|
|
|
|
this.setBookmark(null);
|
2013-06-14 11:25:06 +02:00
|
|
|
this.setElement(null);
|
2012-06-20 05:27:56 +02:00
|
|
|
|
2012-05-14 01:43:36 +02:00
|
|
|
this._super();
|
|
|
|
},
|
2012-06-20 05:27:56 +02:00
|
|
|
|
2012-04-12 22:28:00 +02:00
|
|
|
getDialog: function() {
|
|
|
|
// TODO Refactor to listen to form events to remove two-way coupling
|
|
|
|
return this.closest('.htmleditorfield-dialog');
|
2012-02-09 17:17:39 +01:00
|
|
|
},
|
2012-06-20 05:27:56 +02:00
|
|
|
|
|
|
|
fromDialog: {
|
2013-06-24 18:58:46 +02:00
|
|
|
onssdialogopen: function(){
|
2012-06-20 05:27:56 +02:00
|
|
|
var ed = this.getEditor();
|
|
|
|
ed.onopen();
|
|
|
|
|
|
|
|
this.setSelection(ed.getSelectedNode());
|
|
|
|
this.setBookmark(ed.createBookmark());
|
|
|
|
|
|
|
|
ed.blur();
|
|
|
|
|
|
|
|
this.find(':input:not(:submit)[data-skip-autofocus!="true"]').filter(':visible:enabled').eq(0).focus();
|
|
|
|
|
|
|
|
this.redraw();
|
2015-06-03 01:20:29 +02:00
|
|
|
this.updateFromEditor();
|
2012-06-20 05:27:56 +02:00
|
|
|
},
|
|
|
|
|
2013-06-24 18:58:46 +02:00
|
|
|
onssdialogclose: function(){
|
2012-06-20 05:27:56 +02:00
|
|
|
var ed = this.getEditor();
|
|
|
|
ed.onclose();
|
|
|
|
|
|
|
|
ed.moveToBookmark(this.getBookmark());
|
|
|
|
|
|
|
|
this.setSelection(null);
|
|
|
|
this.setBookmark(null);
|
|
|
|
|
|
|
|
this.resetFields();
|
|
|
|
}
|
2012-05-19 05:51:09 +02:00
|
|
|
},
|
2012-06-20 05:27:56 +02:00
|
|
|
|
2012-05-19 05:51:09 +02:00
|
|
|
/**
|
2013-06-14 11:25:06 +02:00
|
|
|
* @return Object ss.editorWrapper instance
|
2012-05-19 05:51:09 +02:00
|
|
|
*/
|
|
|
|
getEditor: function(){
|
2013-06-14 11:25:06 +02:00
|
|
|
return this.getElement().getEditor();
|
2012-06-20 05:27:56 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
modifySelection: function(callback) {
|
|
|
|
var ed = this.getEditor();
|
|
|
|
|
|
|
|
ed.moveToBookmark(this.getBookmark());
|
|
|
|
callback.call(this, ed);
|
|
|
|
|
|
|
|
this.setSelection(ed.getSelectedNode());
|
|
|
|
this.setBookmark(ed.createBookmark());
|
|
|
|
|
|
|
|
ed.blur();
|
|
|
|
},
|
|
|
|
|
|
|
|
updateFromEditor: function() {
|
|
|
|
/* NOP */
|
|
|
|
},
|
|
|
|
redraw: function() {
|
|
|
|
/* NOP */
|
|
|
|
},
|
|
|
|
resetFields: function() {
|
2012-09-10 01:12:05 +02:00
|
|
|
// Flush the tree drop down fields, as their content might get changed in other parts of the CMS, ie in Files and images
|
|
|
|
this.find('.tree-holder').empty();
|
2012-01-04 17:48:54 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-02-09 17:17:39 +01:00
|
|
|
/**
|
|
|
|
* Inserts and edits links in an html editor, including internal/external web links,
|
|
|
|
* links to files on the webserver, email addresses, and anchors in the existing html content.
|
|
|
|
* Every variation has its own fields (e.g. a "target" attribute doesn't make sense for an email link),
|
|
|
|
* which are toggled through a type dropdown. Variations share fields, so there's only one "title" field in the form.
|
|
|
|
*/
|
2012-01-04 17:48:54 +01:00
|
|
|
$('form.htmleditorfield-linkform').entwine({
|
2014-07-30 00:59:13 +02:00
|
|
|
|
2012-01-04 17:48:54 +01:00
|
|
|
// TODO Entwine doesn't respect submits triggered by ENTER key
|
|
|
|
onsubmit: function(e) {
|
|
|
|
this.insertLink();
|
2012-04-12 22:28:00 +02:00
|
|
|
this.getDialog().close();
|
2012-01-04 17:48:54 +01:00
|
|
|
return false;
|
|
|
|
},
|
|
|
|
resetFields: function() {
|
2012-04-12 22:28:00 +02:00
|
|
|
this._super();
|
2012-07-10 06:32:39 +02:00
|
|
|
|
|
|
|
// Reset the form using a native call. This will also correctly reset checkboxes and radio buttons.
|
|
|
|
this[0].reset();
|
2012-01-04 17:48:54 +01:00
|
|
|
},
|
2012-07-10 06:32:39 +02:00
|
|
|
redraw: function() {
|
2012-01-04 17:48:54 +01:00
|
|
|
this._super();
|
|
|
|
|
2014-07-30 00:59:13 +02:00
|
|
|
var linkType = this.find(':input[name=LinkType]:checked').val();
|
2012-01-04 17:48:54 +01:00
|
|
|
|
|
|
|
this.addAnchorSelector();
|
|
|
|
|
2015-06-03 01:20:29 +02:00
|
|
|
this.resetFileField();
|
|
|
|
|
2012-07-10 06:32:39 +02:00
|
|
|
// Toggle field visibility depending on the link type.
|
2012-04-17 05:43:53 +02:00
|
|
|
this.find('div.content .field').hide();
|
2013-10-20 22:54:02 +02:00
|
|
|
this.find('.field[id$="LinkType"]').show();
|
2013-05-26 01:11:05 +02:00
|
|
|
this.find('.field[id$="' + linkType +'_Holder"]').show();
|
|
|
|
|
|
|
|
if(linkType == 'internal' || linkType == 'anchor') {
|
|
|
|
this.find('.field[id$="Anchor_Holder"]').show();
|
|
|
|
}
|
|
|
|
|
2014-12-15 22:56:10 +01:00
|
|
|
if(linkType == 'email') {
|
|
|
|
this.find('.field[id$="Subject_Holder"]').show();
|
|
|
|
} else {
|
2013-05-26 01:11:05 +02:00
|
|
|
this.find('.field[id$="TargetBlank_Holder"]').show();
|
|
|
|
}
|
|
|
|
|
2012-04-05 06:50:49 +02:00
|
|
|
if(linkType == 'anchor') {
|
2013-05-26 01:11:05 +02:00
|
|
|
this.find('.field[id$="AnchorSelector_Holder"]').show();
|
2012-04-05 06:50:49 +02:00
|
|
|
}
|
2013-10-20 22:46:06 +02:00
|
|
|
this.find('.field[id$="Description_Holder"]').show();
|
2012-01-04 17:48:54 +01:00
|
|
|
},
|
2013-01-10 23:32:13 +01:00
|
|
|
/**
|
|
|
|
* @return Object Keys: 'href', 'target', 'title'
|
|
|
|
*/
|
|
|
|
getLinkAttributes: function() {
|
2013-05-26 01:11:05 +02:00
|
|
|
var href,
|
|
|
|
target = null,
|
2014-12-15 22:56:10 +01:00
|
|
|
subject = this.find(':input[name=Subject]').val(),
|
2013-05-26 01:11:05 +02:00
|
|
|
anchor = this.find(':input[name=Anchor]').val();
|
2012-01-04 17:48:54 +01:00
|
|
|
|
|
|
|
// Determine target
|
2013-05-26 01:11:05 +02:00
|
|
|
if(this.find(':input[name=TargetBlank]').is(':checked')) {
|
|
|
|
target = '_blank';
|
|
|
|
}
|
|
|
|
|
2012-01-04 17:48:54 +01:00
|
|
|
// All other attributes
|
|
|
|
switch(this.find(':input[name=LinkType]:checked').val()) {
|
|
|
|
case 'internal':
|
2012-03-09 02:25:42 +01:00
|
|
|
href = '[sitetree_link,id=' + this.find(':input[name=internal]').val() + ']';
|
2013-05-26 01:11:05 +02:00
|
|
|
|
|
|
|
if(anchor) {
|
|
|
|
href += '#' + anchor;
|
|
|
|
}
|
|
|
|
|
2012-01-04 17:48:54 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 'anchor':
|
|
|
|
href = '#' + anchor;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'file':
|
2015-06-03 01:20:29 +02:00
|
|
|
href = '[file_link,id=' + this.find('.ss-uploadfield .ss-uploadfield-item').attr('data-fileid') + ']';
|
2012-01-04 17:48:54 +01:00
|
|
|
target = '_blank';
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'email':
|
|
|
|
href = 'mailto:' + this.find(':input[name=email]').val();
|
2014-12-15 22:56:10 +01:00
|
|
|
if(subject) {
|
|
|
|
href += '?subject=' + encodeURIComponent(subject);
|
|
|
|
}
|
2012-01-04 17:48:54 +01:00
|
|
|
target = null;
|
|
|
|
break;
|
|
|
|
|
2012-02-22 11:15:54 +01:00
|
|
|
// case 'external':
|
2012-01-04 17:48:54 +01:00
|
|
|
default:
|
|
|
|
href = this.find(':input[name=external]').val();
|
|
|
|
// Prefix the URL with "http://" if no prefix is found
|
|
|
|
if(href.indexOf('://') == -1) href = 'http://' + href;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2013-01-10 23:32:13 +01:00
|
|
|
return {
|
2014-07-30 00:59:13 +02:00
|
|
|
href : href,
|
|
|
|
target : target,
|
2012-01-04 23:31:40 +01:00
|
|
|
title : this.find(':input[name=Description]').val()
|
2012-01-04 17:48:54 +01:00
|
|
|
};
|
2013-01-10 23:32:13 +01:00
|
|
|
},
|
|
|
|
insertLink: function() {
|
2012-06-20 05:27:56 +02:00
|
|
|
this.modifySelection(function(ed){
|
2013-01-10 23:32:13 +01:00
|
|
|
ed.insertLink(this.getLinkAttributes());
|
|
|
|
});
|
2012-01-04 17:48:54 +01:00
|
|
|
},
|
|
|
|
removeLink: function() {
|
2012-06-20 05:27:56 +02:00
|
|
|
this.modifySelection(function(ed){
|
|
|
|
ed.removeLink();
|
2013-01-10 23:32:13 +01:00
|
|
|
});
|
2013-05-26 01:11:05 +02:00
|
|
|
|
2015-06-03 01:20:29 +02:00
|
|
|
this.resetFileField();
|
2012-01-04 17:48:54 +01:00
|
|
|
this.close();
|
|
|
|
},
|
2014-07-30 00:59:13 +02:00
|
|
|
|
2015-06-03 01:20:29 +02:00
|
|
|
resetFileField: function() {
|
|
|
|
// If there's an attached item, remove it
|
|
|
|
var fileField = this.find('#file'),
|
|
|
|
fileUpload = fileField.data('fileupload'),
|
|
|
|
currentItem = fileField.find('.ss-uploadfield-item[data-fileid]');
|
|
|
|
|
|
|
|
if(currentItem.length) {
|
|
|
|
fileUpload._trigger('destroy', null, {content: currentItem});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2014-07-30 00:59:13 +02:00
|
|
|
/**
|
|
|
|
* Builds an anchor selector element and injects it into the DOM next to the anchor field.
|
|
|
|
*/
|
2012-01-04 17:48:54 +01:00
|
|
|
addAnchorSelector: function() {
|
|
|
|
// Avoid adding twice
|
|
|
|
if(this.find(':input[name=AnchorSelector]').length) return;
|
|
|
|
|
2014-07-30 00:59:13 +02:00
|
|
|
var self = this;
|
|
|
|
var anchorSelector = $(
|
|
|
|
'<select id="Form_EditorToolbarLinkForm_AnchorSelector" name="AnchorSelector"></select>'
|
|
|
|
);
|
|
|
|
this.find(':input[name=Anchor]').parent().append(anchorSelector);
|
2012-01-04 17:48:54 +01:00
|
|
|
|
2014-07-30 00:59:13 +02:00
|
|
|
// Initialise the anchor dropdown.
|
|
|
|
this.updateAnchorSelector();
|
2012-01-04 17:48:54 +01:00
|
|
|
|
|
|
|
// copy the value from dropdown to the text field
|
|
|
|
anchorSelector.change(function(e) {
|
|
|
|
self.find(':input[name="Anchor"]').val($(this).val());
|
|
|
|
});
|
|
|
|
},
|
2014-07-30 00:59:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetch relevant anchors, depending on the link type.
|
|
|
|
*
|
|
|
|
* @return $.Deferred A promise of an anchor array, or an error message.
|
|
|
|
*/
|
|
|
|
getAnchors: function() {
|
|
|
|
var linkType = this.find(':input[name=LinkType]:checked').val();
|
|
|
|
var dfdAnchors = $.Deferred();
|
|
|
|
|
|
|
|
switch (linkType) {
|
|
|
|
case 'anchor':
|
|
|
|
// Fetch from the local editor.
|
|
|
|
var collectedAnchors = [];
|
|
|
|
var ed = this.getEditor();
|
|
|
|
// name attribute is defined as CDATA, should accept all characters and entities
|
|
|
|
// http://www.w3.org/TR/1999/REC-html401-19991224/struct/links.html#h-12.2
|
|
|
|
|
|
|
|
if(ed) {
|
|
|
|
var raw = ed.getContent().match(/name="([^"]+?)"|name='([^']+?)'/gim);
|
|
|
|
if (raw && raw.length) {
|
|
|
|
for(var i = 0; i < raw.length; i++) {
|
|
|
|
collectedAnchors.push(raw[i].substr(6).replace(/"$/, ''));
|
|
|
|
}
|
|
|
|
}
|
2012-04-17 05:43:53 +02:00
|
|
|
}
|
2014-07-30 00:59:13 +02:00
|
|
|
|
|
|
|
dfdAnchors.resolve(collectedAnchors);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'internal':
|
|
|
|
// Fetch available anchors from the target internal page.
|
|
|
|
var pageId = this.find(':input[name=internal]').val();
|
|
|
|
|
|
|
|
if (pageId) {
|
|
|
|
$.ajax({
|
|
|
|
url: $.path.addSearchParams(
|
|
|
|
this.attr('action').replace('LinkForm', 'getanchors'),
|
|
|
|
{'PageID': parseInt(pageId)}
|
|
|
|
),
|
|
|
|
success: function(body, status, xhr) {
|
|
|
|
dfdAnchors.resolve($.parseJSON(body));
|
|
|
|
},
|
|
|
|
error: function(xhr, status) {
|
|
|
|
dfdAnchors.reject(xhr.responseText);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
dfdAnchors.resolve([]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
// This type does not support anchors at all.
|
|
|
|
dfdAnchors.reject(ss.i18n._t(
|
|
|
|
'HtmlEditorField.ANCHORSNOTSUPPORTED',
|
|
|
|
'Anchors are not supported for this link type.'
|
|
|
|
));
|
|
|
|
break;
|
2012-01-04 17:48:54 +01:00
|
|
|
}
|
|
|
|
|
2014-08-01 06:25:28 +02:00
|
|
|
return dfdAnchors.promise();
|
2014-07-30 00:59:13 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the anchor list in the dropdown.
|
|
|
|
*/
|
|
|
|
updateAnchorSelector: function() {
|
|
|
|
var self = this;
|
|
|
|
var selector = this.find(':input[name=AnchorSelector]');
|
|
|
|
var dfdAnchors = this.getAnchors();
|
|
|
|
|
|
|
|
// Inform the user we are loading.
|
2012-01-04 17:48:54 +01:00
|
|
|
selector.empty();
|
2012-08-26 23:07:20 +02:00
|
|
|
selector.append($(
|
|
|
|
'<option value="" selected="1">' +
|
2014-07-30 00:59:13 +02:00
|
|
|
ss.i18n._t('HtmlEditorField.LOOKINGFORANCHORS', 'Looking for anchors...') +
|
2012-08-26 23:07:20 +02:00
|
|
|
'</option>'
|
|
|
|
));
|
2014-07-30 00:59:13 +02:00
|
|
|
|
|
|
|
dfdAnchors.done(function(anchors) {
|
|
|
|
selector.empty();
|
|
|
|
selector.append($(
|
|
|
|
'<option value="" selected="1">' +
|
|
|
|
ss.i18n._t('HtmlEditorField.SelectAnchor') +
|
|
|
|
'</option>'
|
|
|
|
));
|
|
|
|
|
|
|
|
if (anchors) {
|
|
|
|
for (var j = 0; j < anchors.length; j++) {
|
|
|
|
selector.append($('<option value="'+anchors[j]+'">'+anchors[j]+'</option>'));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}).fail(function(message) {
|
|
|
|
selector.empty();
|
|
|
|
selector.append($(
|
|
|
|
'<option value="" selected="1">' +
|
|
|
|
message +
|
|
|
|
'</option>'
|
|
|
|
));
|
|
|
|
});
|
|
|
|
|
|
|
|
// Poke the selector for IE8, otherwise the changes won't be noticed.
|
|
|
|
if ($.browser.msie) selector.hide().show();
|
2012-01-04 17:48:54 +01:00
|
|
|
},
|
2014-07-30 00:59:13 +02:00
|
|
|
|
2012-07-10 06:32:39 +02:00
|
|
|
/**
|
|
|
|
* Updates the state of the dialog inputs to match the editor selection.
|
|
|
|
* If selection does not contain a link, resets the fields.
|
|
|
|
*/
|
2012-02-09 17:17:39 +01:00
|
|
|
updateFromEditor: function() {
|
2012-01-05 00:37:51 +01:00
|
|
|
var htmlTagPattern = /<\S[^><]*>/g, fieldName, data = this.getCurrentLink();
|
2012-07-10 06:32:39 +02:00
|
|
|
|
2012-01-04 17:48:54 +01:00
|
|
|
if(data) {
|
|
|
|
for(fieldName in data) {
|
|
|
|
var el = this.find(':input[name=' + fieldName + ']'), selected = data[fieldName];
|
|
|
|
// Remove html tags in the selected text that occurs on IE browsers
|
|
|
|
if(typeof(selected) == 'string') selected = selected.replace(htmlTagPattern, '');
|
2012-07-10 06:32:39 +02:00
|
|
|
|
|
|
|
// Set values and invoke the triggers (e.g. for TreeDropdownField).
|
|
|
|
if(el.is(':checkbox')) {
|
|
|
|
el.prop('checked', selected).change();
|
|
|
|
} else if(el.is(':radio')) {
|
|
|
|
el.val([selected]).change();
|
2015-06-03 01:20:29 +02:00
|
|
|
} else if(fieldName == 'file') {
|
|
|
|
// Can't rely on fieldName, ad UploadFields have different naming convention
|
|
|
|
el = $('#' + fieldName);
|
|
|
|
|
|
|
|
// We have to wait for the UploadField to initialise
|
|
|
|
(function attach(el, selected) {
|
|
|
|
if( ! el.getConfig()) {
|
|
|
|
setTimeout(function(){ attach(el, selected); }, 50);
|
|
|
|
} else {
|
|
|
|
el.attachFiles([selected]);
|
|
|
|
}
|
|
|
|
})(el, selected);
|
2012-01-04 17:48:54 +01:00
|
|
|
} else {
|
|
|
|
el.val(selected).change();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2014-07-30 00:59:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return information about the currently selected link, suitable for population of the link form.
|
|
|
|
*
|
|
|
|
* Returns null if no link was currently selected.
|
|
|
|
*/
|
|
|
|
getCurrentLink: function() {
|
|
|
|
var selectedEl = this.getSelection(),
|
|
|
|
href = "", target = "", title = "", action = "insert", style_class = "";
|
|
|
|
|
|
|
|
// We use a separate field for linkDataSource from tinyMCE.linkElement.
|
|
|
|
// If we have selected beyond the range of an <a> element, then use use that <a> element to get the link data source,
|
|
|
|
// but we don't use it as the destination for the link insertion
|
|
|
|
var linkDataSource = null;
|
|
|
|
if(selectedEl.length) {
|
|
|
|
if(selectedEl.is('a')) {
|
|
|
|
// Element is a link
|
|
|
|
linkDataSource = selectedEl;
|
|
|
|
// TODO Limit to inline elements, otherwise will also apply to e.g. paragraphs which already contain one or more links
|
|
|
|
// } else if((selectedEl.find('a').length)) {
|
|
|
|
// // Element contains a link
|
|
|
|
// var firstLinkEl = selectedEl.find('a:first');
|
|
|
|
// if(firstLinkEl.length) linkDataSource = firstLinkEl;
|
|
|
|
} else {
|
|
|
|
// Element is a child of a link
|
|
|
|
linkDataSource = selectedEl = selectedEl.parents('a:first');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(linkDataSource && linkDataSource.length) this.modifySelection(function(ed){
|
|
|
|
ed.selectNode(linkDataSource[0]);
|
|
|
|
});
|
|
|
|
|
|
|
|
// Is anchor not a link
|
|
|
|
if (!linkDataSource.attr('href')) linkDataSource = null;
|
|
|
|
|
|
|
|
if (linkDataSource) {
|
|
|
|
href = linkDataSource.attr('href');
|
|
|
|
target = linkDataSource.attr('target');
|
|
|
|
title = linkDataSource.attr('title');
|
|
|
|
style_class = linkDataSource.attr('class');
|
|
|
|
href = this.getEditor().cleanLink(href, linkDataSource);
|
|
|
|
action = "update";
|
|
|
|
}
|
|
|
|
|
|
|
|
if(href.match(/^mailto:(.*)$/)) {
|
|
|
|
return {
|
|
|
|
LinkType: 'email',
|
|
|
|
email: RegExp.$1,
|
|
|
|
Description: title
|
|
|
|
};
|
|
|
|
} else if(href.match(/^(assets\/.*)$/) || href.match(/^\[file_link\s*(?:\s*|%20|,)?id=([0-9]+)\]?(#.*)?$/)) {
|
|
|
|
return {
|
|
|
|
LinkType: 'file',
|
|
|
|
file: RegExp.$1,
|
|
|
|
Description: title,
|
|
|
|
TargetBlank: target ? true : false
|
|
|
|
};
|
|
|
|
} else if(href.match(/^#(.*)$/)) {
|
|
|
|
return {
|
|
|
|
LinkType: 'anchor',
|
|
|
|
Anchor: RegExp.$1,
|
|
|
|
Description: title,
|
|
|
|
TargetBlank: target ? true : false
|
|
|
|
};
|
|
|
|
} else if(href.match(/^\[sitetree_link(?:\s*|%20|,)?id=([0-9]+)\]?(#.*)?$/i)) {
|
|
|
|
return {
|
|
|
|
LinkType: 'internal',
|
|
|
|
internal: RegExp.$1,
|
|
|
|
Anchor: RegExp.$2 ? RegExp.$2.substr(1) : '',
|
|
|
|
Description: title,
|
|
|
|
TargetBlank: target ? true : false
|
|
|
|
};
|
|
|
|
} else if(href) {
|
|
|
|
return {
|
|
|
|
LinkType: 'external',
|
|
|
|
external: href,
|
|
|
|
Description: title,
|
|
|
|
TargetBlank: target ? true : false
|
|
|
|
};
|
2012-01-04 17:48:54 +01:00
|
|
|
} else {
|
2014-07-30 00:59:13 +02:00
|
|
|
// No link/invalid link selected.
|
|
|
|
return null;
|
|
|
|
}
|
2012-01-04 17:48:54 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('form.htmleditorfield-linkform input[name=LinkType]').entwine({
|
|
|
|
onclick: function(e) {
|
|
|
|
this.parents('form:first').redraw();
|
2014-07-30 00:59:13 +02:00
|
|
|
this._super();
|
2012-01-04 17:48:54 +01:00
|
|
|
},
|
|
|
|
onchange: function() {
|
|
|
|
this.parents('form:first').redraw();
|
2014-07-30 00:59:13 +02:00
|
|
|
|
|
|
|
// Update if a anchor-supporting link type is selected.
|
|
|
|
var linkType = this.parent().find(':checked').val();
|
|
|
|
if (linkType==='anchor' || linkType==='internal') {
|
|
|
|
this.parents('form.htmleditorfield-linkform').updateAnchorSelector();
|
|
|
|
}
|
|
|
|
this._super();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('form.htmleditorfield-linkform input[name=internal]').entwine({
|
|
|
|
/**
|
|
|
|
* Update the anchor dropdown if a different page is selected in the "internal" dropdown.
|
|
|
|
*/
|
|
|
|
onvalueupdated: function() {
|
|
|
|
this.parents('form.htmleditorfield-linkform').updateAnchorSelector();
|
|
|
|
this._super();
|
2012-01-04 17:48:54 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-02-23 18:35:04 +01:00
|
|
|
$('form.htmleditorfield-linkform :submit[name=action_remove]').entwine({
|
2012-01-04 17:48:54 +01:00
|
|
|
onclick: function(e) {
|
|
|
|
this.parents('form:first').removeLink();
|
2014-07-30 00:59:13 +02:00
|
|
|
this._super();
|
2012-01-04 17:48:54 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
});
|
2012-02-08 21:32:25 +01:00
|
|
|
|
2012-02-09 17:17:39 +01:00
|
|
|
/**
|
|
|
|
* Responsible for inserting media files, although only images are supported so far.
|
|
|
|
* Allows to select one or more files, and load form fields for each file via ajax.
|
|
|
|
* This allows us to tailor the form fields to the file type (e.g. different ones for images and flash),
|
|
|
|
* as well as add new form fields via framework extensions.
|
|
|
|
* The inputs on each of those files are used for constructing the HTML to insert into
|
|
|
|
* the rich text editor. Also allows editing the properties of existing files if any are selected in the editor.
|
|
|
|
* Note: Not each file has a representation on the webserver filesystem, supports insertion and editing
|
|
|
|
* of remove files as well.
|
|
|
|
*/
|
2012-02-08 21:32:25 +01:00
|
|
|
$('form.htmleditorfield-mediaform').entwine({
|
2012-04-20 07:57:46 +02:00
|
|
|
toggleCloseButton: function(){
|
|
|
|
var updateExisting = Boolean(this.find('.ss-htmleditorfield-file').length);
|
|
|
|
this.find('.overview .action-delete')[updateExisting ? 'hide' : 'show']();
|
2012-04-20 06:11:15 +02:00
|
|
|
},
|
2012-06-08 06:42:14 +02:00
|
|
|
onsubmit: function() {
|
2012-06-20 05:27:56 +02:00
|
|
|
this.modifySelection(function(ed){
|
|
|
|
this.find('.ss-htmleditorfield-file').each(function() {
|
|
|
|
$(this).insertHTML(ed);
|
|
|
|
});
|
2012-02-09 17:17:39 +01:00
|
|
|
|
2012-06-20 05:27:56 +02:00
|
|
|
ed.repaint();
|
2013-06-20 05:21:18 +02:00
|
|
|
});
|
2012-02-09 17:17:39 +01:00
|
|
|
|
2012-06-20 05:27:56 +02:00
|
|
|
this.getDialog().close();
|
2012-02-09 17:17:39 +01:00
|
|
|
return false;
|
|
|
|
},
|
2012-06-08 06:42:14 +02:00
|
|
|
updateFromEditor: function() {
|
2012-06-20 05:27:56 +02:00
|
|
|
var self = this, node = this.getSelection();
|
|
|
|
|
2012-02-09 17:17:39 +01:00
|
|
|
// TODO Depends on managed mime type
|
|
|
|
if(node.is('img')) {
|
2013-01-30 03:55:17 +01:00
|
|
|
this.showFileView(node.data('url') || node.attr('src')).done(function(filefield) {
|
|
|
|
filefield.updateFromNode(node);
|
2012-04-20 07:57:46 +02:00
|
|
|
self.toggleCloseButton();
|
2012-02-09 17:17:39 +01:00
|
|
|
self.redraw();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
this.redraw();
|
|
|
|
},
|
2013-06-14 23:26:11 +02:00
|
|
|
redraw: function(updateExisting) {
|
2012-02-09 17:17:39 +01:00
|
|
|
this._super();
|
2012-05-22 08:18:31 +02:00
|
|
|
|
2012-06-20 05:27:56 +02:00
|
|
|
var node = this.getSelection(),
|
2012-02-09 17:17:39 +01:00
|
|
|
hasItems = Boolean(this.find('.ss-htmleditorfield-file').length),
|
2012-05-20 12:53:54 +02:00
|
|
|
editingSelected = node.is('img'),
|
|
|
|
header = this.find('.header-edit');
|
2012-02-09 17:17:39 +01:00
|
|
|
|
|
|
|
// Only show second step if files are selected
|
2013-06-14 23:26:11 +02:00
|
|
|
header[(hasItems) ? 'show' : 'hide']();
|
2012-02-09 17:17:39 +01:00
|
|
|
|
|
|
|
// Disable "insert" button if no files are selected
|
2015-10-01 03:16:07 +02:00
|
|
|
this.closest('ui-dialog')
|
|
|
|
.find('ui-dialog-buttonpane .media-insert')
|
2012-02-09 17:17:39 +01:00
|
|
|
.button(hasItems ? 'enable' : 'disable')
|
2012-05-22 08:18:31 +02:00
|
|
|
.toggleClass('ui-state-disabled', !hasItems);
|
|
|
|
|
2012-02-09 17:17:39 +01:00
|
|
|
// Hide file selection and step labels when editing an existing file
|
2015-09-21 00:00:05 +02:00
|
|
|
this.find('.htmleditorfield-from-computer')[editingSelected ? 'hide' : 'show']();
|
|
|
|
this.find('.htmleditorfield-from-cms')[editingSelected ? 'hide' : 'show']();
|
|
|
|
if (editingSelected) {
|
|
|
|
this.find('.htmleditorfield-from-web').hide();
|
|
|
|
}
|
2012-05-20 12:53:54 +02:00
|
|
|
|
2013-06-14 23:26:11 +02:00
|
|
|
// TODO Way too much knowledge on UploadField internals, use viewfile URL directly instead
|
|
|
|
this.find('.htmleditorfield-mediaform-heading.insert')[editingSelected ? 'hide' : 'show']();
|
2013-06-14 23:26:25 +02:00
|
|
|
this.find('.ss-uploadfield-item-actions')[editingSelected ? 'hide' : 'show']();
|
|
|
|
this.find('.ss-uploadfield-item-name')[editingSelected ? 'hide' : 'show']();
|
|
|
|
this.find('.ss-uploadfield-item-preview')[editingSelected ? 'hide' : 'show']();
|
2013-06-14 23:26:11 +02:00
|
|
|
this.find('.htmleditorfield-mediaform-heading.update')[editingSelected ? 'show' : 'hide']();
|
|
|
|
this.find('.Actions .media-update')[editingSelected ? 'show' : 'hide']();
|
|
|
|
this.find('.ss-uploadfield-item-editform').toggleEditForm(editingSelected);
|
2015-09-21 00:00:05 +02:00
|
|
|
this.find('.htmleditorfield-from-cms .field.treedropdown').css('left', $('.htmleditorfield-mediaform-heading:visible').outerWidth());
|
|
|
|
this.closest('.ui-dialog').addClass('ss-uploadfield-dropzone');
|
2015-10-01 03:16:07 +02:00
|
|
|
this.closest('.ui-dialog')
|
|
|
|
.find('.ui-dialog-buttonpane .media-insert .ui-button-text')
|
|
|
|
.text([editingSelected ? ss.i18n._t(
|
|
|
|
'HtmlEditorField.UPDATE',
|
|
|
|
'Update'
|
|
|
|
) : ss.i18n._t(
|
|
|
|
'HtmlEditorField.INSERT',
|
|
|
|
'Insert'
|
|
|
|
)]);
|
2012-02-09 17:17:39 +01:00
|
|
|
},
|
2014-07-30 00:59:13 +02:00
|
|
|
resetFields: function() {
|
2012-04-12 22:28:00 +02:00
|
|
|
this.find('.ss-htmleditorfield-file').remove(); // Remove any existing views
|
|
|
|
this.find('.ss-gridfield-items .ui-selected').removeClass('ui-selected'); // Unselect all items
|
2012-11-23 17:33:17 +01:00
|
|
|
this.find('li.ss-uploadfield-item').remove(); // Remove all selected items
|
2012-04-12 22:28:00 +02:00
|
|
|
this.redraw();
|
|
|
|
|
|
|
|
this._super();
|
|
|
|
},
|
2012-02-09 17:17:39 +01:00
|
|
|
getFileView: function(idOrUrl) {
|
|
|
|
return this.find('.ss-htmleditorfield-file[data-id=' + idOrUrl + ']');
|
|
|
|
},
|
2013-01-30 03:55:17 +01:00
|
|
|
showFileView: function(idOrUrl) {
|
|
|
|
var self = this, params = (Number(idOrUrl) == idOrUrl) ? {ID: idOrUrl} : {FileURL: idOrUrl};
|
2012-02-09 17:17:39 +01:00
|
|
|
|
2013-01-30 03:55:17 +01:00
|
|
|
var item = $('<div class="ss-htmleditorfield-file loading" />');
|
2013-06-14 23:03:31 +02:00
|
|
|
this.find('.content-edit').prepend(item);
|
2013-01-30 03:55:17 +01:00
|
|
|
|
|
|
|
var dfr = $.Deferred();
|
|
|
|
|
|
|
|
$.ajax({
|
2012-05-16 00:10:00 +02:00
|
|
|
url: $.path.addSearchParams(this.attr('action').replace(/MediaForm/, 'viewfile'), params),
|
2012-02-09 17:17:39 +01:00
|
|
|
success: function(html, status, xhr) {
|
2013-01-30 03:55:17 +01:00
|
|
|
var newItem = $(html).filter('.ss-htmleditorfield-file');
|
2012-02-09 17:17:39 +01:00
|
|
|
item.replaceWith(newItem);
|
|
|
|
self.redraw();
|
2013-01-30 03:55:17 +01:00
|
|
|
dfr.resolve(newItem);
|
2012-02-09 17:17:39 +01:00
|
|
|
},
|
|
|
|
error: function() {
|
|
|
|
item.remove();
|
2013-01-30 03:55:17 +01:00
|
|
|
dfr.reject();
|
2012-02-09 17:17:39 +01:00
|
|
|
}
|
|
|
|
});
|
2013-01-30 03:55:17 +01:00
|
|
|
|
|
|
|
return dfr.promise();
|
2012-02-09 17:17:39 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('form.htmleditorfield-mediaform .ss-gridfield-items').entwine({
|
|
|
|
onselectableselected: function(e, ui) {
|
|
|
|
var form = this.closest('form'), item = $(ui.selected);
|
|
|
|
if(!item.is('.ss-gridfield-item')) return;
|
|
|
|
form.closest('form').showFileView(item.data('id'));
|
|
|
|
form.redraw();
|
2015-09-21 00:00:05 +02:00
|
|
|
|
|
|
|
form.parent().trigger('scroll');
|
2012-02-09 17:17:39 +01:00
|
|
|
},
|
|
|
|
onselectableunselected: function(e, ui) {
|
|
|
|
var form = this.closest('form'), item = $(ui.unselected);
|
|
|
|
if(!item.is('.ss-gridfield-item')) return;
|
|
|
|
form.getFileView(item.data('id')).remove();
|
|
|
|
form.redraw();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-03-29 02:34:55 +02:00
|
|
|
/**
|
|
|
|
* Show the second step after uploading an image
|
|
|
|
*/
|
2012-03-30 02:45:53 +02:00
|
|
|
$('form.htmleditorfield-form.htmleditorfield-mediaform div.ss-assetuploadfield').entwine({
|
2012-04-04 03:45:58 +02:00
|
|
|
//the UploadField div.ss-uploadfield-editandorganize is hidden in CSS,
|
|
|
|
// because we use the detail view for each individual file instead
|
2012-03-29 02:34:55 +02:00
|
|
|
onfileuploadstop: function(e) {
|
|
|
|
var form = this.closest('form');
|
2012-03-30 02:45:53 +02:00
|
|
|
|
|
|
|
//update the editFields to show those Files that are newly uploaded
|
|
|
|
var editFieldIDs = [];
|
|
|
|
form.find('div.content-edit').find('div.ss-htmleditorfield-file').each(function(){
|
|
|
|
//get the uploaded file ID when this event triggers, signaling the upload has compeleted successfully
|
|
|
|
editFieldIDs.push($(this).data('id'));
|
|
|
|
});
|
2013-02-27 19:17:09 +01:00
|
|
|
// we only want this .ss-uploadfield-files - else we get all ss-uploadfield-files wich include the ones not related to #tinymce insertmedia
|
|
|
|
var uploadedFiles = $('.ss-uploadfield-files', this).children('.ss-uploadfield-item');
|
2012-03-30 02:45:53 +02:00
|
|
|
uploadedFiles.each(function(){
|
|
|
|
var uploadedID = $(this).data('fileid');
|
2013-06-20 05:21:18 +02:00
|
|
|
if (uploadedID && $.inArray(uploadedID, editFieldIDs) == -1) {
|
2012-03-30 02:45:53 +02:00
|
|
|
//trigger the detail view for filling out details about the file we are about to insert into TinyMCE
|
2013-06-20 05:21:18 +02:00
|
|
|
$(this).remove(); // Remove successfully added item from the queue
|
2012-03-30 02:45:53 +02:00
|
|
|
form.showFileView(uploadedID);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-09-21 00:00:05 +02:00
|
|
|
form.parent().trigger('scroll');
|
|
|
|
|
2012-03-29 02:34:55 +02:00
|
|
|
form.redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2012-06-21 04:19:41 +02:00
|
|
|
$('form.htmleditorfield-form.htmleditorfield-mediaform input.remoteurl').entwine({
|
|
|
|
onadd: function() {
|
2014-07-14 01:15:38 +02:00
|
|
|
this._super();
|
2012-06-21 04:19:41 +02:00
|
|
|
this.validate();
|
|
|
|
},
|
|
|
|
|
|
|
|
onkeyup: function() {
|
|
|
|
this.validate();
|
|
|
|
},
|
|
|
|
|
|
|
|
onchange: function() {
|
|
|
|
this.validate();
|
|
|
|
},
|
|
|
|
|
|
|
|
getAddButton: function() {
|
|
|
|
return this.closest('.CompositeField').find('button.add-url');
|
|
|
|
},
|
|
|
|
|
|
|
|
validate: function() {
|
|
|
|
var val = this.val(), orig = val;
|
2015-01-13 02:51:24 +01:00
|
|
|
|
|
|
|
val = $.trim(val);
|
2012-06-21 04:19:41 +02:00
|
|
|
val = val.replace(/^https?:\/\//i, '');
|
|
|
|
if (orig !== val) this.val(val);
|
|
|
|
|
|
|
|
this.getAddButton().button(!!val ? 'enable' : 'disable');
|
|
|
|
return !!val;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-05-22 06:45:36 +02:00
|
|
|
/**
|
|
|
|
* Show the second step after adding a URL
|
|
|
|
*/
|
2012-06-11 02:55:40 +02:00
|
|
|
$('form.htmleditorfield-form.htmleditorfield-mediaform .add-url').entwine({
|
2012-06-21 04:19:41 +02:00
|
|
|
getURLField: function() {
|
|
|
|
return this.closest('.CompositeField').find('input.remoteurl');
|
|
|
|
},
|
|
|
|
|
2012-05-22 06:45:36 +02:00
|
|
|
onclick: function(e) {
|
2012-06-22 10:25:15 +02:00
|
|
|
var urlField = this.getURLField(), container = this.closest('.CompositeField'), form = this.closest('form');
|
2012-05-22 06:45:36 +02:00
|
|
|
|
2012-06-21 04:19:41 +02:00
|
|
|
if (urlField.validate()) {
|
2012-06-22 10:25:15 +02:00
|
|
|
container.addClass('loading');
|
2013-01-30 03:55:17 +01:00
|
|
|
form.showFileView('http://' + urlField.val()).done(function() {
|
2012-06-22 10:25:15 +02:00
|
|
|
container.removeClass('loading');
|
2015-09-21 00:00:05 +02:00
|
|
|
|
|
|
|
form.parent().trigger('scroll');
|
2012-06-22 10:25:15 +02:00
|
|
|
});
|
2012-06-21 04:19:41 +02:00
|
|
|
form.redraw();
|
|
|
|
}
|
2012-05-22 06:45:36 +02:00
|
|
|
|
2012-06-11 02:55:40 +02:00
|
|
|
return false;
|
2012-05-22 06:45:36 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-02-09 17:17:39 +01:00
|
|
|
/**
|
|
|
|
* Represents a single selected file, together with a set of form fields to edit its properties.
|
|
|
|
* Overload this based on the media type to determine how the HTML should be created.
|
|
|
|
*/
|
|
|
|
$('form.htmleditorfield-mediaform .ss-htmleditorfield-file').entwine({
|
|
|
|
/**
|
|
|
|
* @return {Object} Map of HTML attributes which can be set on the created DOM node.
|
|
|
|
*/
|
|
|
|
getAttributes: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* @return {Object} Map of additional properties which can be evaluated
|
|
|
|
* by the specific media type.
|
|
|
|
*/
|
|
|
|
getExtraData: function() {
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* @return {String} HTML suitable for insertion into the rich text editor
|
|
|
|
*/
|
|
|
|
getHTML: function() {
|
2013-06-13 09:29:55 +02:00
|
|
|
// Assumes UploadField markup structure
|
|
|
|
return $('<div>').append(
|
|
|
|
$('<a/>').attr({href: this.data('url')}).text(this.find('.name').text())
|
|
|
|
).html();
|
2012-02-09 17:17:39 +01:00
|
|
|
},
|
2012-02-22 17:53:37 +01:00
|
|
|
/**
|
|
|
|
* Insert updated HTML content into the rich text editor
|
|
|
|
*/
|
2012-06-20 05:27:56 +02:00
|
|
|
insertHTML: function(ed) {
|
2012-02-22 17:53:37 +01:00
|
|
|
// Insert content
|
|
|
|
ed.replaceContent(this.getHTML());
|
|
|
|
},
|
2012-02-09 17:17:39 +01:00
|
|
|
/**
|
|
|
|
* Updates the form values from an existing node in the editor.
|
|
|
|
*
|
|
|
|
* @param {DOMElement}
|
|
|
|
*/
|
|
|
|
updateFromNode: function(node) {
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Transforms values set on the dimensions form fields based on two constraints:
|
|
|
|
* An aspect ration, and max width/height values. Writes back to the field properties as required.
|
|
|
|
*
|
|
|
|
* @param {String} The dimension to constrain the other value by, if any ("Width" or "Height")
|
|
|
|
* @param {Int} Optional max width
|
|
|
|
* @param {Int} Optional max height
|
|
|
|
*/
|
|
|
|
updateDimensions: function(constrainBy, maxW, maxH) {
|
|
|
|
var widthEl = this.find(':input[name=Width]'),
|
|
|
|
heightEl = this.find(':input[name=Height]'),
|
|
|
|
w = widthEl.val(),
|
|
|
|
h = heightEl.val(),
|
|
|
|
aspect;
|
|
|
|
|
|
|
|
// Proportionate updating of heights, using the original values
|
|
|
|
if(w && h) {
|
|
|
|
if(constrainBy) {
|
|
|
|
aspect = heightEl.getOrigVal() / widthEl.getOrigVal();
|
|
|
|
// Uses floor() and ceil() to avoid both fields constantly lowering each other's values in rounding situations
|
|
|
|
if(constrainBy == 'Width') {
|
|
|
|
if(maxW && w > maxW) w = maxW;
|
|
|
|
h = Math.floor(w * aspect);
|
|
|
|
} else if(constrainBy == 'Height') {
|
|
|
|
if(maxH && h > maxH) h = maxH;
|
|
|
|
w = Math.ceil(h / aspect);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(maxW && w > maxW) w = maxW;
|
|
|
|
if(maxH && h > maxH) h = maxH;
|
|
|
|
}
|
|
|
|
|
|
|
|
widthEl.val(w);
|
|
|
|
heightEl.val(h);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('form.htmleditorfield-mediaform .ss-htmleditorfield-file.image').entwine({
|
|
|
|
getAttributes: function() {
|
|
|
|
var width = this.find(':input[name=Width]').val(),
|
|
|
|
height = this.find(':input[name=Height]').val();
|
|
|
|
return {
|
|
|
|
'src' : this.find(':input[name=URL]').val(),
|
|
|
|
'alt' : this.find(':input[name=AltText]').val(),
|
2012-04-02 04:10:20 +02:00
|
|
|
'width' : width ? parseInt(width, 10) : null,
|
|
|
|
'height' : height ? parseInt(height, 10) : null,
|
2012-02-09 17:17:39 +01:00
|
|
|
'title' : this.find(':input[name=Title]').val(),
|
2015-09-15 04:52:02 +02:00
|
|
|
'class' : this.find(':input[name=CSSClass]').val(),
|
|
|
|
'data-fileid' : this.find(':input[name=FileID]').val()
|
2012-02-09 17:17:39 +01:00
|
|
|
};
|
|
|
|
},
|
|
|
|
getExtraData: function() {
|
|
|
|
return {
|
|
|
|
'CaptionText': this.find(':input[name=CaptionText]').val()
|
|
|
|
};
|
|
|
|
},
|
|
|
|
getHTML: function() {
|
2013-01-31 04:35:48 +01:00
|
|
|
/* NOP */
|
2012-02-09 17:17:39 +01:00
|
|
|
},
|
2012-02-22 17:53:37 +01:00
|
|
|
/**
|
|
|
|
* Logic similar to TinyMCE 'advimage' plugin, insertAndClose() method.
|
|
|
|
*/
|
2012-06-20 05:27:56 +02:00
|
|
|
insertHTML: function(ed) {
|
2014-07-30 00:59:13 +02:00
|
|
|
var form = this.closest('form');
|
|
|
|
var node = form.getSelection();
|
|
|
|
if (!ed) ed = form.getEditor();
|
2013-01-31 04:35:48 +01:00
|
|
|
|
|
|
|
// Get the attributes & extra data
|
|
|
|
var attrs = this.getAttributes(), extraData = this.getExtraData();
|
|
|
|
|
|
|
|
// Find the element we are replacing - either the img, it's wrapper parent, or nothing (if creating)
|
|
|
|
var replacee = (node && node.is('img')) ? node : null;
|
|
|
|
if (replacee && replacee.parent().is('.captionImage')) replacee = replacee.parent();
|
|
|
|
|
|
|
|
// Find the img node - either the existing img or a new one, and update it
|
|
|
|
var img = (node && node.is('img')) ? node : $('<img />');
|
|
|
|
img.attr(attrs);
|
|
|
|
|
|
|
|
// Any existing figure or caption node
|
|
|
|
var container = img.parent('.captionImage'), caption = container.find('.caption');
|
|
|
|
|
|
|
|
// If we've got caption text, we need a wrapping div.captionImage and sibling p.caption
|
|
|
|
if (extraData.CaptionText) {
|
|
|
|
if (!container.length) {
|
|
|
|
container = $('<div></div>');
|
2012-02-22 17:53:37 +01:00
|
|
|
}
|
2013-01-31 04:35:48 +01:00
|
|
|
|
2013-01-31 22:17:56 +01:00
|
|
|
container.attr('class', 'captionImage '+attrs['class']).css('width', attrs.width);
|
2013-01-31 04:35:48 +01:00
|
|
|
|
|
|
|
if (!caption.length) {
|
|
|
|
caption = $('<p class="caption"></p>').appendTo(container);
|
|
|
|
}
|
|
|
|
|
2013-01-31 22:17:56 +01:00
|
|
|
caption.attr('class', 'caption '+attrs['class']).text(extraData.CaptionText);
|
2013-01-31 04:35:48 +01:00
|
|
|
}
|
|
|
|
// Otherwise forget they exist
|
|
|
|
else {
|
|
|
|
container = caption = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
// The element we are replacing the replacee with
|
|
|
|
var replacer = container ? container : img;
|
|
|
|
|
|
|
|
// If we're replacing something, and it's not with itself, do so
|
|
|
|
if (replacee && replacee.not(replacer).length) {
|
|
|
|
replacee.replaceWith(replacer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have a wrapper element, make sure the img is the first child - img might be the
|
|
|
|
// replacee, and the wrapper the replacer, and we can't do this till after the replace has happened
|
|
|
|
if (container) {
|
|
|
|
container.prepend(img);
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we don't have a replacee, then we need to insert the whole HTML
|
|
|
|
if (!replacee) {
|
2012-02-22 17:53:37 +01:00
|
|
|
// Otherwise insert the whole HTML content
|
|
|
|
ed.repaint();
|
2013-01-31 04:35:48 +01:00
|
|
|
ed.insertContent($('<div />').append(replacer).html(), {skip_undo : 1});
|
2012-02-22 17:53:37 +01:00
|
|
|
}
|
|
|
|
|
2013-01-31 04:35:48 +01:00
|
|
|
ed.addUndo();
|
2012-02-22 17:53:37 +01:00
|
|
|
ed.repaint();
|
|
|
|
},
|
2012-02-09 17:17:39 +01:00
|
|
|
updateFromNode: function(node) {
|
|
|
|
this.find(':input[name=AltText]').val(node.attr('alt'));
|
|
|
|
this.find(':input[name=Title]').val(node.attr('title'));
|
2013-05-13 00:08:03 +02:00
|
|
|
this.find(':input[name=CSSClass]').val(node.attr('class'));
|
2012-02-09 17:17:39 +01:00
|
|
|
this.find(':input[name=Width]').val(node.width());
|
|
|
|
this.find(':input[name=Height]').val(node.height());
|
|
|
|
this.find(':input[name=CaptionText]').val(node.siblings('.caption:first').text());
|
2015-09-15 04:52:02 +02:00
|
|
|
this.find(':input[name=FileID]').val(node.data('fileid'));
|
2012-02-09 17:17:39 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert a flash object tag into the content.
|
|
|
|
* Requires the 'media' plugin for serialization of tags into <img> placeholders.
|
|
|
|
*/
|
|
|
|
$('form.htmleditorfield-mediaform .ss-htmleditorfield-file.flash').entwine({
|
|
|
|
getAttributes: function() {
|
|
|
|
var width = this.find(':input[name=Width]').val(),
|
|
|
|
height = this.find(':input[name=Height]').val();
|
|
|
|
return {
|
|
|
|
'src' : this.find(':input[name=URL]').val(),
|
|
|
|
'width' : width ? parseInt(width, 10) : null,
|
2015-09-15 04:52:02 +02:00
|
|
|
'height' : height ? parseInt(height, 10) : null,
|
|
|
|
'data-fileid' : this.find(':input[name=FileID]').val()
|
2012-02-09 17:17:39 +01:00
|
|
|
};
|
|
|
|
},
|
|
|
|
getHTML: function() {
|
|
|
|
var attrs = this.getAttributes();
|
|
|
|
|
|
|
|
// Emulate serialization from 'media' plugin
|
|
|
|
var el = tinyMCE.activeEditor.plugins.media.dataToImg({
|
|
|
|
'type': 'flash',
|
|
|
|
'width': attrs.width,
|
|
|
|
'height': attrs.height,
|
|
|
|
'params': {'src': attrs.src},
|
|
|
|
'video': {'sources': []}
|
|
|
|
});
|
|
|
|
|
|
|
|
return $('<div />').append(el).html(); // Little hack to get outerHTML string
|
|
|
|
},
|
|
|
|
updateFromNode: function(node) {
|
|
|
|
// TODO Not implemented
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-05-22 06:45:36 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert an oembed object tag into the content.
|
|
|
|
* Requires the 'media' plugin for serialization of tags into <img> placeholders.
|
|
|
|
*/
|
|
|
|
$('form.htmleditorfield-mediaform .ss-htmleditorfield-file.embed').entwine({
|
|
|
|
getAttributes: function() {
|
|
|
|
var width = this.find(':input[name=Width]').val(),
|
|
|
|
height = this.find(':input[name=Height]').val();
|
|
|
|
return {
|
|
|
|
'src' : this.find('.thumbnail-preview').attr('src'),
|
|
|
|
'width' : width ? parseInt(width, 10) : null,
|
|
|
|
'height' : height ? parseInt(height, 10) : null,
|
2013-12-19 19:43:46 +01:00
|
|
|
'class' : this.find(':input[name=CSSClass]').val(),
|
|
|
|
'alt' : this.find(':input[name=AltText]').val(),
|
2015-09-15 04:52:02 +02:00
|
|
|
'title' : this.find(':input[name=Title]').val(),
|
|
|
|
'data-fileid' : this.find(':input[name=FileID]').val()
|
2012-05-22 06:45:36 +02:00
|
|
|
};
|
|
|
|
},
|
|
|
|
getExtraData: function() {
|
|
|
|
var width = this.find(':input[name=Width]').val(),
|
|
|
|
height = this.find(':input[name=Height]').val();
|
|
|
|
return {
|
|
|
|
'CaptionText': this.find(':input[name=CaptionText]').val(),
|
|
|
|
'Url': this.find(':input[name=URL]').val(),
|
|
|
|
'thumbnail': this.find('.thumbnail-preview').attr('src'),
|
|
|
|
'width' : width ? parseInt(width, 10) : null,
|
|
|
|
'height' : height ? parseInt(height, 10) : null,
|
|
|
|
'cssclass': this.find(':input[name=CSSClass]').val()
|
|
|
|
};
|
|
|
|
},
|
|
|
|
getHTML: function() {
|
|
|
|
var el,
|
|
|
|
attrs = this.getAttributes(),
|
|
|
|
extraData = this.getExtraData(),
|
|
|
|
// imgEl = $('<img id="_ss_tmp_img" />');
|
|
|
|
imgEl = $('<img />').attr(attrs).addClass('ss-htmleditorfield-file embed');
|
|
|
|
|
|
|
|
$.each(extraData, function (key, value) {
|
2014-07-30 00:59:13 +02:00
|
|
|
imgEl.attr('data-' + key, value);
|
2012-05-22 06:45:36 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if(extraData.CaptionText) {
|
|
|
|
el = $('<div style="width: ' + attrs['width'] + 'px;" class="captionImage ' + attrs['class'] + '"><p class="caption">' + extraData.CaptionText + '</p></div>').prepend(imgEl);
|
|
|
|
} else {
|
|
|
|
el = imgEl;
|
|
|
|
}
|
|
|
|
return $('<div />').append(el).html(); // Little hack to get outerHTML string
|
|
|
|
},
|
|
|
|
updateFromNode: function(node) {
|
2013-12-19 19:43:46 +01:00
|
|
|
this.find(':input[name=AltText]').val(node.attr('alt'));
|
|
|
|
this.find(':input[name=Title]').val(node.attr('title'));
|
2012-05-22 06:45:36 +02:00
|
|
|
this.find(':input[name=Width]').val(node.width());
|
|
|
|
this.find(':input[name=Height]').val(node.height());
|
|
|
|
this.find(':input[name=Title]').val(node.attr('title'));
|
|
|
|
this.find(':input[name=CSSClass]').val(node.data('cssclass'));
|
2015-09-15 04:52:02 +02:00
|
|
|
this.find(':input[name=FileID]').val(node.data('fileid'));
|
2012-05-22 06:45:36 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-02-09 17:17:39 +01:00
|
|
|
$('form.htmleditorfield-mediaform .ss-htmleditorfield-file .dimensions :input').entwine({
|
|
|
|
OrigVal: null,
|
|
|
|
onmatch: function () {
|
|
|
|
this._super();
|
|
|
|
|
|
|
|
this.setOrigVal(parseInt(this.val(), 10));
|
|
|
|
},
|
2012-05-14 01:43:36 +02:00
|
|
|
onunmatch: function() {
|
|
|
|
this._super();
|
|
|
|
},
|
2012-02-09 17:17:39 +01:00
|
|
|
onfocusout: function(e) {
|
|
|
|
this.closest('.ss-htmleditorfield-file').updateDimensions(this.attr('name'));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deselect item and remove the 'edit' view
|
|
|
|
*/
|
2012-05-22 08:18:31 +02:00
|
|
|
$('form.htmleditorfield-mediaform .ss-uploadfield-item .ss-uploadfield-item-cancel').entwine({
|
2012-02-09 17:17:39 +01:00
|
|
|
onclick: function(e) {
|
2012-05-22 08:18:31 +02:00
|
|
|
var form = this.closest('form'), file = this.closest('ss-uploadfield-item');
|
2012-02-09 17:17:39 +01:00
|
|
|
form.find('.ss-gridfield-item[data-id=' + file.data('id') + ']').removeClass('ui-selected');
|
2012-05-22 08:18:31 +02:00
|
|
|
this.closest('.ss-uploadfield-item').remove();
|
2012-02-09 17:17:39 +01:00
|
|
|
form.redraw();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
2012-02-08 21:32:25 +01:00
|
|
|
});
|
|
|
|
|
2012-05-22 08:18:31 +02:00
|
|
|
$('div.ss-assetuploadfield .ss-uploadfield-item-edit, div.ss-assetuploadfield .ss-uploadfield-item-name').entwine({
|
2012-06-12 12:48:08 +02:00
|
|
|
getEditForm: function() {
|
|
|
|
return this.closest('.ss-uploadfield-item').find('.ss-uploadfield-item-editform');
|
|
|
|
},
|
|
|
|
|
|
|
|
fromEditForm: {
|
|
|
|
onchange: function(e){
|
|
|
|
var form = $(e.target);
|
|
|
|
form.removeClass('edited'); //so edited class is only there once
|
|
|
|
form.addClass('edited');
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-05-22 08:18:31 +02:00
|
|
|
onclick: function(e) {
|
2012-06-12 12:48:08 +02:00
|
|
|
var editForm = this.getEditForm();
|
2013-12-12 14:17:57 +01:00
|
|
|
|
|
|
|
// Make sure we're in an HtmlEditorField here, or fall-back to _super(). HtmlEditorField with
|
|
|
|
// AssetUploadField doesn't use iframes, so needs its own toggleEditForm() logic
|
|
|
|
if (this.closest('.ss-uploadfield-item').hasClass('ss-htmleditorfield-file')) {
|
|
|
|
editForm.parent('ss-uploadfield-item').removeClass('ui-state-warning');
|
|
|
|
|
|
|
|
editForm.toggleEditForm();
|
2012-05-22 08:18:31 +02:00
|
|
|
|
2013-12-12 14:17:57 +01:00
|
|
|
e.preventDefault(); // Avoid a form submit
|
2012-05-22 08:18:31 +02:00
|
|
|
|
2013-12-12 14:17:57 +01:00
|
|
|
return false; // Avoid duplication from button
|
|
|
|
}
|
2012-05-22 08:18:31 +02:00
|
|
|
|
2013-12-12 14:17:57 +01:00
|
|
|
this._super(e);
|
2012-05-22 08:18:31 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$('div.ss-assetuploadfield .ss-uploadfield-item-editform').entwine({
|
2013-06-14 23:26:11 +02:00
|
|
|
toggleEditForm: function(bool) {
|
2012-05-22 08:18:31 +02:00
|
|
|
var itemInfo = this.prev('.ss-uploadfield-item-info'), status = itemInfo.find('.ss-uploadfield-item-status');
|
|
|
|
var text="";
|
|
|
|
|
2013-06-14 23:26:11 +02:00
|
|
|
if(bool === true || (bool !== false && this.height() === 0)) {
|
2012-05-22 08:18:31 +02:00
|
|
|
text = ss.i18n._t('UploadField.Editing', "Editing ...");
|
|
|
|
this.height('auto');
|
|
|
|
itemInfo.find('.toggle-details-icon').addClass('opened');
|
|
|
|
status.removeClass('ui-state-success-text').removeClass('ui-state-warning-text');
|
|
|
|
} else {
|
|
|
|
this.height(0);
|
|
|
|
itemInfo.find('.toggle-details-icon').removeClass('opened');
|
|
|
|
if(!this.hasClass('edited')){
|
2014-07-30 00:59:13 +02:00
|
|
|
text = ss.i18n._t('UploadField.NOCHANGES', 'No Changes');
|
2012-05-22 08:18:31 +02:00
|
|
|
status.addClass('ui-state-success-text');
|
|
|
|
}else{
|
2014-07-30 00:59:13 +02:00
|
|
|
text = ss.i18n._t('UploadField.CHANGESSAVED', 'Changes Made');
|
2012-05-22 08:18:31 +02:00
|
|
|
this.removeClass('edited');
|
|
|
|
status.addClass('ui-state-success-text');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
status.attr('title',text).text(text);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
2013-05-26 01:11:05 +02:00
|
|
|
$('form.htmleditorfield-mediaform .field[id$="ParentID_Holder"] .TreeDropdownField').entwine({
|
2012-06-12 12:48:08 +02:00
|
|
|
onadd: function() {
|
2012-02-09 17:17:39 +01:00
|
|
|
this._super();
|
|
|
|
|
|
|
|
// TODO Custom event doesn't fire in IE if registered through object literal
|
|
|
|
var self = this;
|
|
|
|
this.bind('change', function() {
|
2012-02-23 15:17:39 +01:00
|
|
|
var fileList = self.closest('form').find('.ss-gridfield');
|
2012-02-09 17:17:39 +01:00
|
|
|
fileList.setState('ParentID', self.getValue());
|
|
|
|
fileList.reload();
|
|
|
|
});
|
2012-02-08 21:32:25 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-01-04 17:48:54 +01:00
|
|
|
});
|
2012-02-09 17:17:39 +01:00
|
|
|
})(jQuery);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* These callback globals hook it into tinymce. They need to be referenced in the TinyMCE config.
|
|
|
|
*/
|
|
|
|
function sapphiremce_cleanup(type, value) {
|
|
|
|
if(type == 'get_from_editor') {
|
|
|
|
|
|
|
|
// replace VML pixel image references with image tags - experimental
|
|
|
|
value = value.replace(/<[a-z0-9]+:imagedata[^>]+src="?([^> "]+)"?[^>]*>/ig,"<img src=\"$1\">");
|
|
|
|
|
|
|
|
// Word comments
|
|
|
|
value = value.replace(new RegExp('<(!--)([^>]*)(--)>', 'g'), "");
|
|
|
|
|
|
|
|
// kill class=mso??? and on mouse* tags
|
|
|
|
value = value.replace(/([ \f\r\t\n\'\"])class=mso[a-z0-9]+[^ >]+/ig, "$1");
|
|
|
|
value = value.replace(/([ \f\r\t\n\'\"]class=")mso[a-z0-9]+[^ ">]+ /ig, "$1");
|
|
|
|
value = value.replace(/([ \f\r\t\n\'\"])class="mso[a-z0-9]+[^">]+"/ig, "$1");
|
|
|
|
value = value.replace(/([ \f\r\t\n\'\"])on[a-z]+=[^ >]+/ig, "$1");
|
|
|
|
value = value.replace(/ >/ig, ">");
|
|
|
|
|
|
|
|
// remove everything that's in a closing tag
|
|
|
|
value = value.replace(/<(\/[A-Za-z0-9]+)[ \f\r\t\n]+[^>]*>/ig,"<$1>");
|
|
|
|
}
|
|
|
|
|
|
|
|
if(type == 'get_from_editor_dom') {
|
|
|
|
jQuery(value).find('img').each(function() {
|
|
|
|
this.onresizestart = null;
|
|
|
|
this.onresizeend = null;
|
|
|
|
this.removeAttribute('onresizestart');
|
|
|
|
this.removeAttribute('onresizeend');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
2012-03-01 09:13:42 +01:00
|
|
|
}
|