Drop Target Issue - aem

I've just started using Adobe CQ5 and am working my way through getting my first custom components rolled... I've found a bug that I can't figure out and was hoping someone could shed some light on it.
Basically, I've defined a custom image and associated drop area, but couldn't figure out how to do a placeholder image. So I did this:
<%
if (leftImage != null && leftImage.hasContent()) { leftImage.draw(out); }
else { leftImage.setSelector(".img"); out.print("<img class=\"" + DropTarget.CSS_CLASS_PREFIX + "panelLeftImage" + "\" src=\"http://placehold.it/300x300\" />"); }
%>
It seems to work properly once you've gone into the component edit dialog and clicked "OK", but when you try to drop an image at page load without having gone into the dialog, the resource doesn't resolve and you get a broken image graphic. The drop target is correctly highlighted though.
Any ideas?

For the next wayward traveler... I was able to fix this - eventually.
My JSP looks more like this now:
<%
Image leftImage = new Image(resource, "panelLeftImage");
leftImage.addCssClass(DropTarget.CSS_CLASS_PREFIX + "panelLeftImage");
leftImage.setSelector(".img");
leftImage.setDoctype(Doctype.fromRequest(request));
if (leftImage != null && leftImage.hasContent()) { leftImage.draw(out); }
else { out.print("<img class=\"" + DropTarget.CSS_CLASS_PREFIX + "panelLeftImage" + "\" src=\"http://placehold.it/460x200\" />"); }
%>
Rinse and repeat with different names for each image panel you make in the dialog.
In the cq:dropTargets CRXDE Lite node, you need to have a master for each image, a child parameter node and then children of that for all available images in the component.
So for example, if you had a leftImage and rightImage, it would look like this (interpret the JSON as a little property map):
cq:dropTargets
leftImage { "accept": "image.*", "groups": "media", "jcr:primaryType": "cq:DropTargetConfig", "propertyName": "./leftImage/fileReference" }
parameters { "jcr:primaryType" : "nt:unstructured", "sling:resourceType": "pathToYourComponent" }
leftImage { "jcr:primaryType" : "nt:unstructured", "sling:resourceType": "foundation/components/image" }
rightImage { "jcr:primaryType" : "nt:unstructured", "sling:resourceType": "foundation/components/image" }
rightImage { "accept": "image.*", "groups": "media", "jcr:primaryType": "cq:DropTargetConfig", "propertyName": "./rightImage/fileReference" }
parameters { "jcr:primaryType" : "nt:unstructured", "sling:resourceType": "pathToYourComponent" }
leftImage { "jcr:primaryType" : "nt:unstructured", "sling:resourceType": "foundation/components/image" }
rightImage { "jcr:primaryType" : "nt:unstructured", "sling:resourceType": "foundation/components/image" }
Don't ask me why it works, it just does.

Related

How to create customized Add Comment in Word-Addins Taskpane?

I am creating an MS-Word Add-ins for Word for mac and I have to create a custom comment section with a task pane so I have created one textbox and create a button on click on button comment is added to that selected text.
I find many articles but don't work for me so that I attach a sample code below.
HTML File
<div class="padding">
<textarea id="areaDiv"></textarea>
<button id="addComment">Add Comment</button>
<div id="errorDiv"></div>
</div>
**JS File**
Office.onReady(function () {
// Office is ready
$(document).ready(function () {
// The document is ready
// Use this to check whether the API is supported in the Word client.
if (Office.context.requirements.isSetSupported('WordApi', '1.1')) {
// Do something that is only available via the new APIs
$('#addComment').click(addComment);
$('#supportedVersion').html('This code is using Word 2016 or later.');
}
else {
// Just letting you know that this code will not work with your version of Word.
$('#supportedVersion').html('This code requires Word 2016 or later.');
}
});
});
// Function that writes to a div with id='message' on the page.
function addComment() {
Office.context.document.getSelectedDataAsync(Office.CoercionType.Text,
{ valueFormat: "unformatted", filterType: "all" },
function (asyncResult) {
var error = asyncResult.error;
if (asyncResult.status === Office.AsyncResultStatus.Failed) {
write('');
}
else {
var range = asyncResult.value;
write(range);
}
});
}
function onError(error) {
$('#errorDiv').text(error.name + ' ' + error.code + ': ' + error.message);
}
function write(range) {
$('#errorDiv').text(range);
var text = $("#areaDiv").val();
if (range != null && range != "" && text != null && text != "") {
$('#errorDiv').text(range + " " + text);
var document = Office.context.document.properties.comments;
document.add(range, text);
$("#areaDiv").val("");
}
}
Here there is no error but there is an issue of no comment is set the selected text and not goes in the catch block.
If anyone has an idea about this then it helps me a lot.

leaflet pop-up with JSON as text

For debug purposes, I wanted my marker to have a pop-up that had the json in it.
The value is something like:
var CarState= {
"height" : 6.2,
"width" : 7.3,
"length" : 9.1,
"color" : {
"r" : 255,
"g" : 200,
"b" : 10
}
}
But this is not working, all I get is a truncated pop-up. The content of CarState is constantly changing, but the same property bag is there.
Notes: self refers to the AMD module that this code is in. I don't use this, since you can get in trouble. self.pop is a variable that holds the L.PopUp
this.update = function () {
var text = "<p>" + JSON.stringify(CarState) + "</p>";
self.pop.setContent(text);
self.pop.update();
}
here is what it looks like:
and here is what Chrome says is the pop-up div size:
OK, this is working for me now. Not completely sure what the problem was.
this.update = function () {
var text = "<pre><code>" + JSON.stringify(CarState, null, '\t') + "</code></pre>";
theCar.setPopupContent(text);
theCar.update();
theCar.setLatLng(L.latLng(CarState.lat, CarState.lon));
theMap.panTo(L.latLng(CarState.lat, CarState.lon));
}

