Phantom Js image capturing issue - cakephp

I am new to phantom js.I am using phantom js to create an image of a web page. It works fine for normal web pages, but webpages in which the content loads after scrolling are not getting captured properly.
I am using the following code to generate image:
PhantomJs Code (Desktop.js):
var page = require('webpage').create(),
system = require('system'),
address, output, size;
if (system.args.length < 3 || system.args.length > 5) {
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
phantom.exit(1);
} else {
address = system.args[1];
output = system.args[2];
page.viewportSize = { width: 1280, height:200 };
if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
size = system.args[3].split('*');
page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
: { format: system.args[3], orientation: 'portrait', margin: '1cm' };
}
if (system.args.length > 4) {
page.zoomFactor = system.args[4];
}
page.open(address, function (status) {
if (status !== 'success') {
console.log("status: " + status);
console.log('Unable to load the address!');
phantom.exit();
} else {
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 3000);
}
});
}
CakePhp Code:
$phantomjs_path = '/var/www/html/phantomjs/';
$url = 'http://springsummer.dk/'
$img_path = '/var/www/html/application/app/webroot/img/test.png'
$output = exec($phantomjs_path . 'bin/phantomjs --ssl-protocol=any ' . phantomjs_path . 'utilities/Desktop.js ' . $url . ' ' . $img_path );
I have also checked some post on stackoverflow regarding this problem, but they didn't helped.
Code after adding scrolling:
var page = require('webpage').create(),
system = require('system'),
address, output, size;
var height = 0;
if (system.args.length < 3 || system.args.length > 5) {
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
phantom.exit(1);
} else {
address = system.args[1];
output = system.args[2];
page.viewportSize = { width: 1366, height:768 };
if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
size = system.args[3].split('*');
page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
: { format: system.args[3], orientation: 'portrait', margin: '1cm' };
}
if (system.args.length > 4) {
page.zoomFactor = system.args[4];
}
console.log('Opening');
page.open(address, function (status) {
if (status !== 'success') {
console.log("status: " + status);
console.log('Unable to load the address!');
phantom.exit();
} else {
height = page.evaluate(function() {
window.scrollTop = document.body.scrollHeight;
return document.body.scrollHeight;
});
console.log(height);
page.viewportSize = { width: 1366, height: height };
console.log("Height set");
}
});
console.log('2nd');
if(height > 0){
console.log("Reloading...");
page.open(address, function(status){
if (status !== 'success') {
console.log("status: " + status);
console.log('Unable to reload the address!');
phantom.exit();
} else {
console.log("Capturing ...");
window.setTimeout(function () {
page.render(output);
phantom.exit();
}, 3000);
}
});
}
phantom.exit();
}

Related

Highcharts | Network Graph - Is there a way to expand leaf nodes on click of the Parent node?

Highcharts | Network Graph - Is there a way to expand leaf nodes on click of the Parent node?
Sample Code`Highcharts.addEvent(
Highcharts.Series,
'afterSetOptions',
function (e) {
var colors = Highcharts.getOptions().color
i = 0,
nodes = {};
if (
this instanceof Highcharts.seriesTypes.networkgraph &&
e.options.id === 'lang-tree'
) {
e.options.data.forEach(function (link) {
if (link[0] === 'Parent') {
nodes['Parent'] = {
id: 'Parent',
marker: {
radius: 20
}
};
nodes[link[1]] = {
id: link[1],
marker: {
radius: 10
},
color: colors[i++]
};
} else if (nodes[link[0]] && nodes[link[0]].color) {
nodes[link[1]] = {
id: link[1],
color: nodes[link[0]].color
};
}
});
e.options.nodes = Object.keys(nodes).map(function (id) {
return nodes[id];
});
}
}
);`
Currently, this feature is not available to achieve from the API options without any customization.
Please take a look at this demo where you can find some custom functions to collapse the child nodes on the click event: https://jsfiddle.net/BlackLabel/9mv0ny3j/
point: {
events: {
click: function() {
var point = this;
point.linksFrom.forEach(link => {
if (link.toNode.isHidden) {
link.graphic.show();
link.toNode.graphic.css({
opacity: 1
});
link.toNode.dataLabel.css({
opacity: 1
})
link.toNode.isHidden = false;
} else {
link.graphic.hide();
link.toNode.graphic.css({
opacity: 0
});
link.toNode.dataLabel.css({
opacity: 0
})
link.toNode.isHidden = true;
}
})
}
}
},
API: https://api.highcharts.com/highcharts/series.line.events.click

Dots persist on D3 graph for angularjs

