Fire jquery animation when scrolled to - animation

Im using some jquery to animate a bar graph but it is far enough down the page that the user will need to scroll to see it.
How do I set it to animate when the user has scrolled to its location.
arrayOfDataMulti = new Array(
[[936656,556247],'2005'],
[[913318,453238],'2006'],
[[921707,362327],'2007'],
[[894496,376587],'2008'],
[[738624,326656],'2009'],
[[759379,311336],'2010'],
[[746972,332962],'2011'],
[[666210,295708],'2012'],
[[568817,286204],'2013'],
[[548247,315037],'2014']
);
arrayOfDataMultiForSort = new Array(
[[936656,556247],'2005'],
[[913318,453238],'2006'],
[[921707,362327],'2007'],
[[894496,376587],'2008'],
[[738624,326656],'2009'],
[[759379,311336],'2010'],
[[746972,332962],'2011'],
[[666210,295708],'2012'],
[[568817,286204],'2013'],
[[548247,315037],'2014']
);
arrayOfColors = new Array('#006446','#6ebd44');
$('#exampleMulti').jqbargraph({ data: arrayOfDataMulti, colors: arrayOfColors,legends: ['Scope 1 / Direct','Scope 2 / Indirect'],
legend: true });
$('#multiMulti').click(function(){
$('#exampleMulti').html('');
$('#exampleMulti').jqbargraph({ data: arrayOfDataMulti, colors: arrayOfColors, type: 'multi' });
$('#multiDyn').html(",<br /> type: 'multi'");
});
$('#multiLegend').click(function(){
$('#exampleMulti').html('');
$('#exampleMulti').jqbargraph({ data: arrayOfDataMulti, colors: arrayOfColors, legend: true, legends: ['ads','leads','google ads'] });
$('#multiDyn').html(",<br /> legends: ['ads','leads','google ads'],<br /> legend: true");
});
$('#multiSortDesc').click(function(){
$('#exampleMulti').html('');
$('#exampleMulti').jqbargraph({ data: arrayOfDataMultiForSort, colors: arrayOfColors, sort: 'desc' });
$('#multiDyn').html(",<br /> sort: 'desc'");
});
$('#multiPrePost').click(function(){
$('#exampleMulti').html('');
$('#exampleMulti').jqbargraph({ data: arrayOfDataMulti, colors: arrayOfColors, prefix: '$', postfix: 'k' });
$('#multiDyn').html(",<br /> prefix: '$',<br /> postfix: 'k'");
});
$('#multiHideValues').click(function(){
$('#exampleMulti').html('');
$('#exampleMulti').jqbargraph({ data: arrayOfDataMulti, colors: arrayOfColors, showValues: false });
$('#multiDyn').html(",<br /> showValues: false");
});
$('#multiNoAnimate').click(function(){
$('#exampleMulti').html('');
$('#exampleMulti').jqbargraph({ data: arrayOfDataMulti, colors: arrayOfColors, animate: false });
$('#multiDyn').html(",<br /> animate: false");
});
$('#multiClear').click(function(){
$('#exampleMulti').html('');
$('#exampleMulti').jqbargraph({ data: arrayOfDataMulti, colors: arrayOfColors });
$('#multiDyn').html("");
});
</script>

Will this answer serve your purposes?
function isScrolledIntoView(elem)
{
var $elem = $(elem);
var $window = $(window);
var docViewTop = $window.scrollTop();
var docViewBottom = docViewTop + $window.height();
var elemTop = $elem.offset().top;
var elemBottom = elemTop + $elem.height();
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop));
}
If not, there are some other good answers in that thread, including jQuery's $().appear() function.

Related

How to reformat labels chartisan

Heading
<script>
const chart = new Chartisan({
el: '#chart',
url: "#chart('sample_chart')",
hooks: new ChartisanHooks() //labels format
.datasets([{type: 'line', fill: false}, 'bar'])
.legend()
.colors()
.tooltip()
.title('Sample Chart'),
});
</script>
</body>
How can format labels to be vertical in Laravel chartisan? I suppose that this part of the code has to change, but I am not sure.
give this a try
const chart = new Chartisan({
el: '#chart',
url: "#chart('sample_chart')",
hooks: new ChartisanHooks()
.colors()
.responsive()
.beginAtZero()
.legend({ position: 'bottom' })
.datasets([{ type: 'line', fill: true }])
.custom(function ({ data, merge, server }) {
data.options.scales.yAxes = [{
ticks: {
callback: function(value, index, values) {
return '$' + value;
}
}
}]
return data
})
})
For more info visit this link:https://github.com/Chartisan/Chartisan/issues/7

