All Downloads are FREE. Search and download functionalities are using the official Maven repository.

public.component.assets.js.ace.elements.wysiwyg.js Maven / Gradle / Ivy

There is a newer version: 3.0.1.11
Show newest version
/**
 Wysiwyg. A wrapper for Bootstrap wyswiwyg plugin.
 It's just a wrapper so you still need to include Bootstrap wysiwyg script first.
*/
(function($ , undefined) {
	$.fn.ace_wysiwyg = function($options , undefined) {
		var options = $.extend( {
			speech_button:true,
			wysiwyg:{}
        }, $options);

		var color_values = [
			'#ac725e','#d06b64','#f83a22','#fa573c','#ff7537','#ffad46',
			'#42d692','#16a765','#7bd148','#b3dc6c','#fbe983','#fad165',
			'#92e1c0','#9fe1e7','#9fc6e7','#4986e7','#9a9cff','#b99aff',
			'#c2c2c2','#cabdbf','#cca6ac','#f691b2','#cd74e6','#a47ae2',
			'#444444'
		]

		var button_defaults =
		{
			'font' : {
				values:['Arial', 'Courier', 'Comic Sans MS', 'Helvetica', 'Open Sans', 'Tahoma', 'Verdana'],
				icon:'fa fa-font',
				title:'Font'
			},
			'fontSize' : {
				values:{5:'Huge', 3:'Normal', 1:'Small'},
				icon:'fa fa-text-height',
				title:'Font Size'
			},
			'bold' : {
				icon : 'fa fa-bold',
				title : 'Bold (Ctrl/Cmd+B)'
			},
			'italic' : {
				icon : 'fa fa-italic',
				title : 'Italic (Ctrl/Cmd+I)'
			},
			'strikethrough' : {
				icon : 'fa fa-strikethrough',
				title : 'Strikethrough'
			},
			'underline' : {
				icon : 'fa fa-underline',
				title : 'Underline'
			},
			'insertunorderedlist' : {
				icon : 'fa fa-list-ul',
				title : 'Bullet list'
			},
			'insertorderedlist' : {
				icon : 'fa fa-list-ol',
				title : 'Number list'
			},
			'outdent' : {
				icon : 'fa fa-outdent',
				title : 'Reduce indent (Shift+Tab)'
			},
			'indent' : {
				icon : 'fa fa-indent',
				title : 'Indent (Tab)'
			},
			'justifyleft' : {
				icon : 'fa fa-align-left',
				title : 'Align Left (Ctrl/Cmd+L)'
			},
			'justifycenter' : {
				icon : 'fa fa-align-center',
				title : 'Center (Ctrl/Cmd+E)'
			},
			'justifyright' : {
				icon : 'fa fa-align-right',
				title : 'Align Right (Ctrl/Cmd+R)'
			},
			'justifyfull' : {
				icon : 'fa fa-align-justify',
				title : 'Justify (Ctrl/Cmd+J)'
			},
			'createLink' : {
				icon : 'fa fa-link',
				title : 'Hyperlink',
				button_text : 'Add',
				placeholder : 'URL',
				button_class : 'btn-primary'
			},
			'unlink' : {
				icon : 'fa fa-chain-broken',
				title : 'Remove Hyperlink'
			},
			'insertImage' : {
				icon : 'fa fa-picture-o',
				title : 'Insert picture',
				button_text : ' Choose Image …',
				placeholder : 'Image URL',
				button_insert : 'Insert',
				button_class : 'btn-success',
				button_insert_class : 'btn-primary',
				choose_file: true //show the choose file button?
			},
			'foreColor' : {
				values : color_values,
				title : 'Change Color'
			},
			'backColor' : {
				values : color_values,
				title : 'Change Background Color'
			},
			'undo' : {
				icon : 'fa fa-undo',
				title : 'Undo (Ctrl/Cmd+Z)'
			},
			'redo' : {
				icon : 'fa fa-repeat',
				title : 'Redo (Ctrl/Cmd+Y)'
			},
			'viewSource' : {
				icon : 'fa fa-code',
				title : 'View Source'
			}
		}
		
		var toolbar_buttons =
		options.toolbar ||
		[
			'font',
			null,
			'fontSize',
			null,
			'bold',
			'italic',
			'strikethrough',
			'underline',
			null,
			'insertunorderedlist',
			'insertorderedlist',
			'outdent',
			'indent',
			null,
			'justifyleft',
			'justifycenter',
			'justifyright',
			'justifyfull',
			null,
			'createLink',
			'unlink',
			null,
			'insertImage',
			null,
			'foreColor',
			null,
			'undo',
			'redo',
			null,
			'viewSource'
		]


		this.each(function() {
			var toolbar = ' 
'; for(var tb in toolbar_buttons) if(toolbar_buttons.hasOwnProperty(tb)) { var button = toolbar_buttons[tb]; if(button === null){ toolbar += '
'; continue; } if(typeof button == "string" && button in button_defaults) { button = button_defaults[button]; button.name = toolbar_buttons[tb]; } else if(typeof button == "object" && button.name in button_defaults) { button = $.extend(button_defaults[button.name] , button); } else continue; var className = "className" in button ? button.className : 'btn-default'; switch(button.name) { case 'font': toolbar += ' '; toolbar += ' '; break; case 'fontSize': toolbar += '   '; toolbar += ' '; break; case 'createLink': toolbar += '
'; toolbar += '
'; break; case 'insertImage': toolbar += '
'; toolbar += '
'; break; case 'foreColor': case 'backColor': toolbar += ' '; toolbar += ' '; break; case 'viewSource': toolbar += ' '; break; default: toolbar += ' '; break; } } toolbar += '
'; //////////// var speech_input; if (options.speech_button && 'onwebkitspeechchange' in (speech_input = document.createElement('input'))) { toolbar += ' '; } speech_input = null; //////////// toolbar += '
'; //if we have a function to decide where to put the toolbar, then call that if(options.toolbar_place) toolbar = options.toolbar_place.call(this, toolbar); //otherwise put it just before our DIV else toolbar = $(this).before(toolbar).prev(); toolbar.find('a[title]').tooltip({animation:false, container:'body'}); toolbar.find('.dropdown-menu input[type=text]').on('click', function() {return false}) .on('change', function() {$(this).closest('.dropdown-menu').siblings('.dropdown-toggle').dropdown('toggle')}) .on('keydown', function (e) { if(e.which == 27) { this.value = ''; $(this).change(); } else if(e.which == 13) { e.preventDefault(); e.stopPropagation(); $(this).change(); } }); toolbar.find('input[type=file]').prev().on(ace.click_event, function (e) { $(this).next().click(); }); toolbar.find('.wysiwyg_colorpicker').each(function() { $(this).ace_colorpicker({pull_right:true}).change(function(){ $(this).nextAll('input').eq(0).val(this.value).change(); }).next().find('.btn-colorpicker').tooltip({title: this.title, animation:false, container:'body'}) }); var self = $(this); //view source var view_source = false; toolbar.find('a[data-view=source]').on('click', function(e){ e.preventDefault(); if(!view_source) { $('