Drupal 7 / TinyMCE 3.5.8: paste_preprocess callback not running - drupal-7

Drupal 7 with TinyMCE included via the Wysiwyg module. "Paste" is enabled in the Wysiwyg config screen. The editor is in general working fine, but now I'm attempting to modify TinyMCE's paste feature to strip all attributes from HTML tags. (Client requirement, don't ask.)
Have added the following to the module file:
function MYMODULE_wysiwyg_editor_settings_alter(&$settings, $context) {
if ($context['profile']->editor == 'tinymce') {
drupal_add_js(drupal_get_path('module', 'MYMODULE').'/js/tinymce_callbacks.js');
$settings['paste_preprocess'] = 'MYMODULE_tinymce_paste_preprocess_callback';
}
}
and have created tinymce_callbacks.js with the following contents:
function MYMODULE_tinymce_paste_preprocess_callback(pl, o) {
alert(o.content);
o.content = "-: CLEANED :-\n" + o.content;
}
The actual TinyMCE paste button only works with IE, but the ctrl-V shortcut works with every browser. However, the callback is not called.
I did some digging around. The paste_preprocess setting is definitely being added to the correct JavaScript object, but the only code that references it -- the TinyMCE Paste plugin -- isn't being loaded. So it looks like the problem is with Drupal, not TinyMCE.
Any help getting Drupal to load TinyMCE plugins correctly would be most appreciated.

Make sure that the "paste" TinyMCE plugin is actually being loaded. For some reason, in Drupal there is an entry under "Buttons and Plugins" titled simply "Paste". This however does NOT enable the "paste" plugin required for the paste preprocess callback to occur.
Instead, make sure either "Paste Text" or "Paste from Word" is enabled. This should cause the "paste" plugin to load, and the paste preprocess callback to occur.

Related

Changes to transitive dependencies not triggering live reload

I've added Snowpack 3 to my application and it works for JS/TS files as well as directly imported stylus files.
The file structure is similar to the following:
view.js:
import 'view-styles.styl'
export default function view() {
return (
<div className='example-view'>Hello World</div>
);
}
view-styles.styl
#require './colors.styl'
.example-view
background-color: $mainColor
colors.styl
$mainColor = #ff0000
The LiveReload/HMR works as expected when changing the directly imported stylus file. It does not work when changing anything in the colors.styl file. Changes in this file are only picked up once the view-styles.styl file is updated.
Is this a known limitation of Snowpack?
I would also be ok to trigger the update manually, as I have a way to identify these files using their filenames. I haven't found a way yet to trigger live reloads using Snowpack's JavaScript API. I was able to load the file using the SnowpackDevServer.loadUrl function, but that doesn't help either.
I was able to contribute this to the snowpack stylus plugin. The change was already integrated into the plugin: https://github.com/fansenze/snowpack-plugin-stylus

Sencha - Conditionally adding namesapce in requires

I have a requirement that I want to add namespaces in requires conditionally.
e.g. In below example I want to add 'views.popupgrid' name space on specific condition. Currently it's always loaded.
requires: ['Ext.window.MessageBox','views.popupgrid','user.MyUser' ]
Conditional dependencies are not supported by the Sencha toolchain. While you would be able to write in a text editor of your choice
requires:[
(location.hash=='#test')?'testpopup':'normalpopup'
]
and this would work in the uncompiled version, Sencha Cmd would not be able to compile it correctly, and would throw errors.
Therefore, Sencha Architect does not support this syntax.
What you can do, while staying Standards-compliant: you can use Ext.Loader.loadScript, e.g. like this:
Ext.define('MyForm',{
extend: 'Ext.form.Panel'
initComponent:function() {
var me = this;
me.callParent(arguments);
if(x==3) Ext.Loader.loadScript({
url:'MyCustomFormComponent.js',
onLoad:function(){
me.add({
xtype:'mycustomformcomponent'
});
})
});
}
})
Please note that in this case you will always have to deliver MyCustomFormComponent.js alongside the minified app.js, because the dependency cannot be resolved by the toolchain. Also, depending on the connection, there may be a visible delay before the resource is loaded and the component is added to the form.
It is usually faster and smoother to always load the dependency, especially if you intend to deliver the app as a single minified javascript file (e.g. using Sencha Cmd).

