How can I use bundling with TinyMCE? - asp.net-mvc

Internet Explorer has a fit when I try and render the minified TinyMCE bundle. So, in order to create a bundle that avoids minification, I followed these instructions to set up a "generic" or "basic" bundle in my BundleConfig:
bundles.Add( new Bundle( "~/Scripts/tinymce" )
.Include( "~/Scripts/tinymce/tinymce.min.js",
"~/Scripts/tinymce/jquery.tinymce.min.js" ) );
How do I render this on the page? None of the following seem to work:
#Bundles.Render( "~/Scripts/tinymce" )
#Bundle.Render( "~/Scripts/tinymce" )
#Bundle( "~/Scripts/tinymce" )
This renders the tag at least:
#Scripts.Render( "~/Scripts/tinymce" )
But it throws a 403 error when it tries to load the file:
"NetworkError: 403 Forbidden - http://localhost:1062/Scripts/tinymce/?v=MTojK5ORvAZmonNqNGJ3aWhOYyor-Fa8dZHTqfSOlUM1"

As pointed out in the comments, this question addresses part of the issue. Since you can't give your bundle a name that is also the name of an existing directory, I renamed it:
bundles.Add( new Bundle( "~/js/tinymce" )
.Include( "~/Scripts/tinymce/tinymce.min.js",
"~/Scripts/tinymce/jquery.tinymce.min.js" ) );
However, due to the way TinyMCE dynamically loads dependencies (plugin and theme files) I have to make sure all of that is included in the bundle as well:
bundles.Add( new Bundle( "~/js/tinymce" )
.Include( "~/Scripts/tinymce/tinymce.min.js",
"~/Scripts/tinymce/jquery.tinymce.min.js",
"~/Scripts/tinymce/plugins/autoresize/plugin.min.js",
"~/Scripts/tinymce/plugins/charmap/plugin.min.js",
"~/Scripts/tinymce/plugins/code/plugin.min.js",
"~/Scripts/tinymce/plugins/image/plugin.min.js",
"~/Scripts/tinymce/plugins/table/plugin.min.js",
"~/Scripts/tinymce/plugins/textcolor/plugin.min.js",
"~/Scripts/tinymce/themes/modern/theme.min.js") );
This means that if I wanted a new plugin it would require a code change and redeployment of bin files instead of a simple script update. However, the requirement for this application hasn't changed and probably won't any time soon (plus, it's an internal app), so this isn't really a problem.
Finally, TinyMCE also dynamically loads skin files (css, images and fonts). I can fix this by changing the TinyMCE configuration to specify the skin directory:
$('.tinymce').tinymce({
skin_url: '/Scripts/tinymce/skins/lightgray',
// other stuff...
});
I tried creating a bundle for the theme files:
bundles.Add( new Bundle( "~/css/tinymce" )
.Include( "~/Scripts/tinymce/skins/lightgray/*.css" ) );
And changing my configuration like so:
$('.tinymce').tinymce({
skin_url: '/css/tinymce',
// blah blah blah...
});
But, because TinyMCE looks for individual files, this did not work. It threw 404 errors for skin.min.css and content.min.css.
So now I have some of the TinyMCE files bundled, but not all of them. This is at least better than what I had before (separate HTTP requests for every single file).

Change your bundle name to something other than an existing location on disk
For example: Bundle( "~/Scripts/tinymce") to Bundle( "~/js/tinymce")

Related

windows installer error when specifying "setupIcon"

I've already packaged the app correctly and am now going through the whole electron-winstaller processs, following the Christian Engvall tutorial exactly.
In createInstaller.js I have the standard
return Promise.resolve({
appDirectory: path.join(outPath, '/MyApp-win32-x64/'),
authors: 'Me',
noMsi: true,
outputDirectory: path.join(outPath, 'windows-installer'),
exe: 'MyApp.exe',
setupExe: 'Setup.exe',
setupIcon: path.join(rootPath, '/path/to/appicon.ico')
});
If I remove the setupIcon parameter, it builds the installer just fine. However if I keep it there, I get an 'Unable to load file' error from the console. I've verified that the path to the .ico file is in fact correct, and is a valid .ico file.
What could possibly be happening?
To fix the Setup Icon error when creating an installer with electron-wininstaller you can use Resource Hacker.
It is for editing the exe file and you can change the ressource file and icons.
For more information you there is a tutorial here.

Old bundle version being served up (cached) after copy to server

I have the following code which works fine on my local machine. Changes + build results in a new bundled file including the modified js code. However, when copied to our staging environment, an old version is being served up, so js changes are not seen.
Files copied include new dlls after a full rebuild + the changed js file. I've also recycled the web (even rebooted).
Even when I turn off optimisation, the staging site is still rendering the optimised script tag rather than a list of js files. Going off my head here.
Any ideas?
private void RegisterBundles()
{
BundleTable.Bundles.Add(new ScriptBundle("~/opt/code-scripts").Include(
"~/Scripts/ga.js",
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*",
"~/Scripts/code.js",
"~/Scripts/twitterFetcher.js",
"~/Scripts/tcode.js",
"~/Scripts/waypoints.js",
"~/Scripts/waypoints-sticky.js",
"~/Scripts/code-twitter.js"
));
BundleTable.Bundles.Add(new StyleBundle("~/opt/code-styles").Include(
"~/css/fonts.css",
"~/css/site.css"
));
BundleTable.EnableOptimizations = true;
}
...
#Scripts.Render("~/opt/code-scripts")

404 in Chrome, not IE, using asp.net bundles

The issue is that when the bundles are minified and I look at the Network tab in Chrome I see a 404 for only this url :
http://localhost:57000/bundles/underscore-min.map
No such directory exists.
If I remove the reference to underscore.js in the bundle then the 404 is for only this url :
http://localhost:57000/bundles/angular-sanitize.min.js.map
This doesn't happen in IE. I've moved the order around and there is always one file, and only one, that will generate the 404.
Here's my bundles that generate the issue.
bundles.Add(new ScriptBundle("~/bundles/scripts")
.Include("~/Scripts/angular/angular.js")
.Include("~/Scripts/angular/angular-resource.js")
.Include("~/Scripts/angular/angular-route.js")
.Include("~/Scripts/angular/angular-animate.js")
.Include("~/Scripts/angular/angular-touch.js")
.Include("~/Scripts/angular/angular-sanitize.js")
.Include("~/Scripts/ng-infinite-scroll.js")
.Include("~/Scripts/underscore.js")
.Include("~/Scripts/bootstrap.js")
.Include("~/Scripts/md5.js")
.IncludeDirectory("~/Scripts/app/", "*.js", true));
anyone seen this before?

CKEditor image dialog is failed

I worked with CKEditor on my .Net Mvc4 project. On localhost all works well, but after publishing project to server is not initialising:
"Uncaught TypeError: Cannot set property 'dir' of undefined"
I fixed this by adding code line before editor initialization:
CKEDITOR.basePath = '//some url/ckeditor/'
After that, the ckeditor is working but refusing to open image upload dialog:
error in ckeditor plugins image.js
Uncaught Error: [CKEDITOR.dialog.openDialog] Dialog "image" failed when loading definition.
There is no any changes in my ckeditor folder. The version is: 4.4.5
Any solutions please?
Check the "Network" tab in your browser for HTTP 404 errors. It looks like the file that contains Image Dialog definition is not available. Either it is not present (e.g. has been accidentally removed) or you have some weird url rewrite issues.
Check in your CKEDITOR.basePath plugins folder image plugin is in there, if not then add it and wala working like a charm ! hope it helps !
Issue
You are getting the error from only including the ckeditor.js (or ckeditor4.js since 4.13) file on server, with this error becoming raised when CKE attempts to load other features such as plugins and languages but cannot find these files in the basepath folder. You can confirm this from the network tab in browser devtools, as CKE attempts to load features, then cannot find them.
Option 1: Link to a CDN Bundle
CKE offers 3 primary bundles (basic, standard, full) which offer a choice between features and page load. More info here.
Option 2: Include Necessary Files
Make the extra files available on your server.
Here's a gulp task which bundles everything from the ckeditor node module folder (excluding the sample).
gulp.task("copy-ckeditor", function () {
// Check and copy languages in config.ckEditorLanguages
var isIncluded = function(path) {
var found = false,
lang = path.split('lang')[1];
if (lang) {
for (var i in config.ckEditorLanguages) {
if (lang.indexOf(config.ckEditorLanguages[i]) != -1) {
found = true;
}
}
}
return found;
},
copyFile = function(stream) {
stream.pipe(gulp.dest(config.buildPath.js + "lib/ckeditor"));
};
return gulp.src([
"node_modules/ckeditor/**/*.*",
"!node_modules/ckeditor/samples",
"!node_modules/ckeditor/samples/**/*"
])
.pipe(foreach(function(stream, file){
if (file.path.indexOf("lang") != -1) {
if (isIncluded(file.path)) {
copyFile(stream);
}
} else {
copyFile(stream);
}
return stream;
}));
});
Option 3: Build and Host Your Own Custom Bundle
If you want to use a single file load, you can use the CKE4 Builder allowing you to customise built-in plugins.

load_plugin_textdomain not working

Hey i'm trying to localize a plugin called Donate Plus ( which locallized technicly).
the plugin came with en_CA and de_DE files, i've tried creating a he_IL file without success.
So i've tried with the de files came with the plugin but didn't work.
I've set the WPLANG in wp-config.php to de_DE yet that dosen't change the code.
this is the setting code :
load_plugin_textdomain( 'dplus', '/wp-content/plugins/donate-plus' );
And i did check that all the string are set to be localized.
Anyone has a clue?
I just was with a similar isue, did you try to rename your files from de_DE.po and de_DE.mo to name-of-plugin-de_DE.mo and name-of-plugin-de_DE.po (changing name-of-plugin with yours, of course)?
dplus-de_DE.mo and dplus-de_DE.po It must work ;)
load_plugin_textdomain takes three parameters.
In your case it would be something like this (assuming the .po and .mo files are located in a subdir called 'languages')
load_plugin_textdomain( 'dplus', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
I checked the source of DonatePlus Plugin and I found that the Plugin is doing localization wrongly.
The load_plugin_textdomain() call is made inside the DonatePlus classes constructor. But it should be present inside the 'init' hook. Trying adding the following code (which is at the of the file) inside the init function.
if( class_exists('DonatePlus') )
$donateplus = new DonatePlus();
Where are all the .po and .mo files stored? Are they inside the /wp-content/plugins/donate-plus folder itself? If not then change the path or move the files.
I had a similar issue where I was loading the translation files with the load_plugin_textdomain function from within a service class using PSR-4. This meant that the dirname( plugin_basename( __FILE__ ) ) string returned the wrong path.
The correct path is the relative path your-plugin/languages (assuming you are loading the translation files from the /languages directory).
Absolute paths such as /var/www/html/wp-content/plugins/my-plugin/languages won't work.
My plugins file structure looks something like this:
- my-plugin
- assets
- languages
- services
- Api
- Base
Translation.php
- ...
Plugin.php
- vendor
- views
composer.json
composer.lock
index.php
my-plugin.php
uninstall.php
Since my Translation service is placed in the /services/Base/ directory, this worked for me:
$root = plugin_basename(dirname(__FILE__, 3));
load_plugin_textdomain( 'my-plugin', false, "$root/languages/");
Also, I used no action hook at all instead of init or plugins_loaded and fired the load_plugin_textdomain function at the beginning of the plugin, since the hooks don't fire early enough for the admin menu and action links to get translated.
Use:
load_textdomain( TEXT_DOMAIN , WP_PLUGIN_DIR .'/'.dirname( plugin_basename( FILE ) ) . '/languages/'. get_locale() .'.mo' );

Resources