added an almost usuable editor
This commit is contained in:
7
public/js/bootstrap.min.js
vendored
Normal file
7
public/js/bootstrap.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
138
public/js/editor.js
Normal file
138
public/js/editor.js
Normal file
@@ -0,0 +1,138 @@
|
||||
jQuery(function($){
|
||||
|
||||
var max_delay = 3000; // longest update pause (in ms)
|
||||
var processing_time = 0;
|
||||
var last = null;
|
||||
var help_text = '';
|
||||
|
||||
var tx_input = $('#tx_input');
|
||||
var input = tx_input[0];
|
||||
input.value = input.innerHTML;
|
||||
tx_input.val(input.value)
|
||||
var text_preview = $('#text_preview')[0];
|
||||
var html_output = $('#html_output')[0];
|
||||
|
||||
|
||||
function convert_text ( newval ) {
|
||||
|
||||
// make sure we're getting a string here because we want to
|
||||
// be able to pass this function to setTimeout (passes number)
|
||||
if ( arguments.length === 1 && typeof newval === 'string' ) {
|
||||
input.value = newval;
|
||||
}
|
||||
|
||||
var text = tx_input.val();
|
||||
|
||||
if ( text && text == last ) { return; } // no action needed
|
||||
last = text;
|
||||
|
||||
var startTime = new Date() * 1;
|
||||
var html = textile.convert( text );
|
||||
var endTime = new Date() * 1;
|
||||
processing_time = endTime - startTime;
|
||||
|
||||
text_preview.innerHTML = html;
|
||||
//html_output.value = html;
|
||||
|
||||
// save last output text to storage if we have it
|
||||
if ( supports_html5_storage() ) {
|
||||
if ( !input.value || input.value == help_text ) {
|
||||
localStorage.removeItem( "textile-dingus" );
|
||||
}
|
||||
else {
|
||||
localStorage.setItem( "textile-dingus", input.value );
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
var supports_html5_storage = function () {
|
||||
var r = false;
|
||||
try { r = 'localStorage' in window && window['localStorage'] !== null; } catch (e) { r = false; }
|
||||
supports_html5_storage = r ? function () { return true; } : function () { return false; };
|
||||
return r;
|
||||
};
|
||||
|
||||
function sync_panels () {
|
||||
var col = $('#col_left');
|
||||
var md = $('#tx_input');
|
||||
var tally = $('body > h1').outerHeight();
|
||||
col.children().each(function(){ tally += $(this).outerHeight(); });
|
||||
var space = col.height() - ( tally - md.outerHeight() );
|
||||
$('#tx_input, #text_preview, #html_output, #syntax_guide').height( space - 4 );
|
||||
}
|
||||
|
||||
|
||||
var convertTextTimer;
|
||||
function on_input ( e ) {
|
||||
clearTimeout( convertTextTimer );
|
||||
defer_time = Math.min( processing_time, max_delay );
|
||||
convertTextTimer = setTimeout( convert_text, defer_time );
|
||||
}
|
||||
|
||||
|
||||
$( '.tab' ).minitabs();
|
||||
|
||||
|
||||
// load syntax guide
|
||||
/* $.get('syntax.txt', function ( txt ) {
|
||||
$( '#syntax_guide' ).val( txt );
|
||||
});
|
||||
*/
|
||||
|
||||
$( window ).bind( 'resize', sync_panels ).trigger( 'resize' );
|
||||
|
||||
$( '#tx_input' ).bind( 'keyup', on_input ).focus();
|
||||
|
||||
|
||||
// app saves and loads from local storage
|
||||
/* if ( supports_html5_storage() ) {
|
||||
var prev = localStorage.getItem( 'textile-dingus' ) || '';
|
||||
// id form holds default text or is empty, load from localStorage
|
||||
if ( prev && !input.value || input.value == input.defaultValue ) {
|
||||
input.value = prev;
|
||||
}
|
||||
}
|
||||
*/
|
||||
console.log(input.value)
|
||||
console.log(input)
|
||||
if ( !input.value ) {
|
||||
$.get('help.txt', function ( txt ) {
|
||||
convert_text( (help_text = txt) );
|
||||
});
|
||||
}
|
||||
else {
|
||||
convert_text();
|
||||
}
|
||||
|
||||
|
||||
// enable loading desktop files
|
||||
|
||||
if ( typeof window.FileReader !== 'undefined' ) {
|
||||
tx_input.bind('dragover', function (e) {
|
||||
$( this ).addClass('drophover');
|
||||
e.preventDefault();
|
||||
});
|
||||
tx_input.bind('dragleave dragend drop', function (e) { $( this ).removeClass('drophover'); });
|
||||
tx_input.bind('drop', function (e) {
|
||||
var file = e.originalEvent.dataTransfer.files[0];
|
||||
var reader = new FileReader();
|
||||
reader.onload = function ( event ) {
|
||||
convert_text( event.target.result );
|
||||
};
|
||||
reader.readAsText( file );
|
||||
e.preventDefault();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
$( 'html' ).delegate( 'button.clear,a.clear', 'click', function (e) {
|
||||
convert_text( '' );
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
4
public/js/jquery.min.js
vendored
Normal file
4
public/js/jquery.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
69
public/js/jquery.minitabs.js
Normal file
69
public/js/jquery.minitabs.js
Normal file
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* jQuery minitabs plugin
|
||||
* Version 1.0
|
||||
*
|
||||
* Licenced under dual MIT/GPL license.
|
||||
* GPL: http://www.opensource.org/licenses/gpl-2.0.php
|
||||
* MIT: http://www.opensource.org/licenses/mit-license.php
|
||||
*
|
||||
*/
|
||||
(function($){
|
||||
|
||||
var _defaultConfig = {
|
||||
open: 'tab-open',
|
||||
closed: 'tab-closed',
|
||||
current: 'current',
|
||||
active: 'tabs-active',
|
||||
panel: 'tab-panel'
|
||||
};
|
||||
|
||||
function getRef ( a ) {
|
||||
return $.attr( a, 'href' ).replace( /^[^#]+/, '' );
|
||||
}
|
||||
|
||||
function switchTabs ( link, c ) {
|
||||
var nav = $( link ).closest( '.' + c.active ),
|
||||
id = getRef( link );
|
||||
if ( id && id !== c.current_id ) {
|
||||
nav.trigger( 'tabswitch', [ link, id ] );
|
||||
|
||||
// find currenly active and close it
|
||||
if ( c.current_id ) {
|
||||
var cid = c.current_id;
|
||||
$( cid ).trigger( 'tabclose' ).removeClass( c.open ).addClass( c.closed );
|
||||
nav.find( 'li:has(a[href$=' + cid + '])' ).removeClass( c.current );
|
||||
}
|
||||
|
||||
// find the desired panel and open it
|
||||
$( id ).removeClass( c.closed ).addClass( c.open ).trigger( 'tabopen' );
|
||||
$( link ).closest('li').addClass( c.current );
|
||||
|
||||
c.current_id = id;
|
||||
}
|
||||
}
|
||||
|
||||
$.fn.minitabs = function ( cfg ) {
|
||||
var conf = $.extend( {}, _defaultConfig, cfg );
|
||||
return this.each(function () {
|
||||
|
||||
var current = null;
|
||||
var links = $( 'a', this ).each(function ( i ) {
|
||||
$( getRef( this ) ).addClass( conf.panel + ' ' + conf.closed );
|
||||
if ( $( this ).closest( 'li' ).is( '.' + conf.current ) ) { current = this; }
|
||||
});
|
||||
|
||||
var tab = $( this )
|
||||
.addClass( conf.active )
|
||||
.data( 'tab.config', conf )
|
||||
.undelegate( 'a', 'click.minitabs' )
|
||||
.delegate( 'a', 'click.minitabs', function (e) {
|
||||
switchTabs( this, $.data( e.delegateTarget, 'tab.config' ) );
|
||||
e.preventDefault();
|
||||
})
|
||||
;
|
||||
switchTabs( current || links[0], conf );
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
})(jQuery);
|
||||
1
public/js/textile.min.js
vendored
Normal file
1
public/js/textile.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user