Using data return from sharepoint assetimagepicker - javascript

I'm working with Sharepoint 2007. I use the built in AssetImagePicker.aspx and I need to retrieve the image url from that page and use it in my custom webpart.
I want to run my javascript code to run when clicking the OK button of the AssetImagePicker.aspx but I can't find a way to do that.
Does anyone know how to do this?
Thanks

Not sure if I'm understanding the question properly, and I know nothing about Sharepoint (and AssetImagePicker.aspx) but it sounds like you want to add an event handler to the OK button: to run a function when the click event of the button is fired.
You can either code event handling yourself (see W3Schools or Quirksmode for examples of this) or (probably better) use a library like jQuery.

Related

Find the JS and jQuery codes and functions behinde an event in a web page quickly

When an event occur in a web page maybe a function be ran, of course if web designer has been assigned some codes to it and make require links.
But there are different ways to link the codes and events, especially when we are using a framework like jQuery! For example when we want assign a function to Click event of a Button or Checkbox , we can find it by different selectors and do this in the web page or in an external JS file and import it and....
Now i want now what are your suggestions to find the codes under an events (for example click event on a Checkbox) quickly.
Which lines and where?
I now i can discover the web site codes and pages to find it but i'm looking for a quick way and want know what is your suggestions...
Do you recommend some tools? Please explain them.
Developer Tools in your browser will help, and the search function build in

Add a button dynamically to a WebPage from Firefox Addon.

I actually want to add a button to Gmail. When someone opens a email, he/she sees a button and when someone clicks on it, I add a function to it. I know one way but it's very intensive where I use setInterval() every 300 ms and run a function to check if it's Gmail or not and then add a button dynamically. I need something less intensive because I don't want people to have problems running my add on.
I want it all from my add on script so that I can easily communicate between other functions of my add on.
To add to pages it depends. Pages can do many tricky things (like GitHub using PJAX see this addon on how it was done).
Method 1 - addEventListener to window or gBrowser
But most usually you can catch a DOMContentLoaded or load event. Template HERE.
Method 2 - Observe http-on-examine-response and loadContext
If the URL of the nsIHTTPChannel matches your pattern then get the contentWindow from the loadContext and then manipulate. I need to make a clean template for this but you can see some messy ones: here and here
Method 3 - Add ProgressListener
ProgressListeners are nice because it helps you catch anchor changes, and usually when sites ajax and change page they change the url somehow but it doesnt really load a new page. I'm working on a template for this but it's not ready yet.
Info about addEventListener
If you add event listener in some situations it works for when 3rd parameter is true or when false. If you find one that works for your situation it will always work.
To figure out what combination works for you install this addon: event-listener-experiment-DOMC-and-load it's on GitHub so you can install straight from GitHub with this addon GitHub Extension Installer
Install that addon then navigate to your page, look in the browser console to see what feedback you're getting. It will tell you which works for you. If you need more help tell me the site and I will help you figure it out.
Here's a bootstrap template you can use once you figure out the combination:

TinyMCE - how do you use onClick instead of <a href=""> for links?

Is there a way to change the defalt behaviour of TimyMCE, so that when you insert a link, it renders something like this:
<span onclick="window.open('http://google.com', '_blank', 'location=yes');"></span>
instead of
Ideally, I would like this to be done by the Link button, but it could be done onSubmit.
ADDED:
The reason for doing this (as I know it seems like bad practice) is to be able to port to PhoneGap (using the InAppBrowser plugin), as is not intended for browser use.
Overlooking that this really isn't a good practice, I will assume you have a valid use case for wanting to do such black magic.
But before, a few things to consider:
I would advise you to keep links as links while working in TinyMCE. That way, your users will be able to insert and edit them as usual. Changing them to span elements inside the editor will practically eliminate the ability to edit them without editing the full source. You should probably convert them to span elements outside the editor.
If you're the stubborn type and don't care about #1 or your users, you should note that the default TinyMCE 4 configuration doesn't allow onclick attributes, so you'll need to update extended_valid_elements, otherwise they will be removed during the cleanup process.
There is probably a better way to do what you're trying to do. As #Vic suggested, an event listener would probably be a better option.
Nevertheless, I will humor you. Below is an overview of the process with a working example.
Overview
If you are developing with TinyMCE 3.x, you'll want to tap into the onSaveContent event. If you are using 4.x, use the saveContent event. In both cases, the concept is the same.
This event gets fired whenever the content of the editor is "saved". This happens automatically if TinyMCE is submitted as part of a form, but you can also use tinymce.triggerSave() to force it on all editors at once.
So, simply setup your callback function to replace all links with the evil span alternative. You can use pure JS or TinyMCE's built-in DOM utilities (probably only a good idea if you're already familiar with them), but for clarity (and sanity) it's much easier with jQuery.
Working Example
TinyMCE Fiddle: http://fiddle.tinymce.com/mAdaab/1
This example uses TinyMCE 4
Open your browser's console to see the output
After TinyMCE loads, press the Save button
The resulting HTML will appear in your console
Do with it what you wish, but remember that there probably is a better way.
What you are proposing is a really bad practice (as in not using anchor tags for links) wouldnt it be easier to actually give your link an id or class and attach event listener with javascript and on click prevent default behavour grab the href attribute and use your window.open?

CKFinder popup onbeforeunload javascript

I'm currently working with CKFinder to upload images to a web app (and so on).
Now the problem is, there is no callback when the window closes:
With that I mean something like the javascript "onbeforeunload" event. The popup function only returns the api, and the api only contains the document and not the window.
I've looked through the docs and found a "selectActionFunction", but no sign of a "cancelActionFunction" or something similar.
http://docs.cksource.com/ckfinder_2.x_api/symbols/CKFinder.config.html
Thanks
Ok, in the end I didn't really find a solution within ckfinder, but since I was already working with jquery ui I just opened the ckFinder in a ui dialog box. Which gives me the ability to add a callback to the close button.
Maybe it is possible to add a cancel callback through the skins, but I chose the quick way of ui dialogs. (The only skinning I tend to do is in CSS, which is more then enough most of times)
Anyway, I hope this helps someone else too.

why is this click event failing

ok so i am stumped if you go to my site and click the right center "Take a Quick Tour >>>" ..i get this lightbox that appears and i want to close it programmatically and in firebug i can see the x is id "rokbox-close" but running this in firebug
document.getElementById('rokbox-close').click();
but i get this error
TypeError: document.getElementById("rokbox-close").click is not a function
any ideas how to do this
i can run this
document.getElementById("rokbox-close")
and get the element but the click function fails...i dont have jquery installed so i was wondering if there is a javascript thing i am missing
Not all browsers have a "click()" function associated with buttons and anchors and etc. IE does (I think), but (for example) Firefox doesn't.
edit — wow according to MDC, Firefox 5 will support this.
If you were using a framework such as jQuery, then that code might allow you to do what you want. (With jQuery you definitely can.)
(Also, strictly speaking, we're not talking about an event here. We're talking about the ability to trigger the event handling mechanism programatically.)
If you use simple JavaScript istead of 'click' use 'onclick':
document.getElementById("rokbox-close").onclick = youClickHandlerFunction
If you use jQuery use:
$('#rokbox-close').click(youClickHandlerFunction)
See more info here: http://www.quirksmode.org/js/introevents.html
Or here: http://api.jquery.com/click/
The click() function is something that is not supported by all browsers. You're probably thinking of the click handler that jQuery provides.
For a more complete view of why click() isn't universally handled, check out this link, which covers the long and twisty history of event handling across different browsers:
http://www.quirksmode.org/js/introevents.html

Categories