I am using NVD3 for my graphs and I have this issue where the dots that show up on hover will start to persist as you over over the line. Does anyone have any idea on how to make sure these disappear when the move moves away from them?
Here is the component:
;(function() {
angular.module('canopy.common.components.largeStandardChart')
.component('largeStandardChart', {
templateUrl: 'app/common/components/chart-components/large-standard-chart/large-standard-chart.html',
controller: LargeStandardChartController,
controllerAs: 'vm',
bindings: {
kpi: "<",
updateGraph: '=',
frequency: '<'
}
});
LargeStandardChartController.$inject = ['$rootScope', 'BanyanUtilsService', 'ConfigurationService', '$timeout'];
function LargeStandardChartController($rootScope, UtilsService, CS, $timeout) {
var vm = this;
vm.kpiTrend = [];
vm.kpiTargetTrend = [];
vm.kpiProjectedTrend = [];
vm.predictedDate = null;
var allTrends = vm.kpi.trend.length && vm.kpi.trend[0].values.length ? vm.kpi.trend[0].values : [];
vm.chart = {
chartOptions: {
chart: {
type: 'lineChart',
height: 250,
area: CS.getOrgConfig().graph.general.fillArea,
margin : {
top: 15,
right: 40,
bottom: 50,
left: 70
},
x: (function(d) { return d.time }),
y: (function(d) { return d.value }),
clipVoronoi: false,
xAxis: {
showMaxMin: false,
staggerLabels: vm.frequency === 'DAY' ? false : true,
tickFormat: function(d) {
return vm.frequency === 'DAY'
? d3.time.format(CS.getOrgConfig().dateTime.d3DateFormat)(new Date(d))
: d3.time.format(CS.getOrgConfig().dateTime.d3DateTimeFormat)(new Date(d));
}
},
yAxis: {
showMaxMin: true,
tickFormat: function (d) {
return vm.kpi.kpiMeasure === 'NUMBER' && d ? d.toFixed(1) : UtilsService.getFormattedData(d, vm.kpi.kpiMeasure);
}
},
tooltip: {
hideDelay: 0
},
showXAxis: CS.getOrgConfig().graph.xAxis.showXAxis,
showYAxis: CS.getOrgConfig().graph.yAxis.showYAxis,
showLegend: false,
transitionDuration: 350,
useInteractiveGuideline: false
}
}
};
vm.$onInit = function() {
if(vm.updateGraph) { vm.updateGraph.handler = vm.updateGraphData; }
if (!vm.kpi) { vm.kpi = { trend: vm.kpiTrend, kpiMeasure: "PERCENTAGE" } }
setTrends();
d3.select(window).on('mouseout', function () {
d3.selectAll('.nvtooltip').style('opacity', '0');
});
};
function setTrends() {
_.set(vm.chart, 'chartData', []);
vm.kpiTrend = [];
vm.kpiProjectedTrend = [];
_.forEach(allTrends, function(kpi) {
if (_.has(kpi, 'predict')) {
vm.kpiProjectedTrend.push(kpi);
} else {
if (CS.getOrgConfig().graph.general.showNullValues) {
vm.kpiTrend.push(kpi);
} else {
if (kpi.value) { vm.kpiTrend.push(kpi) }
}
}
});
if (!vm.kpi.hideTarget && !vm.kpiProjectedTrend.length) {
vm.chart.chartData.push({
key: CS.getOrgConfig().labels.target.single,
classed: "dashed",
color: $rootScope.branding.canopyBrandColor,
seriesIndex: 2,
strokeWidth: 1,
values: getTargetValues()
});
}
if (vm.kpiTrend.length) {
vm.chart.chartData.push({
key: 'Value',
classed: "solid",
area: CS.getOrgConfig().graph.general.fillArea,
color: $rootScope.branding.canopyBrandColor,
seriesIndex: 0,
strokeWidth: 2,
values: vm.kpiTrend
});
}
if (vm.kpiProjectedTrend.length) {
vm.chart.chartOptions.chart.useInteractiveGuideline = false;
var lastCurrentValue = angular.copy(vm.kpiTrend).pop();
var firstPredictedValue = angular.copy(vm.kpiTrend).pop();
vm.kpiProjectedTrend.unshift(firstPredictedValue);
vm.endDate = moment.unix(allTrends[ allTrends.length - 1 ].time / 1000).format(CS.getOrgConfig().dateTime.dateFormat); // Divide by 1000 for miliseconds coming from server
vm.chart.chartData.push({
key:'Projected',
classed: "dashed",
color: $rootScope.branding.canopyBrandColor,
strokeWidth: 1,
seriesIndex: 3,
values: vm.kpiProjectedTrend
});
var top = 0, bottom = 0;
if (allTrends.length) {
var top = _.maxBy(allTrends, function(tr) { return tr.value }).value;
var bottom = _.minBy(allTrends, function(tr) { return tr.value }).value;
}
var yTop = vm.kpi.kpiMeasure === 'PERCENTAGE' ? 103 : top + ((top - bottom) * 0.07);
var yBottom = vm.kpi.kpiMeasure === 'PERCENTAGE' ? 0 : bottom - ((top - bottom) * 0.04);
vm.chart.chartData.push({
classed: "solid",
strokeWidth: 1,
seriesIndex: 4,
values: [
{time: lastCurrentValue.time, value: yTop},
{time: lastCurrentValue.time, value: yBottom},
],
color: '#ff0005'
});
}
setDomain();
}
function setDomain () {
var top = 0, bottom = 0;
if (allTrends.length) {
top = _.maxBy(allTrends, function(tr) { return tr.value }).value;
bottom = _.minBy(allTrends, function(tr) { return tr.value }).value;
}
bottom = bottom < 1 && bottom > 0 ? 0 : bottom;
if (top === bottom) { bottom = top - bottom; }
if (top + bottom === 0) { top = 1; }
var yTop = vm.kpi.kpiMeasure === 'PERCENTAGE' ? 103 : top + ((top - bottom) * 0.05);
var yBottom = vm.kpi.kpiMeasure === 'PERCENTAGE' ? 0 : bottom - ((top - bottom) * 0.05);
vm.chart.chartOptions.chart.yDomain = [yBottom, yTop];
}
vm.updateGraphData = function(trend) {
allTrends = trend.length && trend[0].values.length ? trend[0].values : [];
setTrends();
vm.api.updateWithOptions(vm.chart.chartOptions);
vm.api.updateWithData(trend);
vm.api.refresh();
};
function getTargetValues() {
var trend = angular.copy(allTrends);
_.forEach(trend, function(t) {
t.value = vm.kpi.targetValue;
});
return trend;
}
}
})();
and here is what it looks like when I hover:
For anyone having this issue I have finally found the solution. I had to add a listener on the mouseout event and remove the hover class that is added to the .nv-point which is the dot. It looks like this:
d3.select(window).on('mouseout', function () {
d3.selectAll('.nv-point').classed('hover', false);
});

