Tokens expand when holding CTRL and double clicking (Yay!)

This commit is contained in:
Sam Georges 2014-08-30 16:21:16 +10:00
parent 357475c992
commit 8c07bfea15
2 changed files with 25 additions and 9 deletions

View File

@ -439,7 +439,8 @@
function addTokenExpanderToEditor(pane, $form) {
var group = $('[data-field-name=markup]', pane),
editor = $('[data-control=codeeditor]', group),
toolbar = editor.codeEditor('getToolbar')
toolbar = editor.codeEditor('getToolbar'),
canExpand = false
if (editor.data('oc.tokenexpander'))
return
@ -453,19 +454,34 @@
)
breakButton.hide().on('click', function(){
editor.tokenExpander('expandToken', function(token, value){
return $form.request('onExpandMarkupToken', {
data: { tokenType: token, tokenName: value }
})
})
handleExpandToken(editor, $form)
return false
})
$('ul:first', toolbar).prepend(breakButton)
editor
.on('show.oc.tokenexpander', function(){ breakButton.show() })
.on('hide.oc.tokenexpander', function(){ breakButton.hide() })
.on('show.oc.tokenexpander', function(){
canExpand = true
breakButton.show()
})
.on('hide.oc.tokenexpander', function(){
canExpand = false
breakButton.hide()
})
.on('dblclick', function(e){
if ((e.metaKey || e.ctrlKey) && canExpand) {
handleExpandToken(editor, $form)
}
})
}
function handleExpandToken(editor, $form) {
editor.tokenExpander('expandToken', function(token, value){
return $form.request('onExpandMarkupToken', {
data: { tokenType: token, tokenName: value }
})
})
}
function handleMtimeMismatch(form) {

View File

@ -276,7 +276,7 @@ class Index extends Controller
if (!$alias = post('tokenName'))
throw new ApplicationException(trans('cms::lang.component.no_records'));
// Can only break apart components at this stage
// Can only expand components at this stage
if ((!$type = post('tokenType')) && $type != 'component')
return;