+
+function html(element) {
+ var element = $(element);
+
+ function selectTheme(themeId)
+ {
+ var selection = window.getSelection();
+
+ // remove current selection
+ selection.removeAllRanges();
+
+ var range = document.createRange();
+ var s = $(".motyw[theme-class='"+themeId+"']")[0];
+ var e = $(".end[theme-class='"+themeId+"']")[0];
+
+ if(s && e) {
+ range.setStartAfter(s);
+ range.setEndBefore(e);
+ selection.addRange(range);
+ }
+ };
+
+ // function openForEdit($origin)
+ // {
+ // // if(this.currentOpen && this.currentOpen != $origin) {
+ // // this.closeWithSave(this.currentOpen);
+ // // }
+ //
+ // var $box = null
+ //
+ // // annotations overlay their sub box - not their own box //
+ // if($origin.is(".annotation-inline-box"))
+ // $box = $("*[x-annotation-box]", $origin);
+ // else
+ // $box = $origin;
+ //
+ // var x = $box[0].offsetLeft;
+ // var y = $box[0].offsetTop;
+ // var w = $box.outerWidth();
+ // var h = $box.innerHeight();
+ //
+ // console.log("Edit origin:", $origin, " box:", $box);
+ // console.log("offsetParent:", $box[0].offsetParent);
+ // console.log("Dimensions: ", x, y, w , h);
+ //
+ // // start edition on this node
+ // var $overlay = $('<div class="html-editarea"><textarea></textarea></div>');
+ //
+ // h = Math.max(h - 20, 2*parseInt($box.css('line-height')));
+ //
+ // console.log(h);
+ //
+ // $overlay.css({
+ // position: 'absolute',
+ // height: h,
+ // left: x,
+ // top: y,
+ // right: 0
+ // });
+ //
+ // $($box[0].offsetParent).append($overlay);
+ // console.log($overlay);
+ // }
+ //
+ // $('.edit-button').live('click', function() {
+ // openForEdit($(this).parent());
+ // });
+ //
+ var button = $('<button class="edit-button">Edytuj</button>');
+ $(element).bind('mousemove', function(event) {
+ var editable = $(event.target).closest('*[x-editable]');
+ $('.active[x-editable]', element).not(editable).removeClass('active').children('.edit-button').remove();
+ if (!editable.hasClass('active')) {
+ editable.addClass('active').append(button);
+ }
+ });
+
+ $('.motyw').live('click', function() {
+ selectTheme($(this).attr('theme-class'));
+ });
+}
+
+