+ var block_style_popup = null;
+ function block_style() {
+ var action = $(this).data('action');
+ var class_name = null;
+ if (action == 'code') {
+ action = 'pre';
+ class_name = 'screen';
+ }
+ document.execCommand('formatBlock', false, action);
+ var sel = window.getSelection();
+ if (class_name) {
+ $(sel.anchorNode).addClass(class_name);
+ }
+ var range = document.createRange();
+ range.setStart(sel.anchorNode, 0);
+ sel.removeAllRanges();
+ sel.addRange(range);
+ hide_block_style_popup();
+ }
+ function show_block_style_popup() {
+ if (block_style_popup === null) {
+ block_style_popup = $(
+ '<div class="style-popup">' +
+ '<button data-action="code">code</button>' +
+ '</div>');
+ block_style_popup.hide();
+ block_style_popup.insertAfter($('.actions'));
+ block_style_popup.find('button').on('click', block_style);
+ }
+ block_style_popup.css('position', 'absolute');
+ var sel = window.getSelection();
+ var pos = $(sel.anchorNode).offset();
+ block_style_popup.css('top', pos.top - 33);
+ block_style_popup.css('left', pos.left);
+ block_style_popup.show();
+ }
+ function hide_block_style_popup() {
+ if (block_style_popup) {
+ $(block_style_popup).hide();
+ }
+ }
+