After loading articles, the player script does not work?

my content is loaded using ajax and in some articles I use the jwplayer player, but after the articles are loaded, the player script does not work. Here is the player output code itself
<div id='38'></div>
<script type="text/javascript">
var playerInstance = jwplayer("38");
playerInstance.setup({
file: "https://www.youtube.com/watch?v=WrBLHH3WZ5M",
width: "100%",
height: "100%"
});
</script>
Here is a script for loading articles
jQuery(document).ready(function($) {
var $container = $('#masonry');
$container.infinitescroll({
navSelector : '#navigation',
nextSelector : '#navigation #navigation-next a',
itemSelector : '.item',
maxPage :5,
loading: {
msgText: '<?php _e('Loading', 'prpin') ?>',
finishedMsg: '<?php _e('All items loaded', 'prpin') ?>',
img: '<?php echo get_template_directory_uri(); ?>/img/loading.gif',
}
},
// запускаем Masonry как обратный вызов
function(newElements) {
// скрываем новые элементы во время загрузки
var $newElems = $(newElements).css({
opacity: 0});
// убедитесь, что изображения загружаются перед добавлением в макет кладки
$newElems.imagesLoaded(function() {
// показать элементы, теперь они готовы
$newElems.animate({
opacity: 1});
$container.masonry('appended', $newElems, true);
});
onAfterLoaded($newElems);
}
);
});
Please help me solve this problem, for a long time I can not find a solution

How to disable the cell if the date is empty or null or undefined?

