mirror of
https://github.com/claudehohl/Stikked.git
synced 2025-04-26 04:51:08 -05:00
codemirror
This commit is contained in:
parent
8ec606799e
commit
a8a2c631f9
@ -14,6 +14,7 @@
|
|||||||
* - cron()
|
* - cron()
|
||||||
* - about()
|
* - about()
|
||||||
* - _valid_lang()
|
* - _valid_lang()
|
||||||
|
* - get_cm_js()
|
||||||
* Classes list:
|
* Classes list:
|
||||||
* - Main extends CI_Controller
|
* - Main extends CI_Controller
|
||||||
*/
|
*/
|
||||||
@ -131,10 +132,25 @@ class Main extends CI_Controller
|
|||||||
function _form_prep($lang = false, $title = '', $paste = '', $reply = false)
|
function _form_prep($lang = false, $title = '', $paste = '', $reply = false)
|
||||||
{
|
{
|
||||||
$this->load->model('languages');
|
$this->load->model('languages');
|
||||||
$this->load->config('codemirror_languages');
|
|
||||||
$this->load->helper('form');
|
$this->load->helper('form');
|
||||||
$data['languages'] = $this->languages->get_languages();
|
$data['languages'] = $this->languages->get_languages();
|
||||||
$data['codemirror_languages'] = $this->config->item('codemirror_languages');
|
|
||||||
|
//codemirror languages
|
||||||
|
$this->load->config('codemirror_languages');
|
||||||
|
$codemirror_languages = $this->config->item('codemirror_languages');
|
||||||
|
$data['codemirror_languages'] = $codemirror_languages;
|
||||||
|
|
||||||
|
//codemirror modes
|
||||||
|
$cmm = array();
|
||||||
|
foreach ($codemirror_languages as $l)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (gettype($l) == 'array')
|
||||||
|
{
|
||||||
|
$cmm[] = $l['mode'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$data['codemirror_modes'] = $cmm;
|
||||||
|
|
||||||
if (!$this->input->post('submit'))
|
if (!$this->input->post('submit'))
|
||||||
{
|
{
|
||||||
@ -418,4 +434,20 @@ class Main extends CI_Controller
|
|||||||
$this->form_validation->set_message('_valid_lang', 'Please select your language');
|
$this->form_validation->set_message('_valid_lang', 'Please select your language');
|
||||||
return $this->languages->valid_language($lang);
|
return $this->languages->valid_language($lang);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function get_cm_js()
|
||||||
|
{
|
||||||
|
$lang = $this->uri->segment(3);
|
||||||
|
$this->load->config('codemirror_languages');
|
||||||
|
$cml = $this->config->item('codemirror_languages');
|
||||||
|
|
||||||
|
if (isset($cml[$lang]) && gettype($cml[$lang]) == 'array')
|
||||||
|
{
|
||||||
|
header('Content-Type: application/x-javascript; charset=utf-8');
|
||||||
|
foreach ($cml[$lang]['js'] as $js)
|
||||||
|
{
|
||||||
|
echo file_get_contents('./static/js/' . $js[0]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,6 +34,11 @@ $this->carabiner->css('diff.css');
|
|||||||
$this->carabiner->display('css');
|
$this->carabiner->display('css');
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
<script type="text/javascript">
|
||||||
|
//<![CDATA[
|
||||||
|
var base_url = '<?php echo base_url(); ?>';
|
||||||
|
//]]>
|
||||||
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="container">
|
<div id="container">
|
||||||
|
@ -45,13 +45,9 @@
|
|||||||
<div class="item">
|
<div class="item">
|
||||||
<label for="paste">Your paste
|
<label for="paste">Your paste
|
||||||
<span class="instruction">Paste your paste here</span>
|
<span class="instruction">Paste your paste here</span>
|
||||||
<?php
|
<?php if(isset($codemirror_languages[$lang_set]) && gettype($codemirror_languages[$lang_set]) == 'array'){ ?>
|
||||||
if($this->uri->segment(1) == 'view'
|
<span class="instruction"><a href="#" id="enable_codemirror">Enable syntax highlighting</a></span>
|
||||||
&& isset($codemirror_languages[$lang_set])
|
<?php } ?>
|
||||||
&& gettype($codemirror_languages[$lang_set]) == 'array'){
|
|
||||||
?><span class="instruction"><a href="#" id="enable_codemirror">Enable syntax highlighting</a></span><?php
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<textarea id="code" name="code" cols="40" rows="20" tabindex="4"><?php if(isset($paste_set)){ echo $paste_set; }?></textarea>
|
<textarea id="code" name="code" cols="40" rows="20" tabindex="4"><?php if(isset($paste_set)){ echo $paste_set; }?></textarea>
|
||||||
|
@ -18,7 +18,9 @@ if(isset($codemirror_languages[$lang_set]) && gettype($codemirror_languages[$lan
|
|||||||
$codemirror_specific['js'][] = array('codemirror_exec.js');
|
$codemirror_specific['js'][] = array('codemirror_exec.js');
|
||||||
$this->carabiner->group('codemirror', $codemirror_specific);
|
$this->carabiner->group('codemirror', $codemirror_specific);
|
||||||
$this->carabiner->display('codemirror');
|
$this->carabiner->display('codemirror');
|
||||||
echo '<div style="display: none;" id="codemirror_mode">' . $codemirror_languages[$lang_set]['mode'] . '</div>';
|
|
||||||
|
//codemirror modes
|
||||||
|
echo '<div style="display: none;" id="codemirror_modes">' . json_encode($codemirror_modes) . '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
@ -1,19 +1,16 @@
|
|||||||
var CM = window.CM || {}
|
var CM = window.CM || {}
|
||||||
|
|
||||||
CM.on = false;
|
|
||||||
CM.mode = 'php';
|
|
||||||
|
|
||||||
CM.init = function() {
|
CM.init = function() {
|
||||||
if (CM.on) {
|
//CM.editor.toTextArea();
|
||||||
CM.editor.toTextArea();
|
var lang = $('#lang').val();
|
||||||
CM.on = false;
|
console.info(lang);
|
||||||
} else {
|
if (typeof CM.editor == 'undefined') {
|
||||||
CM.editor = CodeMirror.fromTextArea(document.getElementById('code'), {
|
CM.editor = CodeMirror.fromTextArea(document.getElementById('code'), {
|
||||||
mode: CM.mode,
|
mode: CM.mode,
|
||||||
lineNumbers: true,
|
lineNumbers: true,
|
||||||
lineWrapping: true,
|
lineWrapping: true,
|
||||||
});
|
});
|
||||||
CM.on = true;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -21,12 +18,10 @@ $(document).ready(function() {
|
|||||||
$enable_codemirror = $('#enable_codemirror');
|
$enable_codemirror = $('#enable_codemirror');
|
||||||
$enable_codemirror.click(function() {
|
$enable_codemirror.click(function() {
|
||||||
CM.init();
|
CM.init();
|
||||||
//$enable_codemirror.remove();
|
$enable_codemirror.remove();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
$langselect = $('#lang');
|
$('#lang').change(function() {
|
||||||
$langselect.change(function() {
|
|
||||||
CM.mode = $(this).val();
|
|
||||||
CM.init();
|
CM.init();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user