I am trying to insert HTML text in a content control using an Office App from Word Online. Unfortunately, it is not working for me. The same code works if I run it on the desktop version of Word.
For Word Online somehow I can insert only plain text and nothing else. Can anyone please help me with this?
This is the complete Word.Run method:
Word.run(function(context) {
var htmlText = ' <h1>Test HTML Text</h1>'
var range = context.document.getSelection();
var myContentControl = range.insertContentControl();
myContentControl.tag = 'Testtag';
myContentControl.title = 'TestTitle';
myContentControl.insertHtml(htmlText, 'end');
myContentControl.cannotEdit = false;
myContentControl.cannotDelete = false;
context.load(myContentControl, 'id');
// Synchronize the document state by executing the queued commands,
// and return a promise to indicate task completion.
return context.sync().then(function () {
console.log('Created content control with id: ' + myContentControl.id);
});
})
Can anyone please help me with what am I missing to achieve the same in word online.
Related
let hideText = () => {
let selection = window.getSelection();
console.log(selection.toString())
if (selection.toString() === "") {
console.log("Selection Error");
} else {
console.assert(selection.focusNode == selection.anchorNode);
let selectionText = selection.toString();
let selectionNode = selection.anchorNode.parentElement;
selectionNode.innerHTML = selectionNode.innerHTML.replace(selectionText,
`
<textarea>${selectionText}</textarea>
<button onclick="count(1)">+</button>
<button onclick="count(-1)">-</button>`
);
}
so above functions run when a user presses a dblctrl, but as shown in last two lines, i have count() to be run, which i have defined in the tool script. if i inject this code into any webpage and press the button, then count function doesnt run, because it is defined in my script not on the webpage, so how can i push my count() along with this html code written in strings to the webpage.
function count(num, selectionNode){
click+=num;
fontsz = parseFloat((fontsz))+(num*0.5)+"em";
document.querySelector("span").style.fontSize=fontsz;
}```
this is my count function.
You can add scripts to a page.
const script = document.createElement('script')
script.src = "https://example.com" // load your script
// or script.appendChild(document.createTextNode(oldButton.innerHTML))
document.body.appendChild(script)
Just mentioning that injecting javascript into other people's sites is unethical and in some cases criminal, you should only be doing this if you own those sites or have permission to do so.
I want to find a single JavaScript code/keyword like zopim or v2.zopim.com in whole script with using cheerio on NodeJS. I wrote a script that grabs all links from a single web site but the script need to opens all these grabbed links and search for "zopim" keyword in JavaScript codes. I looked cheerio's repository and it's issues but no luck. I'm wondering could anyone help me to figure out this situation?
This is a part of my code that where I open links and search in source code for a keyword. I can post all of it if it's necessary.
function () {
//console.log(totalUrls);
console.log("Crawling is done.")
if (page == 16) {
console.log("Anaylzing web sites...");
async.whilst(
function () {
return checkedUrl < totalUrls.length;
},
function (urlCallback) {
var currentUrl = totalUrls[checkedUrl]
request(currentUrl, function (err, res, body) {
if (err) {
console.log('Error: ' + err);
}
var $ = cheerio.load(body);
$('.headerContent').each(function () {
var title = $(this).find('a').text();
console.log(currentUrl + title);// if the current web site has a '.headerContent' class print it.
// I want to print only if web site source code includes "zopim" keyword in JavaScript code
});
checkedUrl++;
urlCallback();
});
}
);
}
}
You can use :contains selector to find scripts which contain keyword 'zopim' in text and then count found script elements:
const scriptsWithKeywordCount = $('script:contains("zopim")').length;
if (scriptsWithKeywordCount > 0) {
// webpage contains keyword in javascript code
}
I am new to web developing, and I have met this problem. I write the following script:
<script>
function updateProductQuantity(num,index)
{
var inp = document.getElementById("input-"+index);
var tot = document.getElementById("total-"+index);
var n_quantity = inp.value;
if (!isNaN(n_quantity))
{
addArticle(num, null, {"quantity":"set_"+n_quantity});
inp.value = parseInt(inp.value);
}
else window.alert("Not a number: " + n_quantity);
}
</script>
In chorme, (also firefox) this appears like this:
<p> <script>
function updateProductQuantity(num,index)
{
var inp=document.getElementById("input-"+index);
var tot=document.getElementById("total-"+index);
var n_quantity=inp.value;</p>
<p> if (!isNaN(n_quantity))
{
addArticle(num,null, {"quantity":"set_"+n_quantity});
inp.value = parseInt(inp.value);
}
else window.alert("Not a number:" + n_quantity);
}
</script></p>
(both firefox and chrome insert these p tags)
In the browzer, the whole script appears to be inside a "p" element, which I do not write in the code.
Also, the empty lines of my code are converted into p tags.
Of course, the script is broken and I get this error:
Uncaught SyntaxError: Unexpected token <
A workaround is to remove all empty lines from the come. But I dont think this is a solution. Right?
Thanks in advance!
Without seeing all of your code my best guess would be that you've got something else going on like an unclosed tag that is confusing matters.
Try putting the contents of your file through W3C's validator https://validator.w3.org/#validate_by_input and fix any errors that it is showing you
Is it possible to use a code behind of a command used for ribbon button in content editor as a request for experience editor button? We want to stick to SPEAK and not make any changes to Sitecore.ExperienceEditor.config.
After creating new button in Experience editor, telling .js to call NewCommand request by
Sitecore.ExperienceEditor.PipelinesUtil.generateRequestProcessor("ExperienceEditor.NewCommand");
that was referenced in Sitecore.ExperienceEditor.Speak.Requests.config as
<request name="ExperienceEditor.NewCommand" type="Sitecore.Starterkit.customcode.MyCommand,MyProject"/>
nothing happens and logs say
ERROR Could not instantiate speak request object,
name:ExperienceEditor.NewCommand,
type:Sitecore.Starterkit.customcode.MyCommand,MyProject`
Do we have to import PipelineProcessorRequest as suggested by some tutorials or is there a way to use our existing code?
Have you seen this blog post on adding custom SPEAK command buttons to Sitecore 8 Experience Editor?
https://doc.sitecore.net/sitecore%20experience%20platform/the%20editing%20tools/customize%20the%20experience%20editor%20ribbon
Otherwise if that doesn't achieve what your looking for, it might be worth trying to standard SPEAK application way of triggering a button, In a SPEAK application you can call a JavaScript function from a button click using this code.
javascript:app.FunctionName();
In the core DB update the click field on your button to call JavaScript with the javascript: prefix. Does this allow you to trigger your JavaScript?
I was able to use my existing control using guidelines from:
http://jockstothecore.com/sitecore-8-ribbon-button-transfiguration/
Relevant pieces of the old command:
if (args.IsPostBack)
{
// act upon the dialog completion
if (args.Result == "yes")
{
Context.ClientPage.SendMessage(this, "item:load(...)");
}
}
else
{
// trigger the dialog
UrlString url = new UrlString(UIUtil.GetUri("control:CopyLanguage"));
url.Add("id", item.ID.ToString());
url.Add("lang", item.Language.ToString());
url.Add("ver", item.Version.ToString());
SheerResponse.ShowModalDialog(url.ToString(), true);
args.WaitForPostBack();
}
The redressed command:
define(["sitecore"], function (Sitecore) {
Sitecore.Commands.ScoreLanguageTools = {
canExecute: function (context) {
return true; // we will get back to this one
},
execute: function (context) {
var id = context.currentContext.itemId;
var lang = context.currentContext.language;
var ver = context.currentContext.version;
var path = "/sitecore/shell/default.aspx?xmlcontrol=CopyLanguage" +
"&id=" + id + "&lang=" + lang + "&ver=" + ver;
var features = "dialogHeight: 600px;dialogWidth: 500px;";
Sitecore.ExperienceEditor.Dialogs.showModalDialog(
path, '', features, null,
function (result) {
if (result) {
window.top.location.reload();
}
}
);
}
};
});
I'm playing about with PDF.js, and can't seem to find a solution to my problem.
I have a PDF with a trim area and bleed, I need to get the trim area so that I can crop the PDF image data in HTML canvas.
I see that Acrobat has javascript that can return the Trim based on getPageBox("Trim"). Is there any equivalent in PDF.js?
I cant seem to find a reference when inspecting the Javascript PDF Object in the console.
I was able to get it after editing pdf.worker.js. Tested with 1.7.225. First, Add get trimBox() after get cropBox() like this:
get trimBox() {
var trimBox = this.getInheritedPageProp('TrimBox', true);
if (!isArray(trimBox) || trimBox.length !== 4) {
return shadow(this, 'trimBox', this.mediaBox);
}
return shadow(this, 'trimBox', trimBox);
},
Now, in handler.on('GetPage', function ... of WorkerMessageHandler, add a few lines like this:
handler.on('GetPage', function wphSetupGetPage(data) {
return pdfManager.getPage(data.pageIndex).then(function (page) {
var rotatePromise = pdfManager.ensure(page, 'rotate');
var refPromise = pdfManager.ensure(page, 'ref');
var userUnitPromise = pdfManager.ensure(page, 'userUnit');
var viewPromise = pdfManager.ensure(page, 'view');
var trimBoxPromise = pdfManager.ensure(page, 'trimBox'); //added
return Promise.all([
rotatePromise,
refPromise,
userUnitPromise,
viewPromise,
trimBoxPromise //added
]).then(function (results) {
return {
rotate: results[0],
ref: results[1],
userUnit: results[2],
view: results[3],
trimBox: results[4] //added
That's it. Now you can get the trim box in your app by page.pageInfo.trimBox.
In addition to the excellent answer from #Sangbok Lee,
If you use the latest PDF.js version, the this.getInheritedPageProp function has changed to
this._getInheritableProperty('TrimBox', true)
Figured it out.
For anyone else who may be interested in pdf.worker.js on line 2654 I added the following that exposed the trimBox.
tboxX = this.pageDict.map.TrimBox[0];
tboxY = this.pageDict.map.TrimBox[1];
tboxW = this.pageDict.map.TrimBox[2];
tboxH = this.pageDict.map.TrimBox[3];
I'm sure there is a neater way, but it works.