From e78fda72979675ca52847ed82f5b3c9a9e9a5053 Mon Sep 17 00:00:00 2001 From: sanj Date: Mon, 15 Mar 2010 01:29:35 +0530 Subject: [PATCH] merged arabic textbox code --- edgware/files/admin.py | 10 ++++ edgware/settings.py | 2 +- edgware/static/css/editor.css | 49 +++++++++++----- edgware/static/css/fonts.css | 25 ++++++++ edgware/static/js/editor.js | 107 ++++++++++++++++++++-------------- edgware/templates/editor.html | 12 +++- requirements.txt | 1 + 7 files changed, 143 insertions(+), 63 deletions(-) create mode 100644 edgware/static/css/fonts.css diff --git a/edgware/files/admin.py b/edgware/files/admin.py index 26f4a70..65c83b3 100755 --- a/edgware/files/admin.py +++ b/edgware/files/admin.py @@ -1,6 +1,15 @@ from files.models import File, Category, Type from django.contrib import admin from django.contrib.auth.models import User +from django_firefogg.forms import FirefoggInput +from django import forms + +class filesForm(forms.ModelForm): + file = forms.FileField(label='Upload File', + required=False, + widget=FirefoggInput({'passthrough': True})) + class Meta: + model = File class FilesAdmin(admin.ModelAdmin): list_display = ('title', 'type', 'file_date') @@ -8,6 +17,7 @@ class FilesAdmin(admin.ModelAdmin): ordering = ('-file_date',) search_fields = ('title', 'description') exclude = ('userID',) + form = filesForm def save_model(self, request, obj, form, change): if not change: diff --git a/edgware/settings.py b/edgware/settings.py index da834d5..8feae7c 100644 --- a/edgware/settings.py +++ b/edgware/settings.py @@ -101,7 +101,7 @@ INSTALLED_APPS = ( # 'south', 'django.contrib.comments', 'sorl.thumbnail', - 'firefogg', + 'django_firefogg', ) #overwrite default settings with local settings diff --git a/edgware/static/css/editor.css b/edgware/static/css/editor.css index 589fd8a..17e3d0c 100644 --- a/edgware/static/css/editor.css +++ b/edgware/static/css/editor.css @@ -1,5 +1,5 @@ #ajaxBusy { - position: absolute; + position: fixed; top: 10px; right: 10px; width: 6px; @@ -24,6 +24,21 @@ margin-bottom:80px; } +.newTextBox { + background-color:grey; + padding-top:10px; + border-style:solid; + border-width:1px; + height:13px; + width:140px; + font-size: 11px; + cursor: move; + } + +.arabic { + direction: rtl; + } + .ruler_horiz { position: relative; top: 50%; @@ -117,13 +132,25 @@ width: 16px; } + +.navControls { + background-color:lightgrey; + padding-top:10px; + padding-bottom:10px; + padding-left:10px; + padding-right:10px; + border-bottom-style:solid; + border-bottom-width:1px; + font-size:13px; + margin-left: -10px; +} + #bin { border-style:solid; border-width:1px; - position: absolute; - left: 900px; + left: 850px; top: 20px; - width: 250px; + width: 300px; height: 90%; position:fixed; @@ -136,9 +163,11 @@ position: absolute; } + #searchCat { background-color:lightgrey; - padding-left:30px; + margin-left: auto; + margin-right: auto; padding-top:10px; height:30px; } @@ -251,16 +280,6 @@ margin-top:0px; font-size:13px; } -.navControls { - background-color:lightgrey; - padding-top:10px; - padding-bottom:10px; - padding-left:10px; - padding-right:10px; - border-bottom-style:solid; - border-bottom-width:1px; - font-size:13px; -} .searchBin { margin-top:5px; diff --git a/edgware/static/css/fonts.css b/edgware/static/css/fonts.css new file mode 100644 index 0000000..c8a0d43 --- /dev/null +++ b/edgware/static/css/fonts.css @@ -0,0 +1,25 @@ +@font-face { + font-family: GraublauWeb; + src: url(/static/fonts/GraublauWeb.otf) format("opentype"); +} + +@font-face { + font-family: Tallys; + src: url(/static/fonts/Tallys_15.otf) format("opentype"); +} + +@font-face { + font-family: Fontin; + src: url(/static/fonts/Fontin-Regular.otf) format("opentype"); +} + + +@font-face { + font-family: Tagesschrift; + src: url(/static/fonts/YanoneTagesschrift.ttf) format("truetype"); +} + +body { + font-size: 14px; + } + diff --git a/edgware/static/js/editor.js b/edgware/static/js/editor.js index d245782..f420525 100644 --- a/edgware/static/js/editor.js +++ b/edgware/static/js/editor.js @@ -93,7 +93,7 @@ function handleRevision(json) { default: var box = canvas.getBox(json); if (json.prop == 'html') { - box.jq.html(json.new_val); + box.jq.find('.textbox_canvas_content').html(json.new_val); } else { var d = {}; var noPxArr = ['opacity', 'z-index', 'background', 'border-color', 'border-style']; @@ -132,7 +132,7 @@ $(document).ready(function() { }); */ - + $('.newTextBox').tooltip(); $('#newPage').click(function(e) { e.preventDefault(); @@ -249,7 +249,7 @@ Canvas.prototype.init = function() { containment: 'parent', axis: 'y' }); - this.jq.droppable({accept:'.resource, #newTextBox', + this.jq.droppable({accept:'.resource, .newTextBox', drop: function(ev, ui) { var box = $(this).getBox().jq; c = edgeArticle[$(this).attr('data-index')]; @@ -288,13 +288,17 @@ Canvas.prototype.init = function() { } } - else { + var elem = $(ui.draggable); top = $(this).position().top; left = $(this).position().left; - t = new TextBox(c); - width = parseInt(t.jq.css('width')) / 2; - height = parseInt(t.jq.css('height')) / 2; + if (elem.hasClass('arabic')) { + t = new TextBox(c, {'html': '

انقر على مربع التحرير

', 'css': {'direction': 'rtl'}}); + } else { + t = new TextBox(c); + } + width = parseInt(t.jq.css('width') / 2); + height = parseInt(t.jq.css('height') / 2); t.setCSS({'top':toPx((ev.pageY - top) - height), 'left': toPx((ev.pageX - left) - width)}); highest_index = getHighestIndex(c.jq); new_index = parseInt(highest_index) + 1; @@ -431,6 +435,7 @@ TextBox.prototype.create = function(json) { 'html': '

Click to edit textbox

', 'resource_id': 0, 'css': { + 'direction': 'ltr', 'height': '300px', 'width': '300px', 'background-color': '#ffffff', @@ -561,6 +566,12 @@ Call this from the outside to update CSS both client and server-side. css can be */ TextBox.prototype.setCSS = function(css, callServer) { +/* for (var c in css) { + if (css.hasOwnProperty(c)) { + this.css[c] = css[c]; + } + } +*/ this.jq.css(css); var srv = callServer == undefined ? true : callServer; if (srv) { @@ -963,7 +974,7 @@ var Resource = function(json, index) { Resource.prototype.addToBin = function() { var that = this; var e = this.getBinElem(); - edgeBin.jq.append(e); + edgeBin.jq.find('.binResources').append(e); this.jq = $('#' + that.divid); this.addEventHandlers(); }; @@ -1090,7 +1101,7 @@ window.onload = function() }; */ $(document).ready(function(){ - $("#newTextBox").draggable({ revert: true, helper: 'clone'}); + $(".newTextBox").draggable({ revert: true, helper: 'clone'}); }); /* @@ -1230,6 +1241,10 @@ $(".box").live("click", function(e){ $(".properties").css('left', toPx((e.pageX))); } else { $(".properties").remove(); + //BAD HACK: removes the nudge binder if present. Got to be a better way to do this -- potentially bind to document using a custom nudge event, but not sure. + $(document).unbind("keydown"); + //This should click itself, to then display properties wherever it is clicked, but it does not work:( +// $(this).trigger("click"); } // i.setCSS({'top':toPx((ev.pageY - top) - height), 'left': toPx((ev.pageX - left) - width)}); @@ -1364,20 +1379,20 @@ $(".box").live("click", function(e){ $(".crop_imagebox").bind("click", function(e){ e.preventDefault(); text_edit_mode = true; - box.resizable( 'disable' ); + box.resizable( 'disable' ); $(canvas).append(tmpl('tmpl_imagebox_crop', {})); - canvas_top = parseInt(canvas.offset().top); - canvas_left = parseInt(canvas.offset().left); + canvas_top = parseInt(canvas.offset().top); + canvas_left = parseInt(canvas.offset().left); box_top = box.css('top'); box_left = box.css('left'); crop_box_top = parseInt(box_top) + parseInt(box.css('height')) + 5; crop_box_left = parseInt(box_left); - $(".imagebox_crop").css('top', crop_box_top); - $(".imagebox_crop").css('left', crop_box_left); + $(".imagebox_crop").css('top', crop_box_top); + $(".imagebox_crop").css('left', crop_box_left); image = box.find('.edgeImage'); this_imagebox_id = box.attr('data-id'); @@ -1386,7 +1401,7 @@ $(".box").live("click", function(e){ }); $('.properties').remove(); - $(".do_crop_imagebox").bind("click", function(e){ + $(".do_crop_imagebox").bind("click", function(e){ e.preventDefault(); box.resizable( 'enable' ); @@ -1411,22 +1426,21 @@ $(".box").live("click", function(e){ }); $(".cancel_crop_imagebox").bind("click", function(e){ - jcrop.destroy(); - $('.imagebox_crop').remove(); - box.resizable( 'enable' ); + jcrop.destroy(); + $('.imagebox_crop').remove(); + box.resizable( 'enable' ); - text_edit_mode = false; + text_edit_mode = false; }); - - }); + $(".nudge_box").bind("click", function(e){ e.preventDefault(); - $(document).keydown( function (event) { + $(document).bind("keydown", function(event) { // console.log(event.keyCode); if (event.keyCode == '38') { - event.preventDefault(); + event.preventDefault(); top = box.css('top'); if (parseInt(top) > 1) { boxObj.setCSS({'top': toPx(parseInt(top) - 1)}); @@ -1434,40 +1448,40 @@ $(".box").live("click", function(e){ } } if (event.keyCode == '40') { - event.preventDefault(); + event.preventDefault(); top = box.css('top'); - height = box.outerHeight(); - lower_edge = parseInt(top) + parseInt(height); - canvas_height = canvas.css('height'); - console.log('canvas_height:' + canvas_height); - console.log('box lower:' + lower_edge); + height = box.outerHeight(); + lower_edge = parseInt(top) + parseInt(height); + canvas_height = canvas.css('height'); + console.log('canvas_height:' + canvas_height); + console.log('box lower:' + lower_edge); if (lower_edge < parseInt(canvas_height)) { boxObj.setCSS({'top': toPx(parseInt(top) + 1)}); // console.log('down?'); - } + } } if (event.keyCode == '39') { - event.preventDefault(); + event.preventDefault(); left = box.css('left'); - width = box.outerWidth(); - right_edge = parseInt(left) + parseInt(width); - canvas_width = canvas.css('width'); + width = box.outerWidth(); + right_edge = parseInt(left) + parseInt(width); + canvas_width = canvas.css('width'); if (right_edge < parseInt(canvas_width)) { boxObj.setCSS({'left': toPx(parseInt(left) + 1)}); - } - } + } + } if (event.keyCode == '37') { - event.preventDefault(); + event.preventDefault(); left = box.css('left'); if (parseInt(left) > 0) { boxObj.setCSS({'left': toPx(parseInt(left) - 1)}); - } - } - + } + } }); + }); + - }); $(".edit_textbox").bind("click", function(e){ e.preventDefault(); @@ -1477,9 +1491,14 @@ $(".box").live("click", function(e){ box.css('z-index', '1000'); element = box.find('.textbox_canvas_content'); replaceDiv( element[0] ); - box = $(element).getBox().jq; - box.draggable( 'disable' ); - box.resizable( 'disable' ); + boxObj = $(element).getBox(); +// console.log(boxObj); + box = boxObj.jq; + if (box.css("direction") == 'rtl') { + setTimeout(function() { $($('iframe').get(0).contentDocument).find('html').attr("dir", "rtl") }, 500); + } + box.draggable('disable'); + box.resizable('disable'); text_edit_mode = true; $(element).parent().siblings('.save_text').show(); }); diff --git a/edgware/templates/editor.html b/edgware/templates/editor.html index 0b1841e..bce82fb 100644 --- a/edgware/templates/editor.html +++ b/edgware/templates/editor.html @@ -4,6 +4,7 @@ + @@ -190,16 +191,21 @@
-
- + TEXTBOX +
+ + TEXTBOX
-
+
+ إضافة مربع +
+
+
diff --git a/requirements.txt b/requirements.txt index f6a9c9f..b0737b6 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,6 +2,7 @@ -e bzr+http://code.0xdb.org/python-oxdjango/#egg=python-oxdjango -e svn+http://django-tagging.googlecode.com/svn/trunk/#egg=tagging -e bzr+http://firefogg.org/dev/python-firefogg/#egg=python-firefogg +-e bzr+http://firefogg.org/dev/django_firefogg/#egg=django_firefogg django_extensions django-debug-toolbar sorl-thumbnail