mirror of
https://github.com/claudehohl/Stikked.git
synced 2025-04-25 20:41:20 -05:00
codemirror
This commit is contained in:
parent
8ec606799e
commit
a8a2c631f9
@ -14,6 +14,7 @@
|
||||
* - cron()
|
||||
* - about()
|
||||
* - _valid_lang()
|
||||
* - get_cm_js()
|
||||
* Classes list:
|
||||
* - Main extends CI_Controller
|
||||
*/
|
||||
@ -131,10 +132,25 @@ class Main extends CI_Controller
|
||||
function _form_prep($lang = false, $title = '', $paste = '', $reply = false)
|
||||
{
|
||||
$this->load->model('languages');
|
||||
$this->load->config('codemirror_languages');
|
||||
$this->load->helper('form');
|
||||
$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'))
|
||||
{
|
||||
@ -418,4 +434,20 @@ class Main extends CI_Controller
|
||||
$this->form_validation->set_message('_valid_lang', 'Please select your language');
|
||||
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');
|
||||
|
||||
?>
|
||||
<script type="text/javascript">
|
||||
//<![CDATA[
|
||||
var base_url = '<?php echo base_url(); ?>';
|
||||
//]]>
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="container">
|
||||
|
@ -45,13 +45,9 @@
|
||||
<div class="item">
|
||||
<label for="paste">Your paste
|
||||
<span class="instruction">Paste your paste here</span>
|
||||
<?php
|
||||
if($this->uri->segment(1) == 'view'
|
||||
&& isset($codemirror_languages[$lang_set])
|
||||
&& gettype($codemirror_languages[$lang_set]) == 'array'){
|
||||
?><span class="instruction"><a href="#" id="enable_codemirror">Enable syntax highlighting</a></span><?php
|
||||
}
|
||||
?>
|
||||
<?php if(isset($codemirror_languages[$lang_set]) && gettype($codemirror_languages[$lang_set]) == 'array'){ ?>
|
||||
<span class="instruction"><a href="#" id="enable_codemirror">Enable syntax highlighting</a></span>
|
||||
<?php } ?>
|
||||
</label>
|
||||
|
||||
<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');
|
||||
$this->carabiner->group('codemirror', $codemirror_specific);
|
||||
$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 || {}
|
||||
|
||||
CM.on = false;
|
||||
CM.mode = 'php';
|
||||
|
||||
CM.init = function() {
|
||||
if (CM.on) {
|
||||
CM.editor.toTextArea();
|
||||
CM.on = false;
|
||||
} else {
|
||||
//CM.editor.toTextArea();
|
||||
var lang = $('#lang').val();
|
||||
console.info(lang);
|
||||
if (typeof CM.editor == 'undefined') {
|
||||
CM.editor = CodeMirror.fromTextArea(document.getElementById('code'), {
|
||||
mode: CM.mode,
|
||||
lineNumbers: true,
|
||||
lineWrapping: true,
|
||||
});
|
||||
CM.on = true;
|
||||
}
|
||||
};
|
||||
|
||||
@ -21,12 +18,10 @@ $(document).ready(function() {
|
||||
$enable_codemirror = $('#enable_codemirror');
|
||||
$enable_codemirror.click(function() {
|
||||
CM.init();
|
||||
//$enable_codemirror.remove();
|
||||
$enable_codemirror.remove();
|
||||
return false;
|
||||
});
|
||||
$langselect = $('#lang');
|
||||
$langselect.change(function() {
|
||||
CM.mode = $(this).val();
|
||||
$('#lang').change(function() {
|
||||
CM.init();
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user