I'm new to jqgrid and jquery, can someone please help me in disabling the cell when the date is null or empty or undefined?
Actually the json for some (rows,col) date data is there and for some it is not there.
I want to disable the cell in the row for which Date data is not available.
grid cell editing POC
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link rel="stylesheet" type="text/css" href="/jqGrid/jquery-ui-1.11.4.custom/jquery-ui.css">
<link rel="stylesheet" type="text/css" href="/jqGrid/Guriddo_jqGrid_JS_5.0.1/css/ui.jqgrid.css">
<script type="text/ecmascript" src="/jqGrid/Guriddo_jqGrid_JS_5.0.1/js/jquery-1.11.0.min.js"></script>
<script type="text/javascript" src="/jqGrid/jquery-ui-1.11.4.custom/jquery-ui.min.js"></script>
<script type="text/javascript" src="/jqGrid/Guriddo_jqGrid_JS_5.0.1/js/i18n/grid.locale-en.js"></script>
<script type="text/javascript">
$.jgrid.useJSON = true;
</script>
<script type="text/javascript" src="/jqGrid/Guriddo_jqGrid_JS_5.0.1/src/jquery.jqGrid.js"></script>
<script type="text/javascript">
$(function () {
"use strict";
var grid = $("#tree");
var initDateWithButton = function (elem) {
var ids = grid.jqGrid('getDataIDs');
for (var i=0;i<ids.length;i++) {
var id=ids[i];
if (grid.jqGrid('getCell',id,'assignedDate') == null) {
grid.jqGrid('setCell',id,'assignedDate','','not-editable-cell');
}
if (grid.jqGrid('getCell',id,'assignedDate') == "") {
grid.jqGrid('setCell',id,'assignedDate','','not-editable-cell');
}
if (grid.jqGrid('getCell',id,'assignedDate') == undefined) {
grid.jqGrid('setCell',id,'assignedDate','','not-editable-cell');
}
}
if (/^\d+%$/.test(elem.style.width)) {
// remove % from the searching toolbar
elem.style.width = '';
}
// to be able to use 'showOn' option of datepicker in advance searching dialog
// or in the editing we have to use setTimeout
setTimeout(function () {
$(elem).datepicker({
dateFormat: 'dd-M-yy',
showOn: 'button',
changeYear: true,
changeMonth: true,
showWeek: false,
showButtonPanel: true,
buttonImage: 'http://rcban0015:10039/GridPOC/pages/calenderIcon.gif',
onClose: function (dateText, inst) {
inst.input.focus();
}
});
$(elem).next('button.ui-datepicker-trigger').button({
text: false,
position: "relative",
top: "4px"
});
}, 100);
},
dateTemplate = {align: 'center', sorttype: 'date', editable: true,
formatter: 'date', formatoptions: { newformat: 'd-M-Y' }, datefmt: 'd-M-Y',
editoptions: { dataInit: initDateWithButton, size: 11 },
searchoptions: {
sopt: ['eq', 'ne', 'lt', 'le', 'gt', 'ge'],
dataInit: initDateWithButton,
size: 11, // for the advanced searching dialog
attr: {size: 11} // for the searching toolbar
}},
lastSel;
jQuery('#tree').jqGrid({
url: '<%= webAppAccess.getBackchannelActionURL("actionListjqGridPagination",false) %>',
"colModel":[
{
"name":"course_id",
"index":"course_id",
"sorttype":"int",
"key":true,
"hidden":true,
"width":50
},{
"name":"courseName",
"index":"courseName",
"sorttype":"string",
"label":"courseName",
"width":200
},{
"name":"facility",
"index":"facility",
"label":"facility",
"width":200,
"align":"left"
},{
"name":"assignedDate",
"index":"assignedDate",
"label":"assignedDate",
"width":110,
"template": dateTemplate
},{
"name":"dueDate",
"index":"dueDate",
"label":"dueDate",
"width":110,
"template": dateTemplate
},
{
"name":"AssignmentStatus",
"index":"AssignmentStatus",
"label":"AssignmentStatus",
"width":50
},{
"name":"Action",
"index":"Action",
"label":"Action",
"width":50
},
{
"name":"lft",
"hidden":true
},{
"name":"rgt",
"hidden":true
},{
"name":"level",
"hidden":true
},{
"name":"uiicon",
"hidden":true
}
],
"jsonReader": { "repeatitems": false, "root": "employees.rows" },
"toolbar": [true, "top"],
"width":"1200",
"hoverrows":false,
"viewrecords":false,
"gridview":true,
"height":"auto",
"sortname":"lft",
"loadonce":true,
"rowNum": 2,
"rowList":[2,10,15],
"scrollrows":true,
// enable tree grid
"treeGrid":true,
// which column is expandable
"ExpandColumn":"courseName",
// datatype
"treedatatype":"json",
// the model used
"treeGridModel":"nested",
// configuration of the data comming from server
"treeReader":{
"left_field":"lft",
"right_field":"rgt",
"level_field":"level",
"leaf_field":"isLeaf",
"expanded_field":"expanded",
"loaded":"loaded",
// set the ui icon field froom data
"icon_field":"uiicon"
},
"sortorder":"asc",
"datatype":"json",
"pager":"#pager",
"cellEdit": true, // TRUE = turns on celledit for the grid.
"cellsubmit" : 'clientArray',
"editurl": 'clientArray'
});
$('#t_' +"tree")
.append($("<div><label for=\"globalSearchText\">Global search in grid for: </label><input id=\"globalSearchText\" type=\"text\"></input> <button id=\"globalSearch\" type=\"button\">Search</button></div>"));
$("#globalSearchText").keypress(function (e) {
var key = e.charCode || e.keyCode || 0;
if (key === $.ui.keyCode.ENTER) { // 13
$("#globalSearch").click();
}
});
$("#globalSearch").button({
icons: { primary: "ui-icon-search" },
text: false
}).click(function () {
var postData = jQuery('#tree').jqGrid("getGridParam", "postData"),
colModel = jQuery('#tree').jqGrid("getGridParam", "colModel"),
rules = [],
searchText = $("#globalSearchText").val(),
l = colModel.length,
i,
cm;
for (i = 0; i < l; i++) {
cm = colModel[i];
if (cm.search !== false && (cm.stype === undefined || cm.stype === "text")) {
rules.push({
field: cm.name,
op: "cn",
data: searchText
});
}
}
postData.filters = JSON.stringify({
groupOp: "OR",
rules: rules
});
jQuery('#tree').jqGrid("setGridParam", { search: true });
jQuery('#tree').trigger("reloadGrid", [{page: 1, current: true}]);
return false;
});
});
</script>
</head>
<body>
<table id="tree"><tr><td></td></tr></table>
<div id="pager"></div>
</body>
</html>
There are exist alternative fork of jqGrid: free jqGrid, which I develop since more as one year. It has the functionality, where one can define editable property of colModel as function, which can return true or false based on the cell or the row content. See the wiki article for more details.
Check if this How to disable editing for soe cells in row editing of JQGrid
helps, it seen it is a similar thing, You just need to add into your logic.

Getting only modified or new Kendo UI Grid rows to send to the server