Load from JSON with dynamic patterns, patternSourceCanvas is not defined error return by the serialize JSON data

I am trying to save Fabric.js canvas and reload it using loadFromJson. But I am getting error patternSourceCanvas is not defined. I thought I should make it global so I removed var.
How to set the global variable in Fabric JS and use var patternSourceCanvas?
When I use the code below, then everything is working fine and the JSON is loaded easily.
var t = https://image.freepik.com/free-photo/roof-texture_21206171.jpg
fabric.util.loadImage(t, function(t) {
var svg_width = i.width;
console.log('svg widh' + i.width + 'svg height' + i.height);
console.log('img width t'+ t.width + ' img height' + t.height);
if(svg_width >= 300){
if (i.isSameColor && i.isSameColor() || !i.paths) {
i.setPatternFill({
source: t, repeat: 'repeat', offsetX:200 , offsetY : -110 // working
}), e.fabric.renderAll();
console.log('in if image 300 up ', t);
} else if (i.paths){
for (var r = 0; r < i.paths.length; r++)
i.paths[r].setPatternFill({
source: t, repeat: 'repeat' , offsetX: -100 , offsetY:-110
}), e.fabric.renderAll();
console.log('in image elseeee 300 up ', t);
}
}
})
But when I fill some other new shape with the new patternSourceCanvas variable then it's not working. Kindly help me with dynamic patterns.
var t = https://image.freepik.com/free-photo/roof-texture_21206171.jpg
fabric.Image.fromURL(t, function (img) {
img.scaleToHeight(200);
var patternSourceCanvas = new fabric.StaticCanvas();
patternSourceCanvas.add(img);
patternSourceCanvas.renderAll();
var pattern = new fabric.Pattern({
source: function() {
patternSourceCanvas.setDimensions({
width: img.getScaledWidth() ,
height: img.getScaledHeight()
});
patternSourceCanvas.renderAll();
return patternSourceCanvas.getElement();
},
repeat: r
});
console.log('pattern', pattern);
//p.set('fill', pattern);
canvas.renderAll();
if (i.isSameColor && i.isSameColor() || !i.paths) {
i.setPatternFill(pattern);
} else if(i.paths) {
for (var r = 0; r < i.paths.length; r++) {
i.paths[r].setPatternFill(pattern);
}
}
e.fabric.renderAll();
});
You need to put patternSourceCanvas to global scope/ scope where loadFromJSON can access patternSourceCanvas. Else you can use cors enabled image directly.
DEMO
var imageUrl = 'https://upload.wikimedia.org/wikipedia/commons/2/22/Wikimapia_logotype.svg';
var canvas = new fabric.Canvas('canvas');
var rect = new fabric.Rect({
width: 200,
height: 200,
strokeWidth: 2,
stroke: '#000'
})
canvas.add(rect);
fabric.Image.fromURL(imageUrl, function(img) {
img.scaleToHeight(200);
var patternSourceCanvas = new fabric.StaticCanvas();
patternSourceCanvas.add(img);
patternSourceCanvas.setDimensions({
width: img.getScaledWidth(),
height: img.getScaledHeight()
});
patternSourceCanvas.renderAll();
var pattern = new fabric.Pattern({
source: patternSourceCanvas.getElement()
},
function(patternObj) {
rect.fill = patternObj;
rect.dirty = true;
canvas.renderAll();
});
}, {
crossOrigin: 'annonymous'
});
function loadfromjson() {
var json = canvas.toJSON();
canvas.clear();
setTimeout(function() {
canvas.loadFromJSON(json, canvas.renderAll.bind(canvas));
}, 1000)
}
canvas{
border:2px solid #000;
}
<canvas id="canvas" width="300" height="300"></canvas><br>
<button onclick="loadfromjson()">loadfromjson </button>
<script src='https://rawgit.com/kangax/fabric.js/master/dist/fabric.js'></script>

How to update event source object to particular event source in full calendar dynamically

Hello I have loaded one calendar using below code.
dataFactory.httpRequest('getCalanderTaskData','GET').then(function(data) {
$scope.taskCalanderDailyTask = data.dailyTask;
$scope.taskCalanderDueTask = data.dueTask;
$scope.fullCalendarEventSources = {
dailyTask : {
events:$scope.taskCalanderDailyTask,
textColor : '#000',
backgroundColor: '#FFD000',
},
dueTask : {
events:$scope.taskCalanderDueTask,
textColor : '#fff',
backgroundColor: '#da1445',
}
};
$('#fullcalendar').fullCalendar({
eventClick: function(calEvent, jsEvent, view) {
},
eventMouseover: function(calEvent, jsEvent, view) {
var tooltip = '<div class="tooltipevent" style="color:#fff;width:100px;height:50px;background:#125688;position:absolute;z-index:10001;">' + calEvent.title + '</div>';
var $tooltip = $(tooltip).appendTo('body');
$(this).mouseover(function(e) {
$(this).css('z-index', 10000);
$tooltip.fadeIn('500');
$tooltip.fadeTo('10', 1.9);
}).mousemove(function(e) {
$tooltip.css('top', e.pageY + 10);
$tooltip.css('left', e.pageX + 20);
});
},
eventMouseout: function(calEvent, jsEvent) {
$(this).css('z-index', 8);
$('.tooltipevent').remove();
},
eventLimit: 3,
eventSources: [$scope.fullCalendarEventSources.dailyTask, $scope.fullCalendarEventSources.dueTask],
});
});
Above code load first time calendar now when any new task going to added I want to refresh calendar event source without reload page.
Below is the code for saveTask Inside that I have written code for dynamic event source which also remove source and added source but it not update newly added tasks.
$scope.saveTask = function(){
$scope.form.taskLeadId = $scope.leadId;
$scope.form.taskId = $scope.editTaskId;
if($scope.form.taskLeadId != "undefined" && $scope.form.taskLeadId != "")
{
dataFactory.httpRequest('taskCreate','POST',{},$scope.form).then(function(data) {
if(data.status == 1)
{
alertify.notify(data.message, 'success', 5, function(){});
$scope.addTask.$setPristine();
$scope.addTask.$setUntouched();
$scope.form = {};
$(".modal").modal("hide");
getDailyTaskData();
getCalanderTaskData();
console.log("updateed=="+$scope.taskCalanderDailyTask);
$scope.fullCalendarEventSources = {
dailyTask : {
events:$scope.taskCalanderDailyTask,
textColor : '#000',
backgroundColor: '#FFD000',
},
dueTask : {
events:$scope.taskCalanderDueTask,
textColor : '#fff',
backgroundColor: '#da1445',
}
};
$timeout(function () {
$('#fullcalendar').fullCalendar('removeEventSource',$scope.fullCalendarEventSources.dailyTask);
console.log("updateed=="+$scope.taskCalanderDailyTask);
$('#fullcalendar').fullCalendar('addEventSource',$scope.fullCalendarEventSources.dailyTask);
$('#fullcalendar').fullCalendar('refetchEventSources',$scope.fullCalendarEventSources.dailyTask);
$('#fullcalendar').fullCalendar('rerenderEvents');
$('#fullcalendar').fullCalendar('refetchEvents');
$('#fullcalendar').fullCalendar('refresh');
$('#fullcalendar').fullCalendar('updateEvents',$scope.fullCalendarEventSources.dailyTask);
$('#fullcalendar').fullCalendar('rerenderEvents');
$('#fullcalendar').fullCalendar('refetchEvents');
$('#fullcalendar').fullCalendar('refresh');
console.log("after update==");
});
//alertify.alert('Task', 'Congratulations your task is created successfully!');
}
else
{
if($scope.editTask = "edit")
{
alertify.alert('Task Update','Nothing is updated');
}
else
{
alertify.alert('Error', data.message,function(){ alertify.error(data.message)});
$(".modal").modal("hide");
}
}
});
}
else
{
alertify.alert('Error', 'There must be something went wrong please try again later');
$(".modal").modal("hide");
}
}
Any one please help on this.

