New extension pattern
This commit is contained in:
		
							parent
							
								
									68f8aea79c
								
							
						
					
					
						commit
						cc01b5af4e
					
				| @ -264,13 +264,6 @@ define([ | ||||
| 		extensionMgr.onEditorConfigure(editor); | ||||
| 		editor.hooks.chain("onPreviewRefresh", extensionMgr.onAsyncPreview); | ||||
| 		 | ||||
| 		// Convert email addresses (not managed by pagedown)
 | ||||
| 		converter.hooks.chain("postConversion", function(text) { | ||||
| 			return text.replace(/<(mailto\:)?([^\s>]+@[^\s>]+\.\S+?)>/g, function(match, mailto, email) { | ||||
| 				return '<a href="mailto:' + email + '">' + email + '</a>'; | ||||
| 			}); | ||||
| 		}); | ||||
| 		 | ||||
| 		$("#wmd-input, #wmd-preview").scrollTop(0); | ||||
| 		$("#wmd-button-bar").empty(); | ||||
| 		editor.run(previewWrapper); | ||||
|  | ||||
| @ -15,6 +15,7 @@ define( [ | ||||
|     "extensions/markdown-extra", | ||||
|     "extensions/toc", | ||||
|     "extensions/math-jax", | ||||
|     "extensions/email-converter", | ||||
|     "extensions/scroll-link", | ||||
|     "lib/bootstrap" | ||||
| ], function($, _, utils, settings) { | ||||
| @ -54,30 +55,6 @@ define( [ | ||||
| 		extensionMgr[hookName] = createHook(hookName); | ||||
| 	} | ||||
| 	 | ||||
| 	var accordionTmpl = [ | ||||
|          		        '<div class="accordion-group">', | ||||
|          	         		'<div class="accordion-heading">', | ||||
|  		         				'<label class="checkbox pull-right">', | ||||
|  		         					'<input id="input-enable-extension-<%= extensionId %>" type="checkbox" <% if(!optional) { %> disabled <% } %>> enabled', | ||||
|  		         				'</label>', | ||||
|          		         		'<a id="accordion-toggle-test" data-toggle="collapse" data-parent="#accordion-extensions" class="accordion-toggle" href="#collapse-<%= extensionId %>">', | ||||
|          		         			'<%= extensionName %>', | ||||
|          		         		'</a>', | ||||
|          		         	'</div>', | ||||
|                   			'<div id="collapse-<%= extensionId %>" class="accordion-body collapse">', | ||||
|                   				'<div class="accordion-inner"><%= settingsBloc %></div>', | ||||
|                   			'</div>', | ||||
| 	                  	'</div>'].join(""); | ||||
| 	         		 | ||||
| 	function createSettings(extension) { | ||||
| 		$("#accordion-extensions").append($(_.template(accordionTmpl, { | ||||
| 			extensionId: extension.extensionId, | ||||
| 			extensionName: extension.extensionName, | ||||
| 			optional: extension.optional, | ||||
| 			settingsBloc: extension.settingsBloc | ||||
| 		}))); | ||||
| 	} | ||||
| 
 | ||||
| 	// Set extension config
 | ||||
| 	extensionSettings = settings.extensionSettings || {}; | ||||
| 	_.each(extensionList, function(extension) { | ||||
| @ -164,9 +141,37 @@ define( [ | ||||
| 		tryFinished(); | ||||
| 	}; | ||||
| 	 | ||||
| 	var accordionTmpl = [ | ||||
|         '<div class="accordion-group">', | ||||
| 	  		'<div class="accordion-heading">', | ||||
| 				'<label class="checkbox pull-right">', | ||||
| 					'<input id="input-enable-extension-<%= extensionId %>" type="checkbox" <% if(!optional) { %> disabled <% } %>> enabled', | ||||
| 				'</label>', | ||||
| 	      		'<a id="accordion-toggle-test" data-toggle="collapse" data-parent="#accordion-extensions" class="accordion-toggle" href="#collapse-<%= extensionId %>">', | ||||
| 	      			'<%= extensionName %>', | ||||
| 	      		'</a>', | ||||
| 	      	'</div>', | ||||
| 			'<div id="collapse-<%= extensionId %>" class="accordion-body collapse">', | ||||
| 				'<div class="accordion-inner"><%= settingsBloc %></div>', | ||||
| 			'</div>', | ||||
| 	   	'</div>'].join(""); | ||||
| 	         		 | ||||
| 	function createSettings(extension) { | ||||
| 		$("#accordion-extensions").append($(_.template(accordionTmpl, { | ||||
| 			extensionId: extension.extensionId, | ||||
| 			extensionName: extension.extensionName, | ||||
| 			optional: extension.optional, | ||||
| 			settingsBloc: extension.settingsBloc | ||||
| 		}))); | ||||
| 	} | ||||
| 
 | ||||
| 	$(function() { | ||||
| 		// Create accordion in settings dialog
 | ||||
| 		_.each(extensionList, createSettings); | ||||
| 		_.chain( | ||||
| 			extensionList | ||||
| 		).sortBy(function(extension) { | ||||
| 			return extension.extensionName.toLowerCase(); | ||||
| 		}).each(createSettings); | ||||
| 	}); | ||||
| 	 | ||||
| 	return extensionMgr; | ||||
|  | ||||
| @ -6,7 +6,6 @@ define([ | ||||
| 	var buttonPublish = { | ||||
| 		extensionId: "buttonPublish", | ||||
| 		extensionName: 'Button "Publish"', | ||||
|         optional: true, | ||||
| 		settingsBloc: '<p>Adds a "Publish document" button in the navigation bar.</p>' | ||||
| 	}; | ||||
| 	 | ||||
|  | ||||
| @ -6,7 +6,6 @@ define([ | ||||
| 	var buttonSync = { | ||||
| 		extensionId: "buttonSync", | ||||
| 		extensionName: 'Button "Synchronize"', | ||||
|         optional: true, | ||||
| 		settingsBloc: '<p>Adds a "Synchronize documents" button in the navigation bar.</p>' | ||||
| 	}; | ||||
| 	 | ||||
|  | ||||
							
								
								
									
										20
									
								
								js/extensions/email-converter.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										20
									
								
								js/extensions/email-converter.js
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,20 @@ | ||||
| define(function() { | ||||
| 	 | ||||
| 	var emailConverter = { | ||||
| 		extensionId: "emailConverter", | ||||
| 		extensionName: "Email Converter", | ||||
|         optional: true, | ||||
| 		settingsBloc: '<p>Converts email adresses in the form <email@example.com> into a clickable links.</p>' | ||||
| 	}; | ||||
| 	 | ||||
| 	emailConverter.onEditorConfigure = function(editor) { | ||||
| 		editor.getConverter().hooks.chain("postConversion", function(text) { | ||||
| 			return text.replace(/<(mailto\:)?([^\s>]+@[^\s>]+\.\S+?)>/g, function(match, mailto, email) { | ||||
| 				return '<a href="mailto:' + email + '">' + email + '</a>'; | ||||
| 			}); | ||||
| 		}); | ||||
| 	}; | ||||
| 	 | ||||
| 	return emailConverter; | ||||
| }); | ||||
| 	 | ||||
| @ -5,7 +5,7 @@ define([ | ||||
| 	 | ||||
| 	var managePublication = { | ||||
| 		extensionId: "managePublication", | ||||
| 		extensionName: "Manage Publication", | ||||
| 		extensionName: "Manage publication", | ||||
| 		settingsBloc: '<p>Populates the "Manage publication" dialog box.</p>' | ||||
| 	}; | ||||
| 	 | ||||
|  | ||||
| @ -5,7 +5,7 @@ define([ | ||||
| 	 | ||||
| 	var manageSynchronization = { | ||||
| 		extensionId: "manageSynchronization", | ||||
| 		extensionName: "Manage Synchronization", | ||||
| 		extensionName: "Manage synchronization", | ||||
| 		settingsBloc: '<p>Populates the "Manage synchronization" dialog box.</p>' | ||||
| 	}; | ||||
| 	 | ||||
|  | ||||
| @ -1,21 +1,41 @@ | ||||
| define([ | ||||
|     "jquery", | ||||
|     "underscore", | ||||
|     "utils", | ||||
|     "jgrowl" | ||||
| ], function($, _, jGrowl) { | ||||
| ], function($, _, utils, jGrowl) { | ||||
| 	 | ||||
| 	var notifications = { | ||||
| 		extensionId: "notifications", | ||||
| 		extensionName: "Notifications", | ||||
| 		defaultConfig: { | ||||
| 			showingTime: 5000 | ||||
| 			timeout: 5000 | ||||
| 		}, | ||||
| 		settingsBloc: '<p>Shows notification messages in the bottom-right corner of the screen.</p>' | ||||
|         settingsBloc: [ | ||||
|                        	'<p>Shows notification messages in the bottom-right corner of the screen.</p>', | ||||
|                        	'<div class="form-horizontal">', | ||||
| 	                       	'<div class="control-group">', | ||||
| 		                       	'<label class="control-label" for="input-notifications-timeout">Timeout</label>', | ||||
| 		                       	'<div class="controls">', | ||||
| 	                       		'<input type="text" id="input-notifications-timeout" class="input-mini">', | ||||
| 	                       		'<span class="help-inline">ms</span>', | ||||
| 	                       		'</div>', | ||||
|                        		'</div>', | ||||
|                    		'</div>' | ||||
|                       ].join("") | ||||
| 	}; | ||||
| 	 | ||||
| 	notifications.onLoadSettings = function() { | ||||
|     	utils.setInputValue("#input-notifications-timeout", notifications.config.timeout); | ||||
|     }; | ||||
|      | ||||
|     notifications.onSaveSettings = function(newConfig, event) { | ||||
|     	newConfig.timeout = utils.getInputIntValue("#input-notifications-timeout", event, 1, 60000); | ||||
|     }; | ||||
|      | ||||
| 	notifications.onReady = function() { | ||||
| 		// jGrowl configuration
 | ||||
| 		jGrowl.defaults.life = notifications.config.showingTime; | ||||
| 		jGrowl.defaults.life = notifications.config.timeout; | ||||
| 		jGrowl.defaults.closer = false; | ||||
| 		jGrowl.defaults.closeTemplate = ''; | ||||
| 		jGrowl.defaults.position = 'bottom-right'; | ||||
|  | ||||
| @ -6,9 +6,9 @@ define([ | ||||
| 	 | ||||
| 	var toc = { | ||||
| 		extensionId: "toc", | ||||
| 		extensionName: "Table Of Content", | ||||
| 		extensionName: "Table of content", | ||||
|         optional: true, | ||||
| 		settingsBloc: '<p>Generates a table of content and include it in your document using the marker [TOC].</p>' | ||||
| 		settingsBloc: '<p>Generates a table of content when a [TOC] marker is found.</p>' | ||||
| 	}; | ||||
| 	 | ||||
| 	// TOC element description
 | ||||
|  | ||||
| @ -36,16 +36,19 @@ define([ | ||||
| 	 | ||||
| 	// Caution: this function recreate the editor (reset undo operations)
 | ||||
| 	fileMgr.selectFile = function(fileDesc) { | ||||
| 		var fileSystemSize = _.size(fileSystem); | ||||
| 		// If no file create one
 | ||||
| 		if (_.size(fileSystem) === 0) { | ||||
| 			fileDesc = fileMgr.createFile(WELCOME_DOCUMENT_TITLE, welcomeContent); | ||||
| 		} | ||||
| 		fileDesc = fileDesc || fileMgr.getCurrentFile(); | ||||
| 		 | ||||
| 		if(fileDesc === undefined) { | ||||
| 			var fileSystemSize = _.size(fileSystem); | ||||
| 			// If fileSystem empty create one file
 | ||||
| 			if (fileSystemSize === 0) { | ||||
| 				fileDesc = fileMgr.createFile(WELCOME_DOCUMENT_TITLE, welcomeContent); | ||||
| 			}			 | ||||
| 			// If no file is selected take the last created
 | ||||
| 			else { | ||||
| 				fileDesc = fileSystem[_.keys(fileSystem)[fileSystemSize - 1]]; | ||||
| 			} | ||||
| 		} | ||||
| 		fileMgr.setCurrentFile(fileDesc); | ||||
| 
 | ||||
| 		// Notify extensions
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 benweet
						benweet