-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f5132cc
commit 9796eec
Showing
1 changed file
with
52 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,112 +1,111 @@ | ||
cms.plugins.ace = {}; | ||
|
||
cms.plugins.ace.switchOn_handler = function( textarea_id, params ) | ||
{ | ||
cms.plugins.ace.switchOn_handler = function (textarea_id, params) { | ||
var editor_id = getSlug(textarea_id) + 'Div'; | ||
var textarea = $('#' + textarea_id).hide(); | ||
var height = textarea.data('height') ? textarea.data('height') : 300; | ||
var mode = textarea.data('mode') ? textarea.data('mode') : 'php'; | ||
var editArea = $('<div id="' + getSlug(textarea_id) + 'Div" />') | ||
var editArea = $('<div id="' + editor_id + '" />') | ||
.insertAfter(textarea) | ||
.css({ | ||
height: height, | ||
fontSize: 14 | ||
}); | ||
var editor = ace.edit(getSlug(textarea_id) + 'Div'); | ||
|
||
var editor = ace.edit(editor_id); | ||
editor.setValue(textarea.val()); | ||
|
||
editor.clearSelection(); | ||
editor.getSession().setMode("ace/mode/" + mode); | ||
editor.getSession().setMode("ace/mode/" + mode); | ||
editor.getSession().setTabSize(4); | ||
editor.getSession().setUseSoftTabs(false); | ||
editor.getSession().setUseWrapMode(true); | ||
editor.getSession().on('change', function(){ | ||
editor.getSession().on('change', function () { | ||
textarea.val(editor.getSession().getValue()); | ||
}); | ||
editor.setTheme("ace/theme/textmate"); | ||
|
||
function fullscreen(editArea, editor, height) { | ||
if(!editArea.data('fullscreen') || editArea.data('fullscreen') == 'off') { | ||
if (!editArea.data('fullscreen') || editArea.data('fullscreen') == 'off') { | ||
editArea | ||
.css({ | ||
position: 'fixed', | ||
width: '100%', | ||
height: '100%', | ||
top: 0, left: 0 | ||
}) | ||
.data('fullscreen', 'on') | ||
.css({ | ||
position: 'fixed', | ||
width: '100%', | ||
height: '100%', | ||
top: 0, left: 0 | ||
}) | ||
.data('fullscreen', 'on') | ||
|
||
editor.setTheme("ace/theme/monokai"); | ||
} else { | ||
editor.setTheme("ace/theme/textmate"); | ||
editArea | ||
.data('fullscreen', 'off') | ||
.css({ | ||
position: 'relative', | ||
width: 'auto', | ||
height: height, | ||
top: 'auto', left: 'auto' | ||
}); | ||
.data('fullscreen', 'off') | ||
.css({ | ||
position: 'relative', | ||
width: 'auto', | ||
height: height, | ||
top: 'auto', left: 'auto' | ||
}); | ||
} | ||
} | ||
if(textarea.data('readonly') == 'on') { | ||
|
||
if (textarea.data('readonly') == 'on') { | ||
editor.setReadOnly(true); | ||
} else { | ||
editor.commands.addCommand({ | ||
bindKey: {win: 'Ctrl-S', mac: 'Command-S'}, | ||
exec: function(editor) { | ||
bindKey: {win: 'Ctrl-S', mac: 'Command-S'}, | ||
exec: function (editor) { | ||
$('button[name="continue"]').click(); | ||
} | ||
}); | ||
|
||
editor.commands.addCommand({ | ||
name: 'Full-screen', | ||
bindKey: {win: 'Ctrl-F', mac: 'Command-F'}, | ||
exec: function(editor) { | ||
bindKey: {win: 'Ctrl-F', mac: 'Command-F'}, | ||
exec: function (editor) { | ||
fullscreen(editArea, editor, height) | ||
} | ||
}); | ||
}); | ||
} | ||
|
||
return editor; | ||
}; | ||
|
||
// Switch off tinymce handler | ||
cms.plugins.ace.switchOff_handler = function( editor, textarea_id ) | ||
{ | ||
$('#' + textarea_id + 'Div').remove(); | ||
cms.plugins.ace.switchOff_handler = function (editor, textarea_id){ | ||
$('#' + getSlug(textarea_id) + 'Div').remove(); | ||
} | ||
|
||
cms.plugins.ace.exec_handler = function( editor, command, textarea_id, data ) | ||
{ | ||
switch(command) { | ||
cms.plugins.ace.exec_handler = function (editor, command, textarea_id, data){ | ||
var textarea_id = getSlug(textarea_id); | ||
|
||
switch (command) { | ||
case 'insert': | ||
editor.insert(data); | ||
break; | ||
case 'changeHeight': | ||
$('#' + textarea_id + 'Div') | ||
.css({ | ||
height: data | ||
}); | ||
.css({ | ||
height: data | ||
}); | ||
|
||
editor.resize(); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
$(function(){ | ||
$(function () { | ||
cms.filters | ||
.add( 'ace', cms.plugins.ace.switchOn_handler, cms.plugins.ace.switchOff_handler, cms.plugins.ace.exec_handler ); | ||
.add('ace', cms.plugins.ace.switchOn_handler, cms.plugins.ace.switchOff_handler, cms.plugins.ace.exec_handler); | ||
|
||
if($('#highlight_content').length > 0) | ||
cms.filters.switchOn( 'highlight_content', 'ace' ); | ||
if ($('#highlight_content').length > 0) | ||
cms.filters.switchOn('highlight_content', 'ace'); | ||
}); | ||
|
||
cms.init.add(['layout_edit', 'snippet_edit', 'layout_add', 'snippet_add'], function(){ | ||
$(function(){ | ||
if($('#textarea_content').length > 0) | ||
cms.filters.switchOn( 'textarea_content', 'ace', $('#textarea_content').data()); | ||
cms.init.add(['layout_edit', 'snippet_edit', 'layout_add', 'snippet_add'], function () { | ||
$(function () { | ||
if ($('#textarea_content').length > 0) | ||
cms.filters.switchOn('textarea_content', 'ace', $('#textarea_content').data()); | ||
}); | ||
}) |