Resizeable but not draggable in draw2dTouch - javascript

I have tried somthing like this in draw2dTouch:
this.setSelectable(true);
this.setDraggable(false);
this.setResizeable(true);
but the behaviour is not expected as it should be. So please check if this is the library bug due to new release. Because I think in previous version it is not like that.
Thanks in advance.Please help me in it I am stuck in it.

I also had the problem.
It seems to be a bug. I added this line "this.mouseDownElement = figure;" to SingleSelectionPolicy.js as below to fix the problem.
if (figure !== canvas.getSelection().getPrimary() && figure !== null && figure.isSelectable() === true) {
this.select(canvas,figure);
// its a line
if (figure instanceof draw2d.shape.basic.Line) {
if (!(figure instanceof draw2d.Connection)) {
canvas.draggingLineCommand = figure.createCommand(new draw2d.command.CommandType(draw2d.command.CommandType.MOVE));
if (canvas.draggingLineCommand !== null) {
canvas.draggingLine = figure;
}
}
//added to fix Draw2D draggable = false bug
this.mouseDownElement = figure;
}
else if (canDragStart === false) {
figure.unselect();
}
}

Related

Checkbox manipulation with javascript/jquery

Hello I have a problem with checkboxes in my app.
I want to set value of layer visibility to false when other layer visibility is true and also set checkbox value to checked when visibility of layer is true. I have problem with .click function - console throws me typeError checkbox[i].click is not a function.
var changeLayer = function() {
if (layers[0].M.visible == true) {
layers[1].M.visible == false
} else if (layers[0].M.visible == false) {
layers[1].M.visible == true
}
if (layers[1].M.visible == true) {
layers[0].M.visible == false
} else if (layers[1].M.visible == false) {
layers[0].M.visible == true
}
}
var checkbox = $('.layer');
for (i = 0; i < checkbox.length; i++) {
checkbox[i].click(changeLayer);
//$(checkbox[i]).on('click', changeLayer)
}
Here is image of layer switcher where after click on first layer, second one should hide and uncheck the box.
I know that is maybe silly question, but I couldn't find solution. I hope you can help me.
Your code looks fine, but you could simplify it quite a bit. The following will bind the same event to all elements with the class 'layer'.
$('.layer').click(changeLayer);
We'll probably need some more context to provide better solutions. As an FYI .click(someHandler) is just a shortcut for .on('click', someHandler), they are the same.

Message appears twice using Skype SDK chat

i used skype sdk Here and here is my code snippet after
config.conversation.historyService.activityItems.added(function(newMsg) {
if(typeof newMsg.direction != 'function') {} else {
if(newMsg.direction() == 'Incoming') {
direction = "black";
} else if(newMsg.direction() == 'Outgoing' && newMsg.status() === "Succeeded") {
direction = "green";
} else {}
$("#conversationText").append('<br/><div class="chat-user-info"><h1 class="chat-user-name">' + newMsg.sender.displayName() + '</h1><h2 class="chat-user-time">' + new Date() + '</h2></div><div class="chat-user-message"><h3 style="color:' + direction + ';">' + newMsg.text() + '</h3></div><br/>');
}
});
But, the message appears when it is on state pending or even if fails , after this i try to put the message inside but it appears only on the other side not mine.
Github related issue Here
Why did you add the typeof newMsg.direction != 'function' condition, does it correct something ?
The behaviour of your code seems correct here because the message appends only if the message is "Outgoing" and not "Succeeded".
Did you have any bugs or logs with the original solution wich is
conversation.historyService.activityItems.added(function(message) {
if (message.type() == 'TextMessage') {
if (message.direction() == 'Incoming' ) {
historyAppend(XMessage(message));
} else if (message.direction() == 'Outgoing' && message.status() === "Succeeded") {
historyAppend(XMessage(message));
}
}
});
I did solve this by workaround appending the message first regardless message.direction() value

Check translate3d support not working when loading script in body

This proposed solution seems to work quite well in most scenarios but I noticed it fails to detect support for translate3d properties when a <script> tag is used within the <body>.
Reproduction online
This is the function used to detect the 3d support:
function has3d() {
if (!window.getComputedStyle) {
return false;
}
var el = document.createElement('p'),
has3d,
transforms = {
'webkitTransform':'-webkit-transform',
'OTransform':'-o-transform',
'msTransform':'-ms-transform',
'MozTransform':'-moz-transform',
'transform':'transform'
};
// Add it to the body to get the computed style.
document.body.insertBefore(el, null);
for (var t in transforms) {
if (el.style[t] !== undefined) {
el.style[t] = "translate3d(1px,1px,1px)";
has3d = window.getComputedStyle(el).getPropertyValue(transforms[t]);
}
}
document.body.removeChild(el);
return (has3d !== undefined && has3d.length > 0 && has3d !== "none");
}

javascript how to prevent from mulitiple dots in input field

I'm trying to develop functionality for input generated by jsf. I already have javascript code that uses the onkeypressed to prevent putting non-numeric values by user:
function validateNumberKey(event){
return (45<event.charCode && event.charCode<58 && event.shiftKey==false && DotTracker().prototype.wasPressed())
|| (event.keyCode==8) || (event.keyCode==9)
}
the code that findsout if user pressed dot is here:
function DotTracker() {
var dotPressed = false;
this.wasPressed = function() {
var currentDot = dotPressed;
dotPressed = true;
return currentDot;
};
}
And simplified input reference:
<input type="text" id="inpurCP" onfocus="new DotTracker()" onkeypressed="validateNumberKey(event)"/>
I'm pretty sure that something goes wrong with calling wasPressed() method. But I'm not quite familiar with javascript though...
Ok I solve the problem. Instead of using DotTracker(). I created another function:
function wasDotPressed(event) {
var index = -1;
if(event.charCode == 46) {
var currentValue = event.currentTarget.value;
index = currentValue.indexOf('.');
}
return index == -1;
}
and add the relevant line of code to the validateNumberKey(event):
function validateNumberKey(event){
return (45<event.charCode && event.charCode<58 && event.shiftKey==false && wasDotPressed(event))
|| (event.keyCode==8) || (event.keyCode==9)
}
And finally it works :). Hope that it help anyone that is struggling such problem.

Simple If statement for Javascript(jQuery)

I am trying to wrap my head around if statements. I am new to this.
I have a pretty simple script pulling data(text) from a html5 data attribute.
var $datatext = $(this).data('explain');
Now I want an if statement when html5 attribute data-explain is missing or empty.
var $success = if ($datatext < 0) {
// show some other text, maybe? =
$(this).text('Fail');
} else {
// show original, maybe? =
$(this).text($datatext);
}
Again, hard time wrapping my head around it. Ohhh these ifs.
That should work:
if (typeof $datatext !== 'undefined' && $datatext.length > 0) {
$(this).text($datatext);
} else {
$(this).text('Fail');
}
check for the length not for the data in $datatext rewrite your code like this
if ($datatext.length > 0) {
// show original, maybe? =
$(this).text($datatext);
} else {
// show some other text, maybe? =
$(this).text('Fail');
}
You can do it this way,
Live Demo
$('.someclass').each(function() {
if(typeof this.attributes['data-explain'] != 'undefined')
{
alert(this.id + ": explain exists");
explain = $.trim(this.getAttribute('data-explain'))
if(explain.length > 0)
alert(explain);
else
alert("no value for explain");
}
else
alert(this.id + ": explain does not exists");
});​

Categories