I have integrated the bootstrap-wysihtml5 editor to description section in my rails application. Now I want to add the client side validation so that it would validate the presence of description field. I used bootstrap-wysihtml5-rails gem.
The editor is being initialized with following code:
<script type="text/javascript">
$(document).ready(function(){
$('#description').each(function(i, elem) {
$(elem).wysihtml5({
toolbar: {
"fa": true, // use Font Awesome
"font-styles": false, // Font styling, e.g. h1, h2, etc.
"emphasis": true, // Italics, bold, etc.
"lists": false, // (Un)ordered lists, e.g. Bullets, Numbers.
"html": false, // Button which allows you to edit the generated HTML.
"link": true, // Button to insert a link.
"image": true, // Button to insert an image.
"color": false, // Button to change color of font
"blockquote": false // Blockquote
}
});
});
})
Thanks in advance.
Found the solution by adding the events as suggested by the documentation
$('#some-textarea').wysihtml5({
"events": {
"load": function() {
console.log("Loaded!");
},
"blur": function() {
console.log("Blured");
}
}
});
Related
I'm trying to override the default configuration on the Advanced Real-Time Chart TradingView Widget.
I added a simple moving average on which I managed to set the period (from default 9 to 200).
I would like to change the color, but I didn't find any documentation on how to achieve that?
Question 1 : Is there any documentation on how to customize the widget?
Question 2 : Is it possible / how to change the indicators colors?
Here is a snippet of what I'm trying to achieve:
<!-- TradingView Widget BEGIN -->
<div class="tradingview-widget-container">
<div id="tradingview_f7f00"></div>
<div class="tradingview-widget-copyright"><span class="blue-text">AAPL Chart</span> by TradingView</div>
<script type="text/javascript" src="https://s3.tradingview.com/tv.js"></script>
<script type="text/javascript">
new TradingView.widget(
{
"width": 980,
"height": 610,
"symbol": "NASDAQ:AAPL",
"interval": "D",
"timezone": "Etc/UTC",
"theme": "light",
"style": "1",
"locale": "en",
"toolbar_bg": "#f1f3f6",
"enable_publishing": false,
"allow_symbol_change": true,
// ==================== BEGIN ====================
"studies": [
{
id: "MASimple#tv-basicstudies",
// This sets the period
inputs: {
length: 200,
},
// This doesn't work...
styles: {
color: '#ff0000',
}
},
],
// ==================== END ====================
"container_id": "tradingview_f7f00"
}
);
</script>
</div>
<!-- TradingView Widget END -->
Refer:
Tradingview Simple Moving Average widget configure
Try like this,
You should use the names of the studies in the Insert Study dialog as they are but using lower case letters.
"studies_overrides": {
"moving average.ma.color": "#2A2E39",
"moving average.ma.linewidth": 2,
},
You need to pass an overrider object to the widget constructor just like you are passing other parameters such as width, or height:
new TradingView.widget({
overrides: {
'paneProperties.background': '#2E2E2E',
}
});
This one would change the background, for example.
To know more about overrides just consult the wiki page of the library, on the overrides section :)
Context
I have a small Ember app, which, amongst other things, displays a number of connected users and, when hovering an element of the page, their names as a list.
All in all, it works quite well. The applications pulls data from a REST endpoint every two minutes, as the backend didn't allow for pushing data.
The contents of the tooltip are computed in the Controller, with a function that basically concatenate strings in various ways according to the context. Then it's bound to a data attribute of the <img> the tooltip is created on. When the View is ready and didInsertElement is fired, the tooltip is generated (if needs be) based on this data-bindattr value.
Question
When new data is pulled from the backend, everything is updated accordingly, except the tooltip content. (When browsing the page's DOM, the data-bindattr value is updated too.)
What could cause the tooltip to not refresh? Is it a case of JQuery-UI not calculating it again?
Some code
Refreshing code in the app's controller:
Monitor.ApplicationController = Ember.ArrayController.extend({
itemController: 'process',
sortProperties: ['name'],
sortAscending: true,
intervalId: undefined,
startRefreshing: function() {
var self = this;
if (self.get('intervalId')) {
return;
}
self.set( 'intervalId', setInterval(function() {
self.store.find('process');
}, 120000 ));
}
});
View: Process.hbs
<div {{bind-attr class=":inline inactive:inactive"}}>
<img {{bind-attr src=icon}} {{bind-attr data-caption=contentText}} class="caption" />
<div class="counter">{{nbUsers}}</div>
</div>
View: ProcessView
Monitor.ProcessView = Ember.View.extend({
// (...) Various stuff.
didInsertElement: function() {
this.updateTooltip();
},
updateTooltip: function() {
console.log('Inside updateTooltip!');
if (!this.$()) {return;}
if (this.get('controller').get('inactive')) {
this.$().tooltip({items: '.caption', disabled: true});
return;
}
this.$().tooltip({
items: '.caption',
tooltipClass: 'tooltip',
content: function() {
return $(this).data('caption');
},
position: {
my: 'left+15px center',
at: 'right center',
collision: 'flip'
},
show: false,
hide: false
});
}.observes('controller.inactive', 'controller.contentText')
});
Controller: ProcessController
Monitor.ProcessController = Ember.ObjectController.extend({
contentText: function() {
var tooltipContent = '';
this.get('containers').forEach(function(container) {
// Do a lot of things to tooltipContent involving:
// container.get('name')
// container.get('text')
// container.get('size')
// container.get('nbUsers')
// The data-bindattr value refreshes correctly so I cut this out for readability.
return tooltipContent;
}.property('name', 'containers.#each')
});
Edit 1:
Replaced 'containers.#each' by 'contentText' in the observer and added logging.
Here's what I think is happening:
Your tooltip library isn't observing the data-caption attribute. Meaning, when you update the attribute, you have to explicitly tell the library to update the tooltip as well. So although your attribute is updating just fine, the tooltip library isn't actually watching for those updates.
This can be remedied by calling updateTooltip, which you do, in didInsertElement. However, didInsertElement only fires once, when the element is first inserted. It's not called when the content changes.
Those two things combined are, I think, causing your problem. I think that all you need to do is have updateTooltip also observe the controller.contextText property. Then it should be called when the text updates.
So it turns out my codes declares and initialize a tooltip, but once it's done, you can't change the content the same way. Plus it adds unneeded computing anyway.
Thanks to #GJK's answer and that question, I found out what was happening. Turns out you need to set the content of the tooltip to refresh it, not recreate it.
Here is the working code for Ember integration:
Monitor.ProcessView = Ember.View.extend({
// Other stuff
didInsertElement: function() {
this.initTooltip();
},
initTooltip: function() {
if (!this.$()) {return;}
if (this.get('controller').get('inactive')) {
this.$().tooltip({items: '.caption', disabled: true});
return;
}
this.$().tooltip({
items: '.caption',
tooltipClass: 'tooltip',
content: function() {
return $(this).data('caption');
},
position: {
my: 'left+15px center',
at: 'right center',
collision: 'flip'
},
show: false,
hide: false
});
},
updateTooltip: function() {
if (!this.$()) {return;}
if (this.get('controller').get('inactive')) {
this.$().tooltip({items: '.caption', disabled: true});
return;
}
content = this.get('controller').get('contentText');
this.$().tooltip("option", "content", content);
}.observes('controller.contentText')
});
As an added bonus, you can avoid using the data attribute as a buffer now, although I'm not sure why.
I'm using jquery datatables with theme roller support, and I would like to place a jquery-ui button in a column for each row. In order to do this, I'm using the following code:
oTable = $('#balances').dataTable({
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
...
"aoColumns": [
...
{
"mData": null,
"mRender": function(data, type, row) {
return $("<div />")
.append($("<button id='detail'>Details</button>").button())
.html();
}
}
]
});
The buttons are drawn and I can attach events to them, but it seems that I'm missing something (for example, these buttons don't animate when you move the mouse over them).
How can I correct this? Is there a better way to do it?
Thank you in advance.
Because using multiple identical Ids is not recommended, I'd suggest using a class instead, and moving the .button() call further down in the code:
oTable = $('#balances').dataTable({
"bProcessing": true,
"bServerSide": true,
"bJQueryUI": true,
...
"aoColumns": [
...
{
"mData": null,
"mRender": function(data, type, row) {
return $("<div />")
.append($("<button class='detail'>Details</button>"))
.html();
}
}
]
});
$("button.detail").button();
I have a partial view (asp.net MVC 3.0) to render Tinymce as a richeditor and want to show a text watermark on it.
#model String
#using Nop.Web.Framework.UI;
#{
Html.AddScriptParts(#Url.Content("~/Content/editors/tinymce/tiny_mce.js"));
//set useDefaultImagePlugin to 'true' if you want to move back to a standard image plugin
bool useDefaultImagePlugin = false;
var imagePluginName = useDefaultImagePlugin ? "image" : "netadvimage";
}
#Html.TextArea(string.Empty, /* Name suffix */
ViewData.TemplateInfo.FormattedModelValue /* Initial value */
)
<script type="text/javascript">
//Notes: autosave plugin is disabled
(function () {
tinyMCE.init({
// General options
mode: "exact",
elements: "#ViewData.TemplateInfo.GetFullHtmlFieldName(string.Empty)",
theme: "advanced",
height: "120px",
width: "100%",
verify_html: false,
plugins: "equation,netadvimage,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,wordcount,advlist",
// Theme options
theme_advanced_buttons1: "equation,#imagePluginName,|,justifyleft,justifycenter,justifyright,justifyfull,|,link,unlink,|,pastetext",
theme_advanced_buttons2: "",
theme_advanced_buttons3: "",
theme_advanced_toolbar_location: "top",
theme_advanced_toolbar_align: "left",
theme_advanced_resizing: false,
// Example content CSS (should be your site CSS)
//content_css : "css/content.css",
convert_urls: false,
// Drop lists for link/image/media/template dialogs
template_external_list_url: "lists/template_list.js",
external_link_list_url: "lists/link_list.js",
external_image_list_url: "lists/image_list.js",
media_external_list_url: "lists/media_list.js"
});
tinyMCE.focus(function () {
if ($(this).getContent() == "Type some text here") {
tinyMCE.setContent("");
} else if ($(this).getContent() == "") {
tinyMCE.setContent("Type some text here");
}
})
})();
</script>
and i tried to follow a similiar post at TinyMCE hint text as in the above script but it never shows anything on the textarea content.
Even with http://code.google.com/p/jquery-watermark/ , it only flickers the content and get blank instantly.
Thanks
I am using navButtonAdd to have a column chooser in my jqgrid but it adds the button to the bottom navigation bar. Is it possible to add the same icon to the top of my cloned navigation bar. Here is my code...
jQuery("#grid").jqGrid({
......
toppager: true,
....
);
jQuery("#grid").jqGrid('navGrid','#pager',
{cloneToTop: true, edit:false, add:false, del:false, search:false},
{ }, { }, { }, { } );
jQuery("#grid").jqGrid('navButtonAdd', '#pager', {
caption : "",
buttonicon : "ui-icon-calculator",
title : "Choose Columns",
onClickButton : function() {
jQuery("#grid").jqGrid('columnChooser');
}
});
If the toppager will be created it will have the id constructed from the grid id and "_toppager", so it will be "grid_toppager" in your case. So you should use
jQuery("#grid").jqGrid('navButtonAdd', '#grid_toppager', {...});
See here and here for more details and for demos.
For basic functionality, setting the toppager: true and cloneToTop: true would suffice as below.
$("#list").jqGrid({
pager: '#pager',toppager: true
});
$("#list").jqGrid('navGrid',"#pager",{
cloneToTop:true
});