HosipLan

Untitled

Oct 8th, 2012
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * This file is part of the Kdyby (http://www.kdyby.org)
  3.  *
  4.  * Copyright (c) 2008, 2012 Filip Procházka ([email protected])
  5.  *
  6.  * For the full copyright and license information, please view the file license.txt that was distributed with this source code.
  7.  */
  8.  
  9. $(document).ready(function () {
  10.  
  11.     /**
  12.      * @author Filip Procházka <[email protected]>
  13.      */
  14.     $('.kdyby-node-designer').each(function () {
  15.         var designer = $(this);
  16.  
  17.         /**
  18.          * Init CodeMirror on editor textareas
  19.          */
  20.         var editors = designer.find('textarea.code-editor');
  21.         editors.each(function () {
  22.             var editorTextarea = $(this);
  23.             var editor = CodeMirror.fromTextArea(editorTextarea[0], {
  24.                 lineNumbers: true,
  25.                 mode: editorTextarea.data('editor-mode'),
  26.                 indentUnit: 4,
  27.                 indentWithTabs: true,
  28.                 tabMode: "indent"
  29.             });
  30.             editorTextarea.data('code-editor', editor);
  31.         });
  32.  
  33.         /**
  34.          * Fix CodeMirror when changing tabs
  35.          */
  36.         designer.on('click.tab.data-api', '[data-toggle="tab"]', function (e) {
  37.             window.setTimeout(function () {
  38.                 editors.each(function () {
  39.                     var editor = $(this).data('code-editor');
  40.                     if (editor) editor.refresh();
  41.                 });
  42.             }, 100);
  43.         });
  44.  
  45.         /**
  46.          * When CTRL+S is hit inside designer, it tries to find first input:submit with primary class
  47.          * and send a form with it, otherwise just finds the first button and submits with it.
  48.          */
  49.         designer.on('keydown', '*', function (e) {
  50.             if (!e.altKey && !e.metaKey && e.ctrlKey && e.which === 83) {
  51.                 var form = $(e.target).closest('form');
  52.                 var firstSubmit = form.find('.nav-actions input.btn-primary:submit');
  53.  
  54.                 if (!firstSubmit.length) {
  55.                     firstSubmit = form.find('.nav-actions input:submit:first');
  56.                 }
  57.  
  58.                 $.nette.ajax({
  59.                     cache: false
  60.                 }, firstSubmit[0], e);
  61.             }
  62.         });
  63.  
  64.         /**
  65.          * When in addComponent wizard user clicks on socket, submit form.
  66.          */
  67.         designer.find('.kdyby-choose-container').on('click', 'input:radio', function () {
  68.             designer.find('.nav-actions input[name*=continue]').click();
  69.         });
  70.     });
  71.  
  72. });
Advertisement
Add Comment
Please, Sign In to add comment