AngularJS templateUrl not getting refreshed, always uses the cached version

app.directive('myDirective',function() {
return {
restrict : 'A',
templateUrl : 'app/html.html'
};
});
I'm running into a problem with template html getting cached in the internet explorer. Every time the html is changed, either one of these need to be done to load the new templete:
Delete browsing history and clear temporary internet files.
Change browser setting 'Check for newer versions of stored pages' from Automatic to 'Every time I visit'
A similar problem is stated Here. The marked answer works, but was thinking if there is any better solution to the problem rather than defeating the browser caching.
You must use app version and increase after each update:
<html data-ver="1.0">
And in your js code:
// for example: read app version from data-ver attribute on html tag
window.appVersion = angular.element(document.getElementsByTagName('html')).attr('data-ver');
app.directive('myDirective',function() {
return {
restrict : 'A',
templateUrl : 'app/html.html?v=' + window.appVersion
};
});
I had this issue with changes that I made to my templates. I was able get rid of the single template file that I needed to by following these steps:
Open Internet Explorer
Click the Tools (Alt-X) button and then click Internet Options
Click the General tab, and then under Browsing history, slick Settings
In the Temporary Internet Files and History Settings dialog box, click View Files
Locate the template file that you have modified and delete it.
I hope this helps.

CakePHP 2.5.2 Themeing and theme.ctp

I've created a simple application that is about to be vastly expanded upon and get a bit out of hand if I don't get the theme sorted out early as I need to start working with tinyMCE.
I created my theme in app/View/Themed/Default and added the following into my app controller
public $theme = 'Default';
Something seems to be working because cakePHP is not rendering my views and is giving me the following errors.
Error: The view for {controller name}Controller::add() was not found.
Error: Confirm you have created the file:
/home/cake/public_html/app/View/Themed/Default/{controller}/theme.ctp
I've been reading through the documentation and nowhere in there does it tell me that I need to create a folder for every controller and add a theme.ctp file inside. so I'm at a bit of a loss as to what needs to go into this theme.ctp file.
If I add the Controller folder, and a blank them.ctp file, the view is not rendered. So I am assuming something vital is required here.
I discovered the problem.
Further down the page from legacy code that was ported across, the following code was sitting at the bottom of the page.
AppController.php
function beforeRender() {
$this->view = "Theme";
$this->theme = "default";
}
So it was being forced into rendering a view that did not exist.

tinyMCE aborts with "Object doesn't support this action".

I'm trying to use the AngularJS directive ui-tinymce with tinyMce 4.0.25 and IE10, and am unable to get it to work at all.
My html looks like this:
<textarea ui-tinymce ng-model="fubar"></textarea>
In my controller, I have:
$scope.fubar = "this is a <b>test</b>";
It all goes badly at these two lines in the tinymce initialization code itself.
Theme = ThemeManager.get(settings.theme);
self.theme = new Theme(self, ThemeManager.urls[settings.theme]);
The first line sets Theme to undefined and the last line aborts with the message "Object doesn't support this action". The value of ThemeManager.urls[settings.theme] is "http://localhost:57683/Scripts/tinymce/themes/modern", which seems right.
I can no longer find it, but I'd previously found a post where this issue was due to this code being executed before some other part of tinyMCE had been loaded. The solution there was to use a certain tinyMCE option that forced loading in a certain way, however that option has been removed in tinyMCE 4.x. Even more frustrating is that I had tinyMCE working for days with my own directive when suddenly this occurred. I've simplified this to just using ui-tinymce (with the same result) to rule out any of my code as the culprit.
Mea culpa! I'd switched to using tinymce.js instead of tinymce.min.js and didn't realize that the min code expects the theme to be modern/theme.min.js (which I had) but the unminified code expects the theme to be modern/theme.js.

Resources