Skip to content

Instantly share code, notes, and snippets.

@teltploek
Created October 14, 2014 13:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teltploek/64d261a9f43511dc3918 to your computer and use it in GitHub Desktop.
Save teltploek/64d261a9f43511dc3918 to your computer and use it in GitHub Desktop.
var url = 'http://testwebserv30.ft.dk/fttdservice';
$(document).ready(function() {
$("#tabs").tabs();
// shortcut for insert
shortcut.add("Ctrl+i", function() {
var selectednodes = $.jstree.reference('#jstree').get_selected(true);
if (selectednodes != null && selectednodes.length > 0) {
callSitecore(selectednodes[0]);
alert('link indsættes i tekst');
} else {
alert('Vælg et link');
}
});
// insert button
$('#btninsert').click(function() {
var selectednodes = $.jstree.reference('#jstree').get_selected(true);
callSitecore(selectednodes[0]);
});
// jstree configuration
$('#jstree').jstree({
core: {
data: [
{
text: "Tingdok",
icon: 'jstree-themeicon-folderlink',
state: {
opened: true,
selected: true,
},
li_attr: { 'cid': '/' }
}
],
themes: {
dots: true,
stripes: false
},
check_callback: function(operation, node, node_parent, node_position, more) {
if (more && more.dnd && more.pos !== 'i') {
return false;
}
if (operation === "move_node" || operation === "copy_node") {
if (this.get_node(node).parent === this.get_node(node_parent).id) {
return false;
}
}
return true;
},
},
contextmenu: {
items: {
itemCreate: {
label: "Indsæt link",
action: function(node) {
var tree = $("#jstree").jstree(true);
var n = tree.get_selected();
var myNode = tree.get_node(n);
callSitecore(myNode);
},
shortcut_label: "ctrl + i",
_disabled: false
},
}
},
plugins: ['themes', 'types', 'search', 'contextmenu']
})
.on('activate_node.jstree', function(e, data) {
if (data.node.children.length > 0 || data.node.li_attr['cid'] == '') return;
var id = data.node.li_attr['cid'];
SetJSONData(id);
});
var to = false;
$('#txtsearch').keyup(function() {
if (to) {
clearTimeout(to);
}
to = setTimeout(function() {
var v = $('#txtsearch').val();
$('#jstree').jstree(true).search(v);
}, 250);
});
});
function getRadWindow() {
if (window.radWindow) {
return window.radWindow;
}
if (window.frameElement && window.frameElement.radWindow) {
return window.frameElement.radWindow;
}
return null;
}
var isRadWindow = true;
var radWindow = getRadWindow();
if (radWindow) {
if (window.dialogArguments) {
radWindow.Window = window;
}
}
function callSitecore(node) {
var text = node.text;
var url = node.li_attr['nodeurl'];
var returnValue;
if (node.li_attr['cssType'] == 'Link' || node.li_attr['cssType'] == 'FolderLink') {
text = node.li_attr['urlTitle'];
}
console.log('Indsættes i sitecore\n\n' + 'title: ' + text + '\n\nurl: ' + url);
returnValue = url + '##' + text;
getRadWindow().close(returnValue);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment