add markitup definition file

This commit is contained in:
drillbits
2015-09-29 10:55:22 +09:00
parent d0adccc436
commit 1789faf3a0
2 changed files with 326 additions and 0 deletions
+89
View File
@@ -0,0 +1,89 @@
/// <reference path="../jquery/jquery.d.ts" />
/// <reference path="markitup.d.ts" />
// https://github.com/markitup/1.x/blob/master/markitup/sets/default/set.js
var mySettings = {
onShiftEnter: {
keepDefault: false,
replaceWith: '<br />\n'
},
onCtrlEnter: {
keepDefault: false,
openWith: '\n<p>',
closeWith: '</p>'
},
onTab: {
keepDefault: false,
replaceWith: ' '
},
markupSet: [
{
name: 'Bold',
key: 'B',
openWith: '(!(<strong>|!|<b>)!)',
closeWith: '(!(</strong>|!|</b>)!)'
},
{
name: 'Italic',
key: 'I',
openWith: '(!(<em>|!|<i>)!)',
closeWith: '(!(</em>|!|</i>)!)'
},
{
name: 'Stroke through',
key: 'S',
openWith: '<del>',
closeWith: '</del>'
},
{separator: '---------------'},
{
name: 'Bulleted List',
openWith: ' <li>',
closeWith: '</li>',
multiline: true,
openBlockWith: '<ul>\n',
closeBlockWith: '\n</ul>'
},
{
name: 'Numeric List',
openWith: ' <li>',
closeWith: '</li>',
multiline: true,
openBlockWith: '<ol>\n',
closeBlockWith: '\n</ol>'
},
{
separator: '---------------'
},
{
name: 'Picture',
key: 'P',
replaceWith: '<img src="[![Source:!:http://]!]" alt="[![Alternative text]!]" />'
},
{
name: 'Link',
key: 'L',
openWith: '<a href="[![Link:!:http://]!]"(!( title="[![Title]!]")!)>',
closeWith: '</a>',
placeHolder: 'Your text to link...'
},
{
separator: '---------------'
},
{
name: 'Clean',
className: 'clean',
replaceWith: (markitup: MarkItUp.MarkupSet): string => {
return markitup.selection.replace(/<(.*?)>/g, "")
}
},
{
name: 'Preview',
className: 'preview',
call: 'preview'
}
]
};
// http://markitup.jaysalvat.com/documentation/
$('#markItUp').markItUp(mySettings);
+237
View File
@@ -0,0 +1,237 @@
// Type definitions for markitup/1.x
// Project: https://github.com/markitup/1.x
// Definitions by: drillbits <https://github.com/drillbits>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="../jquery/jquery.d.ts" />
declare module MarkItUp {
interface Options {
/**
* Apply a specific className to the wrapping Div. Useful to prevent CSS conflicts between instances.
*/
nameSpace?: string;
/**
* Enable/Disable the handle to resize the editor.
*/
resizeHandle?: boolean;
/**
* Display the preview in a popup window with comma-separated list of specs. If empty or false, the preview will be displayed in the built-in iFrame preview.
*/
previewInWindow?: string;
/**
* AutoRefresh the preview iFrame or window when the editor is used.
*/
previewAutoRefresh?: boolean;
/**
* You can set the path of your own parser to preview markup languages other than html. If this property is set, the built-in preview will be overridden by your own preview script.
* Use ~/ for markItUp! root.
*/
previewParserPath?: string;
/**
* Name of the var posted with the editor content to the parser defined above.
*
* default: 'data'
*/
previewParserVar?: string;
/**
* Path to the Html preview template.
* Use ~/ for markItUp! root.
*
* default: '~/templates/preview.html'
*/
previewTemplatePath?: string;
/**
* Parse the content with the javascript parser of your choice before passing it to the preview.
*
* default: false
*/
previewParser?: boolean;
/**
* Position of the Built-in preview before or after the main textarea.
* 'before'|'after'
*
* default: 'after'
*/
previewPosition?: string;
/**
* Define what to do when Enter key is pressed.
*/
onEnter?: MarkupSet;
/**
* Define what to do when Ctrl+Enter keys are pressed.
*/
onCtrlEnter?: MarkupSet;
/**
* Define what to do when Shift+Enter keys are pressed.
*/
onShiftEnter?: MarkupSet;
/**
* Define what to do when Tab key is pressed. Warning, this key is also used to jump at the end of a new inserted markup.
*/
onTab?: MarkupSet;
/**
* Function to be called before any markup insertion.
*/
beforeInsert?: (h: MarkupSet) => string;
/**
* Function to be called after any markup insertion.
*/
afterInsert?: (h: MarkupSet) => string;
/**
* Note that most of the settings below are used by the engine for all insertion calls ($.markItUp( {} ), onEnter, onShiftEnter, onCtrlEnter, onTab) except exclusive button properties marked by
*/
markupSet?: MarkupSet[];
}
interface MarkupSet {
/**
* Button name
*/
name?: string;
/**
* Classname to be applied to this very button.
*/
className?: string;
/**
* Shortcut key to be applied to the button. Ctrl+key trigger the action of a button.
*/
key?: string;
/**
* Markup to be added before selection. Accepts functions.
*/
openWith?: string|((h: MarkupSet) => string);
/**
* Markup to be added after selection. Accepts functions.
*/
closeWith?: string|((h: MarkupSet) => string);
/**
* Text to be added in place of the cursor or selection. Accepts functions.
*/
replaceWith?: string|((h: MarkupSet) => string);
/**
* Text to be added before a whole block. Accepts functions.
*/
openBlockWith?: string|((h: MarkupSet) => string);
/**
* Text to be added after a whole block. Accepts functions.
*/
closeBlockWith?: string|((h: MarkupSet) => string);
/**
* Set whether the tags has to be inserted at each line or on the whole selected block.
*/
multiline?: boolean;
/**
* Placeholder text to be inserted if no text is selected by the user.
*/
placeHolder?: string|((h: MarkupSet) => string);
/**
* Function to be called just before a markup insertion. If a global beforeInsert callback is already defined this function is fired just after.
*/
beforeInsert?: (h: MarkupSet) => string;
/**
* Function to be called just after a markup insertion. If a global afterInsert callback is already defined this function is fired before.
*/
afterInsert?: (h: MarkupSet) => string;
/**
* Function to be called before a multiline markup insertion.
*/
beforeMultiInsert?: (h: MarkupSet) => string;
/**
* Function to be called after a multiline markup insertion.
*/
afterMultiInsert?: (h: MarkupSet) => string;
/**
* Open a dropdown menu with another button set.
*/
dropMenu?: MarkupSet[];
/**
* Keep (true) or not (false) the default behaviour of the key.
*/
keepDefault?: boolean;
/**
* Returns the selection.
*/
selection?: string;
/**
* Returns the textarea object.
*/
textarea?: HTMLElement;
/**
* Returns the position of the selection.
*/
caretPosition?: number;
/**
* Returns the position of the scrollbar.
*/
scrollPosition?: number;
/**
* If a multi-line edition is trigged (Ctrl + Shift + click). This property return the number of the line being processed.
*/
line?: number;
/**
* Returns true if the Control key is pressed when the callback is fired.
*/
ctrlKey?: boolean;
/**
* Returns true if the Shift key is pressed when the callback is fired.
*/
shiftKey?: boolean;
/**
* Returns true if the Alt key is pressed when the callback is fired.
*/
altKey?: boolean;
}
interface Static {
(): JQuery;
(settings: Options): JQuery;
}
}
interface JQueryStatic {
markItUp: MarkItUp.Static;
}
interface JQuery {
markItUp(settings?: MarkItUp.Options): JQuery;
markItUpRemove(): JQuery;
}