New extension pattern
This commit is contained in:
		
							parent
							
								
									68f8aea79c
								
							
						
					
					
						commit
						cc01b5af4e
					
				| @ -264,13 +264,6 @@ define([ | |||||||
| 		extensionMgr.onEditorConfigure(editor); | 		extensionMgr.onEditorConfigure(editor); | ||||||
| 		editor.hooks.chain("onPreviewRefresh", extensionMgr.onAsyncPreview); | 		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-input, #wmd-preview").scrollTop(0); | ||||||
| 		$("#wmd-button-bar").empty(); | 		$("#wmd-button-bar").empty(); | ||||||
| 		editor.run(previewWrapper); | 		editor.run(previewWrapper); | ||||||
|  | |||||||
| @ -15,6 +15,7 @@ define( [ | |||||||
|     "extensions/markdown-extra", |     "extensions/markdown-extra", | ||||||
|     "extensions/toc", |     "extensions/toc", | ||||||
|     "extensions/math-jax", |     "extensions/math-jax", | ||||||
|  |     "extensions/email-converter", | ||||||
|     "extensions/scroll-link", |     "extensions/scroll-link", | ||||||
|     "lib/bootstrap" |     "lib/bootstrap" | ||||||
| ], function($, _, utils, settings) { | ], function($, _, utils, settings) { | ||||||
| @ -54,30 +55,6 @@ define( [ | |||||||
| 		extensionMgr[hookName] = createHook(hookName); | 		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
 | 	// Set extension config
 | ||||||
| 	extensionSettings = settings.extensionSettings || {}; | 	extensionSettings = settings.extensionSettings || {}; | ||||||
| 	_.each(extensionList, function(extension) { | 	_.each(extensionList, function(extension) { | ||||||
| @ -164,9 +141,37 @@ define( [ | |||||||
| 		tryFinished(); | 		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() { | 	$(function() { | ||||||
| 		// Create accordion in settings dialog
 | 		// Create accordion in settings dialog
 | ||||||
| 		_.each(extensionList, createSettings); | 		_.chain( | ||||||
|  | 			extensionList | ||||||
|  | 		).sortBy(function(extension) { | ||||||
|  | 			return extension.extensionName.toLowerCase(); | ||||||
|  | 		}).each(createSettings); | ||||||
| 	}); | 	}); | ||||||
| 	 | 	 | ||||||
| 	return extensionMgr; | 	return extensionMgr; | ||||||
|  | |||||||
| @ -6,7 +6,6 @@ define([ | |||||||
| 	var buttonPublish = { | 	var buttonPublish = { | ||||||
| 		extensionId: "buttonPublish", | 		extensionId: "buttonPublish", | ||||||
| 		extensionName: 'Button "Publish"', | 		extensionName: 'Button "Publish"', | ||||||
|         optional: true, |  | ||||||
| 		settingsBloc: '<p>Adds a "Publish document" button in the navigation bar.</p>' | 		settingsBloc: '<p>Adds a "Publish document" button in the navigation bar.</p>' | ||||||
| 	}; | 	}; | ||||||
| 	 | 	 | ||||||
|  | |||||||
| @ -6,7 +6,6 @@ define([ | |||||||
| 	var buttonSync = { | 	var buttonSync = { | ||||||
| 		extensionId: "buttonSync", | 		extensionId: "buttonSync", | ||||||
| 		extensionName: 'Button "Synchronize"', | 		extensionName: 'Button "Synchronize"', | ||||||
|         optional: true, |  | ||||||
| 		settingsBloc: '<p>Adds a "Synchronize documents" button in the navigation bar.</p>' | 		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 = { | 	var managePublication = { | ||||||
| 		extensionId: "managePublication", | 		extensionId: "managePublication", | ||||||
| 		extensionName: "Manage Publication", | 		extensionName: "Manage publication", | ||||||
| 		settingsBloc: '<p>Populates the "Manage publication" dialog box.</p>' | 		settingsBloc: '<p>Populates the "Manage publication" dialog box.</p>' | ||||||
| 	}; | 	}; | ||||||
| 	 | 	 | ||||||
|  | |||||||
| @ -5,7 +5,7 @@ define([ | |||||||
| 	 | 	 | ||||||
| 	var manageSynchronization = { | 	var manageSynchronization = { | ||||||
| 		extensionId: "manageSynchronization", | 		extensionId: "manageSynchronization", | ||||||
| 		extensionName: "Manage Synchronization", | 		extensionName: "Manage synchronization", | ||||||
| 		settingsBloc: '<p>Populates the "Manage synchronization" dialog box.</p>' | 		settingsBloc: '<p>Populates the "Manage synchronization" dialog box.</p>' | ||||||
| 	}; | 	}; | ||||||
| 	 | 	 | ||||||
|  | |||||||
| @ -1,21 +1,41 @@ | |||||||
| define([ | define([ | ||||||
|     "jquery", |     "jquery", | ||||||
|     "underscore", |     "underscore", | ||||||
|  |     "utils", | ||||||
|     "jgrowl" |     "jgrowl" | ||||||
| ], function($, _, jGrowl) { | ], function($, _, utils, jGrowl) { | ||||||
| 	 | 	 | ||||||
| 	var notifications = { | 	var notifications = { | ||||||
| 		extensionId: "notifications", | 		extensionId: "notifications", | ||||||
| 		extensionName: "Notifications", | 		extensionName: "Notifications", | ||||||
| 		defaultConfig: { | 		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() { | 	notifications.onReady = function() { | ||||||
| 		// jGrowl configuration
 | 		// jGrowl configuration
 | ||||||
| 		jGrowl.defaults.life = notifications.config.showingTime; | 		jGrowl.defaults.life = notifications.config.timeout; | ||||||
| 		jGrowl.defaults.closer = false; | 		jGrowl.defaults.closer = false; | ||||||
| 		jGrowl.defaults.closeTemplate = ''; | 		jGrowl.defaults.closeTemplate = ''; | ||||||
| 		jGrowl.defaults.position = 'bottom-right'; | 		jGrowl.defaults.position = 'bottom-right'; | ||||||
|  | |||||||
| @ -6,9 +6,9 @@ define([ | |||||||
| 	 | 	 | ||||||
| 	var toc = { | 	var toc = { | ||||||
| 		extensionId: "toc", | 		extensionId: "toc", | ||||||
| 		extensionName: "Table Of Content", | 		extensionName: "Table of content", | ||||||
|         optional: true, |         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
 | 	// TOC element description
 | ||||||
|  | |||||||
| @ -36,16 +36,19 @@ define([ | |||||||
| 	 | 	 | ||||||
| 	// Caution: this function recreate the editor (reset undo operations)
 | 	// Caution: this function recreate the editor (reset undo operations)
 | ||||||
| 	fileMgr.selectFile = function(fileDesc) { | 	fileMgr.selectFile = function(fileDesc) { | ||||||
| 		var fileSystemSize = _.size(fileSystem); | 		fileDesc = fileDesc || fileMgr.getCurrentFile(); | ||||||
| 		// If no file create one
 |  | ||||||
| 		if (_.size(fileSystem) === 0) { |  | ||||||
| 			fileDesc = fileMgr.createFile(WELCOME_DOCUMENT_TITLE, welcomeContent); |  | ||||||
| 		} |  | ||||||
| 		 | 		 | ||||||
| 		if(fileDesc === undefined) { | 		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
 | 			// If no file is selected take the last created
 | ||||||
|  | 			else { | ||||||
| 				fileDesc = fileSystem[_.keys(fileSystem)[fileSystemSize - 1]]; | 				fileDesc = fileSystem[_.keys(fileSystem)[fileSystemSize - 1]]; | ||||||
| 			} | 			} | ||||||
|  | 		} | ||||||
| 		fileMgr.setCurrentFile(fileDesc); | 		fileMgr.setCurrentFile(fileDesc); | ||||||
| 
 | 
 | ||||||
| 		// Notify extensions
 | 		// Notify extensions
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 benweet
						benweet