Fancybox 2 and soundcloud media helper case

I was wondering if some could help me to produce another case in Fancybox 2 media helper for Soundcloud. I need it to load the soundclooud iframe when the fancybox is triggered - otherwise with a number of embeds things go really slow.
I'm not very familiar with regular expressions - hence my enquiry.
The google part looks like this:
google_maps : {
matcher : /maps\.google\.([a-z]{2,3}(\.[a-z]{2})?)\/(\?ll=|maps\?)(.*)/i,
type : 'iframe',
url : function( rez ) {
return '//maps.google.' + rez[1] + '/' + rez[3] + '' + rez[4] + '&output=' + (rez[4].indexOf('layer=c') > 0 ? 'svembed' : 'embed');
}
}
Now if we take the standard iframe code for soundcloud:
<iframe width="100%" height="166" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=http%3A%2F%2Fapi.soundcloud.com%2Ftracks%2F91535490"></iframe>
I believe we would take the url from the iframe as the direct link does not contain the id of the track - only string representation of it.
What I've got so far (trying hard ;) - is the following, which doesn't work:
soundcloud : {
matcher : /w\.soundcloud\.([a-z]{2,3}(\.[a-z]{2})?)\/(\?ll=|url\?)(.*)/i,
type : 'iframe',
url : function( rez ) {
return '//w.soundcloud.com/player/?url=$1';
}
}
Could someone point me in the right direction here please?
Ok - for those who also wonder - I've managed to get it to work with the following:
soundcloud : {
matcher : /w\.soundcloud\.com\/player\/(.*)\/?(.*)/,
type : 'iframe',
url : function( rez, params, obj ) {
obj.width = '600px';
obj.height = '166px';
return '//w.soundcloud.com/player/' + rez[1];
}
}

jstree initially selected menu causes infinity loop;

I'm using jstree_pre1.0_fix_1. And I want to have the preselected menu.
javascript is following,
$("#Menu").jstree({
"plugins" : [ "themes", "html_data", "ui"],
"ui" :{ "initially_select" : ["#MENUITEM_012"] },
"themes" : {
"theme" : "custom",
"dots" : false,
"icons" : false,
},
}).
bind("select_node.jstree", function(e,data) {
window.location.href = data.rslt.obj.children("a").attr("href");
});
When jstree is loaded, it selects a node(#MENUITEM_012), then window.location.href is changed, then jstree loaded and selects a node again.
How can I escape this situation.
Just found the solution. The problem is caused by the library trying to select the node( i.e. to make it appear selected after the navigated page is loaded). And handler had been set when a node is visited to navigate the page to another page.
The solution is to make sure that the node is selected with a mouse click.
.bind("select_node.jstree", function(e,data) {
var evt = window.event || event;
var button = evt.which || evt.button;
if( button != 1 || ( typeof button == "undefined")) return true;
window.location.href = data.rslt.obj.children("a").attr("href");
})
Answer myself;
remove
.bind("select_node.jstree", function(e,data) {
window.location.href = data.rslt.obj.children("a").attr("href");
})
add
$(".jstree li a").live("click", function(e) {
window.location.href = $(this).attr("href");
});

JSTREE, exact move position

I want to show an explicit tooltip while drag-drop tree node inside treeview.
example: "Node 1 will be moved before/after/inside Node 2"
From move_node callback argument, we can get the position ("before/after/inside") but not from check_move callback (neither from prepare_move).
Tooltip should be displayed while drag-droping, so move_node is too late.
The same problem when drag-drop external object to treeview, the drag_check callback from dnd plugin has no information about the position (we just know the target node but not if it is before, after or inside).
In that case, even for drag_finish callback we don't have the information.
Is there somebody who can help me solving this issue ?
I just tested this and its working fine for me on prepare_move ...
.bind("prepare_move.jstree",function(event, data) {
console.log("o : " + data.rslt.o.attr("id"));
console.log("r : " + data.rslt.r.attr("id"));
console.log("p : " + data.rslt.p);
})
this is what is logged
o : item_3
r : item_2
p : inside
I am using JSTree v1.0RC2
Here what I use to do it with jQuery plugin jDialog (or you can replace it with a simple jAlert function):
.bind("move_node.jstree", function (e, data) {
var id = data.rslt.o.attr("id").replace("node_","");
var name = data.inst.get_text(data.rslt.obj);
jConfirm('Moving node name:' + name, 'dialog title'), function(answer) {
if (answer == true){
$.post("/js_trees/"+ id,
{
"_method" : "put",
"operation" : "moving_my_node",
"id" : data.rslt.o.attr("id").replace("node_",""),
"ref" : data.rslt.np.attr("id").replace("node_",""),
"position" : data.rslt.cp,
"title" : data.rslt.name,
"copy" : data.rslt.cy ? 1 : 0
},
function (r) {
if(!r.status) {
$.jstree.rollback(data.rlbk);
} else {
$(data.rslt.oc).attr("id", "node_" + r.id);
if(data.rslt.cy && oc.children("UL").length) {
data.inst.refresh(data.rslt.oc);
}
}
}
);
}else{
$.jstree.rollback(data.rlbk);
}
});
})