I have a need to reduce more javascripts from my site. Smileys is one of the targets. I don't need ui.dialog nor draggable capabilities. So I propose this for you to review and surely improve.
I remove all dependencies for jquery ui and their javascripts.
I edit the smileys.js as below:
// $Id: smileys.js,v 1.1.2.3 2009/01/05 08:50:25 Gurpartap Exp $
/* Filename: smileys.js
* jQuery Smileys Code for Drupal smileys module.
* License: GPL (Read LICENSE.txt for more information).
* Copyright, authors.
*/
// Add more textarea IDs that can parse Smileys.
var textareaIDs = {
"edit-teaser-js": "",
"edit-body": "",
"edit-comment": ""
};
var textareaFocussed = "edit-body";
Drupal.behaviors.smileysAutoAttach = function() {
$('.smileys').after('<span id="toggleSmileys" class="smiley-class">' + Drupal.t('more...') + '</span>');
$("#toggleSmileys").bind("click", function() {
var t = $(this);
var basePath = Drupal.settings.basePath;
t.text('loading...');
$('<div id="smileysContent"></div>').appendTo(".smileys").load(basePath + "smileys/fetch", function() {
Drupal.smileysAttach();
t.remove();
}).css('max-height', 160).show();
});
$("textarea").bind("focus", function() {
var textAreaID = $(this).attr("id");
if (textAreaID in textareaIDs) {
textareaFocussed = textAreaID;
}
});
Drupal.smileysAttach();
};
Drupal.smileysAttach = function() {
$("img.smiley-class:not(.smileysProcessed)").addClass("smileysProcessed")
.bind("click", function() {
var smiley = " " + this.alt + " ";
// edit-body and edit-comment included to insert smiley into them when none of the textarea is focussed.
$("textarea#"+ textareaFocussed +", textarea#edit-comment").each(function() {
if (typeof tinyMCE !== "undefined" && (tinyMCE.getInstanceById("edit-comment") ? true : false || tinyMCE.getInstanceById("edit-body") ? true : false)) {
// tinyMCE support
tinyMCE.execCommand("mceInsertContent", false, smiley);
}
// If you have FCKeditor always enabled, you may uncomment the following code
// For advanced information on issue see: http://drupal.org/node/213679
/*else if (typeof FCKeditorAPI !== "undefined" && fckIsRunning[fckLaunchedJsId]) {
// FCKeditor support
FCKeditorAPI.GetInstance(fckLaunchedJsId).InsertHtml(smiley);
}*/
else {
// Plain textarea support
if (document.selection) {
this.focus();
document.selection.createRange().text = smiley;
}
else if (this.selectionStart || this.selectionStart === 0) {
var cursorPos = this.selectionEnd + smiley.length;
this.value = this.value.substring(0, this.selectionStart) + smiley + this.value.substring(this.selectionEnd);
this.selectionStart = this.selectionEnd = cursorPos;
}
else {
this.value = this.value + smiley;
}
this.focus();
}
});
});
};
To suit my design, I also need the css files as below:
.smileys{position:relative;padding:6px 10px;}
.smiley-class{cursor:pointer;border:0;}
.smiley-content{border:none;}
.smileys span {
float:left;
min-width:26px;
text-align:center;
margin-right:5px;
}
.smileys fieldset {padding:0;border:0;}
#smileysContent{
clear:both;
float:left;
margin:1em 0;
overflow:auto;
width:100%;
max-height:160px;
}
I am sorry that I can't create any patch for this so far. But hopefully is useful to someone who also has a need to reduce more files. I realize that it's bad to edit any module files, that's why I am here to propose, just in case it's any good and so I can take advantage for betterment and more suggestions as well, and ultimately apllied for the next release, and I don't have to worry anymore in the next upgrade :)
The whole idea is simply to attach the more smileys directly after the default visible ones upon request. And hopefully also address the issue here => http://drupal.org/node/590856.
Thanks.
Comments
Comment #1
gausarts commentedThe proposal also hopefully addressed the bandwith problem here => http://drupal.org/node/641160. As you know, all smileys currently are loaded behind scene on every page request. With the above, you only load more smileys if needed. Hope the attachment for better illustration was loaded, but can't due to slow connection, perhaps later.
Thanks