Although I have tried several times, I could not solve trying many method.
Shortly this is the thing what I want to do : only get modified or new rows as an object or JSON string.
You should use set for changing the content of a record. Then, getting the records modified is just iterating through datasource.data() array and checking which items have dirty set to true.
var data = grid.dataSource.data();
var dirty = $.grep(data, function(item) {
return item.dirty
});
// Dirty array contains those elements modified
console.log("dirty", dirty);
The following snippet shows both that changing the data programmatically or via Grid built-in incell edition is compatible with this approach.
$(document).ready(function() {
var crudServiceBaseUrl = "http://demos.telerik.com/kendo-ui/service",
dataSource = new kendo.data.DataSource({
transport: {
read: {
url: crudServiceBaseUrl + "/Products",
dataType: "jsonp"
},
update: {
url: crudServiceBaseUrl + "/Products/Update",
dataType: "jsonp"
},
destroy: {
url: crudServiceBaseUrl + "/Products/Destroy",
dataType: "jsonp"
},
create: {
url: crudServiceBaseUrl + "/Products/Create",
dataType: "jsonp"
},
parameterMap: function(options, operation) {
if (operation !== "read" && options.models) {
return {models: kendo.stringify(options.models)};
}
}
},
batch: true,
pageSize: 20,
schema: {
model: {
id: "ProductID",
fields: {
ProductID: { editable: false, nullable: true },
ProductName: { validation: { required: true } },
Discontinued: { type: "boolean" }
}
}
}
});
var grid = $("#grid").kendoGrid({
dataSource: dataSource,
navigatable: true,
pageable: true,
height: 300,
columns: [
"ProductName",
{ field: "Discontinued", width: 120 }
],
editable: "incell",
selectable: true
}).data("kendoGrid");
$("#change").on("click", function() {
var sel = grid.select();
if (sel.length) {
var item = grid.dataItem(sel);
item.set("Discontinued", true);
}
});
$("#show").on("click", function() {
var data = grid.dataSource.data();
var dirty = $.grep(data, function(item) {
return item.dirty
});
$("#logger").html(JSON.stringify(dirty, null, 2));
});
});
#logger {
min-height: 60px;
border: 1px solid black;
overflow-x: scroll
}
#grid {
width: 500px;
}
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.common.min.css" />
<link rel="stylesheet" href="http://cdn.kendostatic.com/2014.3.1119/styles/kendo.default.min.css" />
<script src="http://cdn.kendostatic.com/2014.3.1119/js/jquery.min.js"></script>
<script src="http://cdn.kendostatic.com/2014.3.1119/js/kendo.all.min.js"></script>
<div id="example">
<div>
This button changes the Discontinued field to "true" for the selected row:
<button id="change" class="k-button">Change selected</button>
</div>
<div>
Click for displaying modified rows:
<button id="show" class="k-button">Show dirty</button>
<pre id="logger"></pre>
</div>
<div id="grid"></div>
</div>

datepicker in mvc3 with razor engine

I have two datepicker in my view one for "From" and other for "to".
I want when "from" selected date less than "to" should disable.
and also please guide me how to format the view of datePicker
<div>
From:
<input type="text" id="txtFromDate" />
To:
<input type="text" id="txtToDate" />
</div>
$(function() {
$("#txtFromDate").datepicker({
numberOfMonths: 1,
highlightWeek: true,
onSelect: function(selected) {
$("#txtToDate").datepicker("option", "mindate", selected)
}
});
$("#txtToDate").datepicker({
numberOfMonths: 1,
onSelect: function(selected) {
$("#txtFromDate").datepicker("option", "maxDate", selected)
}
});
});
I got the solution...
$(function () {
$("#txtFromDate").datepicker({
changeMonth: true,
changeYear: true,
buttonImage: '../../Images/DatePicker.jpg',
dateFormat: 'dd-mm-yy',
buttonText: 'Select date:',
firstDay: 1,
buttonImageOnly: true,
showOn: 'both',
showAnim: 'fadeIn',
onSelect: function () {
var min = $(this).datepicker('getDate') || new Date(); // Selected date or today if none
var max = new Date(min.getTime());
max.setMonth(max.getMonth() + 12 * 10); // Add one month
$("#txtToDate").datepicker('option', { minDate: min, maxDate: max });
}
});
});
$(function () {
var min = $("#txtFromDate").datepicker('getDate')
$("#txtToDate").datepicker({
changeMonth: true,
changeYear: true,
buttonImage: '../../Images/DatePicker.jpg',
dateFormat: 'dd-mm-yy',
buttonText: 'Select date:',
firstDay: 1,
buttonImageOnly: true,
showOn: 'both',
showAnim: 'fadeIn',
onSelect: function () { $(this).trigger("onchange", null); }
});
});

Resources