how to deselect all selected row in multi select using ngListSelect dependency?

I am using ngListSelect dependency for output like
http://nidhishkrishnan.github.io/ngListSelect/
Here is the custom directive:
(function(window, angular, undefined) { 'use strict'; angular.module('ngListSelect', [])
.run(['$templateCache',
function($templateCache) {
var addRemoveHtml =
"<div class='ngListSelect container' style='margin-left: 0;' ng-style='containerStyle'>" +
"<div style='float:left; width:40%'>" +
"<div ng-style='panelCssStyle' ng-class='panelClass' class='panel'>" +
"<div class='panel-heading' ng-style='panelCssStyle' ng-class='panelClass'><b><span ng-bind='availableText'></span></b></div>" +
"<select size='9' ng-style='dropdownStyle' style='width: 100%; vertical-align: top; color: black;' ng-model='leftMouseSelectedItems' ng-options='{{leftSelectNgOption}}' ng-dblclick='addItemsToRight()' multiple></select>" +
"</div>" +
"</div>" +
"<div style='display: inline-block; width: 20%; text-align: center'>" +
"<br/>" +
"<button ng-click='addItemsToRight()' ng-class='buttonClass' ng-style='buttonCssStyle' class='btn' style='width:60px; height: 34px; line-height: 17px; vertical-align:middle;outline:none !important;margin-bottom:7px'><span style='font-size:25px;'>→</span>" +
"</button>" +
"<br/>" +
"<button ng-click='addItemsToLeft()' ng-class='buttonClass' ng-style='buttonCssStyle' class='btn' style='width:60px; height: 34px; line-height: 17px; vertical-align:middle;outline:none !important;margin-bottom:7px'><span style='font-size:25px;'>←</span>" +
"</button>" +
"<br/>" +
"<button ng-click='addAllItemsToRight()' ng-class='buttonClass' ng-style='buttonCssStyle' class='btn' style='width:60px; height: 34px; line-height: 17px; vertical-align:middle;outline:none !important;margin-bottom:7px'><span style='font-size:30px;'>⇉</span>" +
"</button>" +
"<br/>" +
"<button ng-click='addAllItemsToLeft()' ng-class='buttonClass' ng-style='buttonCssStyle' class='btn' style='width:60px; height: 34px; line-height: 17px; vertical-align:middle;outline:none !important;margin-bottom:7px'><span style='font-size:30px;'>⇇</span>" +
"</button>" +
"<br/>" +
"</div>" +
"<div style='float: right; width: 40%'>" +
"<div ng-style='panelCssStyle' ng-class='panelClass' class='panel'>" +
"<div class='panel-heading' ng-style='panelCssStyle' ng-class='panelClass'><b><span ng-bind='selectedText'></span></b></div>" +
"<select size='9' ng-style='dropdownStyle' style='width: 100%; vertical-align: top; color: black;' id='selectedlist' ng-model='rightMouseSelectedItems' ng-options='{{rightSelectNgOption}}' ng-dblclick='addItemsToLeft()' multiple></select>" +
"</div>" +
"<div style='float: left; margin-left:13%;'>" +
"<button ng-disabled='isSelectedOptionDisabled' ng-click='addItemsToTop()' ng-class='buttonClass' ng-style='buttonCssStyle' class='btn' style='width:60px; height: 34px; line-height: 17px; outline:none !important;margin-bottom:7px;'><span style='font-size:25px;'>↑</span>" +
"</button>" +
"</div>" +
"<div style='float: left; margin-left:5%;'>" +
"<button ng-disabled='isSelectedOptionDisabled' ng-click='addItemsToDown()' ng-class='buttonClass' ng-style='buttonCssStyle' class='btn' style='width:60px; height: 34px; line-height: 17px; outline:none !important;margin-bottom:7px;'><span style='font-size:25px;'>↓</span>" +
"</button>" +
"</div>" +
"<div style='float: left; margin-left:5%;'>" +
"<button ng-disabled='isSelectedOptionDisabled' title='Ascending/ Descending' ng-click='setAscendingDescendingOrder()' ng-class='buttonClass' ng-style='buttonCssStyle' class='btn' style='padding-top: 0px; border-top-width: 1px; padding-bottom: 8px; width:100%; height: 34px; line-height: 17px; outline:none !important;margin-bottom:7px;'><div ng-style='letterStyle.mainContainer' style='position:relative'><div ng-style='letterStyle.letterDarkblue' style='position:absolute;top:
-3px;'>{{topLetter}}</div><div ng-style='letterStyle.letterCrimson' style='position:absolute;padding-top: 10px; padding-bottom: 0px;'>{{bottomLetter}}</div><div ng-style='letterStyle.arrow' style='padding-left: 7px;'>↓</div></div>" +
"</button>" +
"</div>" +
"</div>" +
"</div>";
$templateCache.put("ngListSelect.html", addRemoveHtml);
}
])
.directive('ngListSelect', ['$filter',
function($filter) {
return {
restrict: 'E',
replace: true,
scope: {
selectedListItems: "=selectedList",
availableListItems: "=availableList",
key: "#key",
buttonStyle: "#buttonStyle",
panelStyle: "#panelStyle",
height: "#height",
width: "#width",
availableLabel: "#availableLabel",
selectedLabel: "#selectedLabel"
},
templateUrl: 'ngListSelect.html',
compile: function(tElem, tAttrs) {
return {
pre: function(scope, iElem, iAttrs) {
scope.availableText = angular.isUndefined(scope.availableLabel) ? 'Available' : scope.availableLabel;
scope.selectedText = angular.isUndefined(scope.selectedLabel) ? 'Selected' : scope.selectedLabel;
scope.height = angular.isUndefined(scope.height) ? '144px' : scope.height;
scope.width = angular.isUndefined(scope.width) ? '640px' : scope.width;
scope.buttonStyle = angular.isUndefined(scope.buttonStyle) ? 'alpha' : scope.buttonStyle;
scope.buttonClass = getColor(scope.buttonStyle, 'button');
scope.panelStyle = angular.isUndefined(scope.panelStyle) ? 'alpha' : scope.panelStyle;
scope.panelClass = getColor(scope.panelStyle, 'panel');
scope.leftMouseSelectedItems = [];
scope.rightMouseSelectedItems = [];
scope.dropdownStyle = {
height: scope.height
};
scope.containerStyle = {
width: scope.width
};
scope.ascendingOrderFlag = true;
scope.topLetter = 'A';
scope.bottomLetter = 'Z';
scope.letterStyle = {
mainContainer:{"width":"10px","line-height":"9px"},
letter:{"font-size":"10px","float":"left","font-weight":"600","font-family":"sans-serif"},
letterCrimson:{"font-size":"10px","float":"left","font-weight":"600","font-family":"sans-serif", "color":"crimson"},
letterDarkblue:{"font-size":"10px","float":"left","font-weight":"600","font-family":"sans-serif", "color":"darkblue"},
arrow:{"font-size":"25px"}
};
if (scope.availableListItems[0] instanceof Object) {
scope.leftSelectNgOption = "item as item." + scope.key + " for item in availableListItems | orderBy:'" + scope.key + "'";
scope.rightSelectNgOption = "item as item." + scope.key + " for item in selectedListItems";
scope.availableListItems = getUnique(scope.availableListItems, scope.key);
}
else {
scope.leftSelectNgOption = "item as item for item in availableListItems | orderBy:'toString()'";
scope.rightSelectNgOption = "item as item for item in selectedListItems";
scope.availableListItems = getUnique(scope.availableListItems);
}
function getColor(colorClass, type) {
var data = {}, color = {};
switch (colorClass) {
case 'pearl':
type === 'button' ? (data['btn-default'] = true) : (data['panel-default'] = true);
break;
case 'blue':
type === 'button' ? (data['btn-primary'] = true) : (data['panel-primary'] = true);
break;
case 'alpha':
color = {};
color['background-color'] = 'hsl(193, 32%, 49%) !important';color['background-repeat'] = 'repeat-x';color['filter'] = 'progid:DXImageTransform.Microsoft.gradient(startColorstr="#b8d3da", endColorstr="#5493a4")';color['background-image'] = '-khtml-gradient(linear, left top, left bottom, from(#b8d3da), to(#5493a4))';color['background-image'] = '-moz-linear-gradient(top,
#b8d3da, #5493a4)';color['background-image'] = '-ms-linear-gradient(top, #b8d3da, #5493a4)';color['background-image']
= '-webkit-gradient(linear, left top, left bottom, color-stop(0%, #b8d3da), color-stop(100%, #5493a4))';color['background-image'] = '-webkit-linear-gradient(top, #b8d3da,
#5493a4)';color['background-image'] = '-o-linear-gradient(top, #b8d3da, #5493a4)';color['background-image'] = 'linear-gradient(#b8d3da, #5493a4)';color['border-color'] = '#5493a4
#5493a4 hsl(193, 32%, 41.5%)';color['color'] = '#333 !important';color['text-shadow'] = '0 1px 1px rgba(255, 255, 255,
0.49)';color['-webkit-font-smoothing'] = 'antialiased';
type === 'button' ? (scope.buttonCssStyle = color) : (scope.panelCssStyle = color);
break;
case 'sand':
color = {};
color['background-color'] = 'hsl(33, 32%, 49%) !important';color['background-repeat'] = 'repeat-x';color['filter'] = 'progid:DXImageTransform.Microsoft.gradient(startColorstr="#dacbb8", endColorstr="#a48054")';color['background-image'] = '-khtml-gradient(linear, left top, left bottom, from(#dacbb8), to(#a48054))';color['background-image'] = '-moz-linear-gradient(top,
#dacbb8, #a48054)';color['background-image'] = '-ms-linear-gradient(top, #dacbb8, #a48054)';color['background-image']
= '-webkit-gradient(linear, left top, left bottom, color-stop(0%, #dacbb8), color-stop(100%, #a48054))';color['background-image'] = '-webkit-linear-gradient(top, #dacbb8,
#a48054)';color['background-image'] = '-o-linear-gradient(top, #dacbb8, #a48054)';color['background-image'] = 'linear-gradient(#dacbb8, #a48054)';color['border-color'] = '#a48054
#a48054 hsl(33, 32%, 41.5%)';color['color'] = '#333 !important';color['text-shadow'] = '0 1px 1px rgba(255, 255, 255,
0.49)';color['-webkit-font-smoothing'] = 'antialiased';
type === 'button' ? (scope.buttonCssStyle = color) : (scope.panelCssStyle = color);
break;
case 'olive':
color = {};
color['background-color'] = 'hsl(89, 32%, 49%) !important';color['background-repeat'] = 'repeat-x';color['filter'] = 'progid:DXImageTransform.Microsoft.gradient(startColorstr="#cadab8", endColorstr="#7ea454")';color['background-image'] = '-khtml-gradient(linear, left top, left bottom, from(#cadab8), to(#7ea454))';color['background-image'] = '-moz-linear-gradient(top,
#cadab8, #7ea454)';color['background-image'] = '-ms-linear-gradient(top, #cadab8, #7ea454)';color['background-image']
= '-webkit-gradient(linear, left top, left bottom, color-stop(0%, #cadab8), color-stop(100%, #7ea454))';color['background-image'] = '-webkit-linear-gradient(top, #cadab8,
#7ea454)';color['background-image'] = '-o-linear-gradient(top, #cadab8, #7ea454)';color['background-image'] = 'linear-gradient(#cadab8, #7ea454)';color['border-color'] = '#7ea454
#7ea454 hsl(89, 32%, 41.5%)';color['color'] = '#333 !important';color['text-shadow'] = '0 1px 1px rgba(255, 255, 255,
0.49)';color['-webkit-font-smoothing'] = 'antialiased';
type === 'button' ? (scope.buttonCssStyle = color) : (scope.panelCssStyle = color);
break;
default:
data[colorClass] = true;
}
return data;
}
function getUnique(array, key) {
if (array[0] instanceof Object) {
var object = {};
for (var i = 0; i < array.length; i++){
object[array[i][key]] = array[i];
}
array = [];
for (var objKey in object) {
array.push(object[objKey]);
}
return array;
} else {
return array.sort().filter(function(item, pos, ary) {
return !pos || item != ary[pos - 1];
});
}
}
function orderSelections() {
if (scope.selectedListItems[0] instanceof Object) {
scope.selectedListItems = $filter('orderBy')(scope.selectedListItems, scope.key);
}
else {
scope.selectedListItems = $filter('orderBy')(scope.selectedListItems, 'toString()');
}
}
scope.setAscendingDescendingOrder = function() {
if(scope.ascendingOrderFlag) {
scope.topLetter = 'Z';
scope.bottomLetter = 'A';
scope.ascendingOrderFlag = false;
if (scope.selectedListItems[0] instanceof Object) {
scope.selectedListItems = setOrdering(scope.key, true);
}
else {
scope.selectedListItems = setOrdering('toString()', true);
}
}
else {
scope.topLetter = 'A';
scope.bottomLetter = 'Z';
scope.ascendingOrderFlag = true;
if (scope.selectedListItems[0] instanceof Object) {
scope.selectedListItems = setOrdering(scope.key, false);
}
else {
scope.selectedListItems = setOrdering('toString()', false);
}
}
};
function setOrdering(orderVariable, reverse) {
return $filter('orderBy')(scope.selectedListItems, orderVariable, reverse);
}
scope.addItemsToRight = function() {
angular.forEach(scope.leftMouseSelectedItems, function(leftMouseSelectedItem, key) {
scope.selectedListItems.push(leftMouseSelectedItem);
angular.forEach(scope.availableListItems, function(availableListItem, index) {
if (scope.availableListItems[0] instanceof Object) {
if (availableListItem[scope.key] === leftMouseSelectedItem[scope.key]) {
scope.availableListItems.splice(index, 1);
}
} else {
if (availableListItem === leftMouseSelectedItem) {
scope.availableListItems.splice(index, 1);
}
}
});
});
scope.leftMouseSelectedItems = [];
orderSelections();
setSelectedOptionDisabledEnabled();
};
scope.addAllItemsToRight = function() {
angular.forEach(scope.availableListItems, function(availableListItem, key) {
scope.selectedListItems.push(availableListItem);
});
scope.availableListItems = [];
scope.leftMouseSelectedItems = [];
orderSelections();
setSelectedOptionDisabledEnabled();
};
scope.addItemsToLeft = function() {
angular.forEach(scope.rightMouseSelectedItems, function(rightMouseSelectedItem, key) {
scope.availableListItems.push(rightMouseSelectedItem);
angular.forEach(scope.selectedListItems, function(selectedListItem, index) {
if (scope.availableListItems[0] instanceof Object) {
if (selectedListItem[scope.key] === rightMouseSelectedItem[scope.key]) {
scope.selectedListItems.splice(index, 1);
}
} else {
if (selectedListItem === rightMouseSelectedItem) {
scope.selectedListItems.splice(index, 1);
}
}
});
});
scope.rightMouseSelectedItems = [];
setSelectedOptionDisabledEnabled();
};
scope.addAllItemsToLeft = function() {
angular.forEach(scope.selectedListItems, function(selectedListItem, key) {
scope.availableListItems.push(selectedListItem);
});
scope.selectedListItems = [];
scope.rightMouseSelectedItems = [];
setSelectedOptionDisabledEnabled();
};
function setSelectedOptionDisabledEnabled() {
scope.isSelectedOptionDisabled = scope.selectedListItems.length<=0;
}
scope.addItemsToTop = function() {
var prevIndex = -1;
angular.forEach(scope.rightMouseSelectedItems, function(rightMouseSelectedItem, key) {
var itemIndex = scope.selectedListItems.indexOf(rightMouseSelectedItem);
if (itemIndex - 1 === prevIndex) {
prevIndex = itemIndex;
} else if (itemIndex > 0) {
var itemToMove = scope.selectedListItems.splice(itemIndex, 1);
scope.selectedListItems.splice(itemIndex - 1, 0, itemToMove[0]);
}
});
};
scope.addItemsToDown = function() {
var prevIndex = scope.selectedListItems.length;
angular.forEach(scope.rightMouseSelectedItems.concat().reverse(), function(rightMouseSelectedItem, key) {
var itemIndex = scope.selectedListItems.indexOf(rightMouseSelectedItem);
if (itemIndex + 1 === prevIndex) {
prevIndex = itemIndex;
} else if (itemIndex < scope.selectedListItems.length - 1) {
var itemToMove = scope.selectedListItems.splice(itemIndex, 1);
scope.selectedListItems.splice(itemIndex + 1, 0, itemToMove[0]);
}
});
};
setSelectedOptionDisabledEnabled();
}
};
}
};
} ]); })(window, window.angular);
now i am trying to add one anchor tag deselectall on both left and
right side and i made two function in the directive for that as
scope.deselectrightall = function(slt) {
scope.selectedListItems.slt=[];
};
scope.deselectleftall = function(av) {
scope.availableListItems.av=[];
};
slt is right side multi select data & av is left side multi select data. but this function does not work for me
Please Help Me...
You should change your code to this.
$scope.checkAll = function () {
if ($scope.selectedAll) {
$scope.selectedAll = true;
} else {
$scope.selectedAll = false;
}
angular.forEach($scope.Items, function (item) {
item.Selected = $scope.selectedAll;
});

Resources