fixes highlight.js

This commit is contained in:
zmagod 2017-01-19 17:09:25 +01:00
parent 039a8d7da6
commit 9550c6dd35
10 changed files with 38 additions and 13 deletions

View file

@ -233,7 +233,7 @@ var HelperModule = (function(){
// initialize code markup in rich text fields
(function() {
$(document).ready(function() {
$('pre code [class^=language]').each(function(i, block) {
$('[class^=language]').each(function(i, block) {
hljs.highlightBlock(block);
});
});

View file

@ -79,6 +79,7 @@ function applyCancelCallBack() {
setTimeout(function() {
initStepsComments();
TinyMCE.destroyAll();
}, 1000);
})
@ -245,6 +246,7 @@ function formNewAjax($form) {
toggleButtons(true);
TinyMCE.init();
TinyMCE.highlight();
//Rerender tables
$new_step.find("div.step-result-hot-table").each(function() {
$(this).handsontable("render");

View file

@ -2,13 +2,18 @@ var TinyMCE = (function() {
'use strict';
function initHighlightjs() {
$('pre code [class^=language]').each(function(i, block) {
if(!$(block).hasClass('hljs')) {
hljs.highlightBlock(block);
}
$('[class*=language]').each(function(i, block) {
hljs.highlightBlock(block);
});
}
function initHighlightjsIframe(iframe) {
$('[class*=language]', iframe).each(function(i, block) {
hljs.highlightBlock(block);
});
}
// returns a public API for TinyMCE editor
return Object.freeze({
init : function() {
if (typeof tinyMCE != 'undefined') {
@ -19,13 +24,27 @@ var TinyMCE = (function() {
codesample_languages: [{"text":"R","value":"r"},{"text":"MATLAB","value":"matlab"},{"text":"Python","value":"python"},{"text":"JSON","value":"javascript"},{"text":"HTML/XML","value":"markup"},{"text":"JavaScript","value":"javascript"},{"text":"CSS","value":"css"},{"text":"PHP","value":"php"},{"text":"Ruby","value":"ruby"},{"text":"Java","value":"java"},{"text":"C","value":"c"},{"text":"C#","value":"csharp"},{"text":"C++","value":"cpp"}],
init_instance_callback: function(editor) {
SmartAnnotation.init($(editor.contentDocument.activeElement));
initHighlightjsIframe($(this.iframeElement).contents());
},
setup: function(editor) {
editor.on('keydown', function(e) {
if(e.keyCode == 13 && $(editor.contentDocument.activeElement).atwho('isSelecting'))
editor.on('Change', function(e) {
if(e.keyCode == 13 && $(editor.contentDocument.activeElement).atwho('isSelecting')) {
return false;
}
});
}
editor.on('NodeChange', function(e) {
var node = e.element;
var editor = this;
setTimeout(function() {
if($(node).is('pre') && !editor.isHidden()){
initHighlightjsIframe($(editor.iframeElement).contents());
}
}, 200);
});
},
codesample_content_css: '<%= asset_path('highlightjs-github-theme') %>'
});
}
},

View file

@ -263,7 +263,7 @@ module BootstrapFormHelper
# Returns <textarea> helper tag for tinyMCE editor
def tiny_mce_editor(name, options = {})
options.merge!(class: 'tinymce', cols: 120, rows: 40)
options.merge!(class: 'tinymce', cols: 120, rows: 15)
text_area(name, options)
end
end

View file

@ -65,7 +65,6 @@ class Experiment < ActiveRecord::Base
Experiment
.where('experiments.project_id IN (?)', projects_ids)
.where_attributes_like([:name], a_query)
.limit(Constants::ATWHO_SEARCH_LIMIT)
return include_archived ? new_query : new_query.is_archived(false)
elsif include_archived
new_query =

View file

@ -71,7 +71,7 @@ class MyModule < ActiveRecord::Base
.distinct
.where('my_modules.experiment_id IN (?)', experiments_ids)
.where_attributes_like([:name], a_query)
.limit(Constants::ATWHO_SEARCH_LIMIT)
if include_archived
return new_query
else

View file

@ -49,7 +49,7 @@ class Project < ActiveRecord::Base
.where('projects.visibility = 1 OR user_projects.user_id = ?',
user.id)
.where_attributes_like(:name, a_query)
.limit(Constants::ATWHO_SEARCH_LIMIT)
if include_archived
return new_query
else

View file

@ -44,7 +44,7 @@ class Sample < ActiveRecord::Base
.distinct
.where('samples.organization_id = ?', current_organization.id)
.where_attributes_like(['samples.name'], a_query)
.limit(Constants::ATWHO_SEARCH_LIMIT)
return new_query
else
new_query = Sample

View file

@ -14,6 +14,7 @@ class SmartAnnotation
# Search tasks
res = MyModule
.search(@current_user, false, @query, 1, @current_organization)
.limit(Constants::ATWHO_SEARCH_LIMIT)
modules_list = []
res.each do |my_module_res|
@ -40,6 +41,7 @@ class SmartAnnotation
# Search projects
res = Project
.search(@current_user, false, @query, 1, @current_organization)
.limit(Constants::ATWHO_SEARCH_LIMIT)
projects_list = []
res.each do |project_res|
@ -56,6 +58,7 @@ class SmartAnnotation
# Search experiments
res = Experiment
.search(@current_user, false, @query, 1, @current_organization)
.limit(Constants::ATWHO_SEARCH_LIMIT)
experiments_list = []
res.each do |experiment_res|
@ -76,6 +79,7 @@ class SmartAnnotation
# Search samples
res = Sample
.search(@current_user, false, @query, 1, @current_organization)
.limit(Constants::ATWHO_SEARCH_LIMIT)
samples_list = []
res.each do |sample_res|

View file

@ -61,6 +61,7 @@ Rails.application.config.assets.precompile += %w(projects/show.js)
Rails.application.config.assets.precompile += %w(notifications.js)
Rails.application.config.assets.precompile += %w(users/invite_users_modal.js)
Rails.application.config.assets.precompile += %w(samples/sample_types_groups.js)
Rails.application.config.assets.precompile += %w(highlightjs-github-theme.css)
# Libraries needed for Handsontable formulas
Rails.application.config.assets.precompile += %w(lodash.js)