some wip

Oleg committed Oct 13, 2011
commit 6920e423c9866a810f046bb5022a51d77b692c05
Showing 5 changed files with 83 additions and 7 deletions
app/assets/javascripts/comfortable_mexican_sofa/application.js +7 -5
@@ @@ -5,6 +5,8 @@
//= require comfortable_mexican_sofa/codemirror/codemirror.js
//= require comfortable_mexican_sofa/elrte/elrte.js
//= require comfortable_mexican_sofa/elrte/elrte.codemirror.js
+ //= require comfortable_mexican_sofa/elrte/elrte.sofa_link.js
+ //= require comfortable_mexican_sofa/elrte/elrte.sofa_image.js
$.CMS = function(){
var current_path = window.location.pathname;
@@ @@ -77,12 +79,12 @@ $.CMS = function(){
},
enable_rich_text: function(){
- elRTE.prototype.options.panels.style_sofa = ['bold', 'italic', 'underline', 'strikethrough'];
- elRTE.prototype.options.panels.format_sofa = ['formatblock'];
- elRTE.prototype.options.panels.copypaste_sofa = ['pasteformattext'];
- elRTE.prototype.options.panels.links_sofa = ['link', 'unlink'];
+ elRTE.prototype.options.panels.sofa_style = ['bold', 'italic', 'underline', 'strikethrough'];
+ elRTE.prototype.options.panels.sofa_format = ['formatblock'];
+ elRTE.prototype.options.panels.sofa_copypaste = ['pasteformattext'];
+ elRTE.prototype.options.panels.sofa_links = ['sofa_link', 'unlink'];
- elRTE.prototype.options.toolbars.sofa = ['undoredo', 'format_sofa', 'style_sofa', 'alignment', 'lists', 'copypaste_sofa', 'links_sofa'];
+ elRTE.prototype.options.toolbars.sofa = ['undoredo', 'sofa_format', 'sofa_style', 'alignment', 'lists', 'sofa_copypaste', 'sofa_links', 'sofa_image'];
$('textarea.rich_text').elrte({
height: 300,
app/assets/javascripts/comfortable_mexican_sofa/elrte/elrte.js +1 -1
@@ @@ -6,7 +6,7 @@ this.error=jQuery('<div class="el-dialogform-error rounded-5" />').hide().append
this.spinner.hide();return this};this.showMessage=function(f,g){this.hideError();this.hideSpinner();this.message.html(f||"").show();g&&this.content.hide();return this};this.hideMessage=function(){this.message.hide();this.content.show();return this};this.tab=function(g,f){g=this.opts.tabPrefix+g;if(!this.ul){this.ul=jQuery("<ul />").prependTo(this.form)}jQuery("<li />").append(jQuery("<a />").attr("href","#"+g).html(f)).appendTo(this.ul);this.tabs[g]={tab:jQuery("<div />").attr("id",g).addClass("tab").appendTo(this.form),table:null};
return this};this.table=function(f){f=f&&f.indexOf(this.opts.tabPrefix)==-1?this.opts.tabPrefix+f:f;if(f&&this.tabs&&this.tabs[f]){this.tabs[f].table=jQuery("<table />").appendTo(this.tabs[f].tab)}else{this._table=jQuery("<table />").appendTo(this.form)}return this};this.append=function(j,k,g){k=k?"el-df-tab-"+k:"";if(!j){return this}if(k&&this.tabs[k]){if(g){!this.tabs[k].table&&this.table(k);var h=jQuery("<tr />").appendTo(this.tabs[k].table);if(!jQuery.isArray(j)){h.append(jQuery("<td />").append(j))
}else{for(var f=0;f<j.length;f++){h.append(jQuery("<td />").append(j[f]))}}}else{if(!jQuery.isArray(j)){this.tabs[k].tab.append(j)}else{for(var f=0;f<j.length;f++){this.tabs[k].tab.append(j[f])}}}}else{if(!g){if(!jQuery.isArray(j)){this.form.append(j)}else{for(var f=0;f<j.length;f++){this.form.append(j[f])}}}else{if(!this._table){this.table()}var h=jQuery("<tr />").appendTo(this._table);if(!jQuery.isArray(j)){h.append(jQuery("<td />").append(j))}else{for(var f=0;f<j.length;f++){h.append(jQuery("<td />").append(j[f]))
- }}}}return this};this.separator=function(f){f="el-df-tab-"+f;if(this.tabs&&this.tabs[f]){this.tabs[f].tab.append(jQuery("<div />").addClass("separator"));this.tabs[f].table&&this.table(f)}else{this.form.append(jQuery("<div />").addClass("separator"))}return this};this.open=function(){var f=this;this.ul&&this.form.tabs(this.opts.tabs);setTimeout(function(){f.dialog.find(":text").keydown(function(g){if(g.keyCode==13){g.preventDefault();f.form.submit()}}).filter(":first")[0].focus()},200);this.dialog.dialog("open");
+ }}}}return this};this.separator=function(f){f="el-df-tab-"+f;if(this.tabs&&this.tabs[f]){this.tabs[f].tab.append(jQuery("<div />").addClass("separator"));this.tabs[f].table&&this.table(f)}else{this.form.append(jQuery("<div />").addClass("separator"))}return this};this.open=function(){var f=this;this.ul&&this.form.tabs(this.opts.tabs);setTimeout(function(){f.dialog.find(":text").keydown(function(g){if(g.keyCode==13){g.preventDefault();f.form.submit()}}).first().focus()},200);this.dialog.dialog("open");
return this};this.close=function(){if(typeof(this.opts.close)=="function"){this.opts.close()}this.dialog.dialog("destroy")}}(function(a){a.fn.elColorPicker=function(h){var b=this;var f=a.extend({},a.fn.elColorPicker.defaults,h);this.hidden=a('<input type="hidden" />').attr("name",f.name).val(f.color||"").appendTo(this);this.palette=null;this.preview=null;this.input=null;function c(j){b.val(j);f.change&&f.change(b.val());b.palette.slideUp()}function g(){b.palette=a("<div />").addClass(f.paletteClass+" rounded-3");
for(var j=0;j<f.colors.length;j++){a("<div />").addClass("color").css("background-color",f.colors[j]).attr({title:f.colors[j],unselectable:"on"}).appendTo(b.palette).mouseenter(function(){var k=a(this).attr("title");b.input.val(k);b.preview.css("background-color",k)}).click(function(k){k.stopPropagation();c(a(this).attr("title"))})}b.input=a('<input type="text" />').addClass("rounded-3").attr("size",8).click(function(k){k.stopPropagation();a(this).focus()}).keydown(function(p){if(p.ctrlKey||p.metaKey){return true
}var o=p.keyCode;if(o==27){return b.mouseleave()}if(o!=8&&o!=13&&o!=46&&o!=37&&o!=39&&(o<48||o>57)&&(o<65||o>70)){return false}var q=a(this).val();if(q.length==7||q.length==0){if(o==13){p.stopPropagation();p.preventDefault();c(q);b.palette.slideUp()}if(p.keyCode!=8&&p.keyCode!=46&&o!=37&&o!=39){return false}}}).keyup(function(k){var o=a(this).val();o.length==7&&/^#[0-9abcdef]{6}$/i.test(o)&&b.val(o)});b.preview=a("<div />").addClass("preview rounded-3").click(function(k){k.stopPropagation();c(b.input.val())
app/assets/javascripts/comfortable_mexican_sofa/elrte/elrte.sofa_image.js +32 -0
@@ @@ -0,0 +1,32 @@
+ (function($){
+
+ elRTE.prototype.ui.prototype.buttons.sofa_image = function(rte, name) {
+ this.constructor.prototype.constructor.call(this, rte, name);
+
+ this.command = function(){
+
+ var cms_dialog = jQuery(jQuery('#cms_dialog').get(0) || jQuery('<div id="cms_dialog"></div>'));
+ cms_dialog.dialog({
+ modal : true,
+ resizable : false,
+ closeOnEscape : true,
+ autoOpen : false
+ });
+
+ jQuery.ajax({
+ url: '/' + $('meta[name="cms-admin-path"]').attr('content') +
+ '/sites/' +
+ $('meta[name="cms-site-id"]').attr('content') +
+ '/dialogs/images'
+ })
+
+ }
+
+ this.update = function(){
+ this.domElem.removeClass('disabled');
+ }
+ }
+ elRTE.prototype.options.buttons.sofa_image = 'Image';
+ elRTE.prototype.options.panels.sofa_image = ['sofa_image'];
+
+ })(jQuery);
\ No newline at end of file
app/assets/javascripts/comfortable_mexican_sofa/elrte/elrte.sofa_link.js +40 -0
@@ @@ -0,0 +1,40 @@
+ (function($){
+ elRTE.prototype.ui.prototype.buttons.sofa_link = function(rte, name){
+ this.constructor.prototype.constructor.call(this, rte, name);
+
+ var self = this;
+
+ this.command = function(){
+ dialog_opts = {
+ rtl : this.rte.rtl,
+ submit: function(e, d) { e.stopPropagation(); e.preventDefault(); self.set(); d.close(); },
+ close : function() {self.rte.browser.msie && self.rte.selection.restoreIERange(); },
+ dialog: {
+ width : 'auto',
+ width : 430,
+ title : this.rte.i18n('Link')
+ }
+ }
+ d = new elDialogForm();
+ d.append('BALHHH');
+ d.open();
+
+ }
+
+ this.update = function(){
+ var n = this.rte.selection.getNode();
+ if (this.rte.dom.selfOrParentLink(n)) {
+ this.domElem.removeClass('disabled').addClass('active');
+ } else if (this.rte.dom.selectionHas(function(n) { return n.nodeName == 'A' && n.href; })) {
+ this.domElem.removeClass('disabled').addClass('active');
+ } else if (!this.rte.selection.collapsed() || n.nodeName == 'IMG') {
+ this.domElem.removeClass('disabled active');
+ } else {
+ this.domElem.addClass('disabled').removeClass('active');
+ }
+ }
+ }
+
+ elRTE.prototype.options.buttons.sofa_link = 'Link';
+
+ })(jQuery)
\ No newline at end of file
app/views/layouts/cms_admin/_head.html.erb +3 -1
@@ @@ -5,7 +5,7 @@
<meta name="cms-admin-path" content="<%= ComfortableMexicanSofa.config.admin_route_prefix %>" />
<meta name="cms-locale" content="<%= I18n.locale %>" />
- <meta name="cms-js-assets-base-path" content="<%= ComfortableMexicanSofa.asset_pipeline_enabled?? '/assets' : '/javascripts' %>/comfortable_mexican_sofa"/>
+ <meta name="cms-site-id" content="<%= @site.try(:id) %>"/>
<% if ComfortableMexicanSofa.asset_pipeline_enabled? %>
@@ @@ -30,6 +30,8 @@
'comfortable_mexican_sofa/codemirror/codemirror',
'comfortable_mexican_sofa/elrte/elrte',
'comfortable_mexican_sofa/elrte/elrte.codemirror',
+ 'comfortable_mexican_sofa/elrte/elrte.sofa_image',
+ 'comfortable_mexican_sofa/elrte/elrte.sofa_link',
'comfortable_mexican_sofa/application' %>
<% end %>