You are not logged in.
#1 2007-01-03 17:19:05
- khoosys
- Member
- Registered: 2007-01-03
- Posts: 11
Custom File Browser - "inst has no properties" error
I have the editor working fine and now am implementing a custom file and image browser. I have read the really useful guide from Felix Riesterer, but still have a problem which has stumped me:
- I initialise the main editor with callback:
file_browser_callback : "myFileBrowser",
which is:
function myFileBrowser (field_name, url, type, win) {
// alert("Field_Name: " + field_name + "\\nURL: " + url + "\\nType: " + type + "\\nWin: " + win); // debug/testing
var fileBrowserWindow = new Array();
var cmsURL = '/pop_editor/browser.htm'; // script URL
var query = '?'+'{query}'; // possible parameters
fileBrowserWindow["file"] = cmsURL + query + "&type=" + type; // PHP session ID is now included if there is one at all
fileBrowserWindow["width"] = "700";
fileBrowserWindow["height"] = "450";
fileBrowserWindow["close_previous"] = "no";
tinyMCE.openWindow(fileBrowserWindow, {
window : win,
input : field_name,
resizable : "no",
inline : "yes"
});
return false;
}
Now, even if I create an empty window for /pop_editor/browser.htm (my custom browser), on closing the window (using the usual close window icon) and then selecting "Insert" on the underlying image or link popup window I get the error:
"inst has no properties" - err on line 269 of functions.js, which starts like this:
267function insertAction() {
268 var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
269 var elm = inst.getFocusElement();
270 var formObj = document.forms[0];
271 var src = formObj.src.value;
...
I you click insert without opening the custom window, there isn't an error.
Am I missing something really obvious in my custom window?
Using Firefox 2 on Mac.
Thanks
Stephen
Offline
#2 2007-01-05 22:52:01
- Felix Riesterer
- Administrator
- From: Germany
- Registered: 2005-12-30
- Posts: 3901
- Website
Re: Custom File Browser - "inst has no properties" error
Hi khoosys!
Thanks for your mail, but I prefer this matter to be discussed in this thread so others might benefit from it using the search function (which very few only seem to know about...).
Your code looks like taken from the Wiki article about custom filebrowser implementation.
Let's have a closer look:
Code:
function myFileBrowser (field_name, url, type, win) {
// alert("Field_Name: " + field_name + "\\nURL: " + url + "\\nType: " + type + "\\nWin: " + win); // debug/testing
var fileBrowserWindow = new Array();
var cmsURL = '/pop_editor/browser.htm'; // script URLI don't understand why you changed the value of "cmsURL" to this string (used to be window.location.pathname). Isn't your server-side script going to answer the request by using your HTML file (called '/pop_editor/browser.htm') as a template? Since such a filebrowser usually needs to be somewhat dynamic a static HTML file won't offer you all the files available on the server if there have been recent file uploads or deletions...
This might already pose some problems but I can't tell you anything substantial since you haven't given me any link to a test scenario or any portion of this HTML file's code!
Let's go on...
Code:
var query = '?'+'{query}'; // possible parametersWhat's '{query}' supposed to mean? If this is to be sent to the browser as is then it might provoke some funny results if any at all. The filebrowser call would request this URL: "http://yourdomain.com/pop_editor/browser.htm?{query}". If you intended "query" to be a variable in your script then this is the first time this variable has been used (or is it a global variable defined in some other part?) and as such is "undefined". But since you have put it in single quotes (doesn't matter in double quotes either) the variable name is treated as string data and will lead to the URL as I mentioned earlier.
Code:
fileBrowserWindow["file"] = cmsURL + query + "&type=" + type; // PHP session ID is now included if there is one at all
Now this is downright senseless! You do use a variable named "query" here which isn't defined! If you wanted to change my original variable ("searchString") and use a different name for it then you still need to define it and give it a value! Compare the respective part of code in the Wiki article!
All this fuzz about meddling with the request URL is to keep a possible session variable in the URL because if a client doesn't accept cookies this information usually is transported via search string.
The rest of your code matches my example in the Wiki article.
I strongly recommend that you change your code to exactly my version and use a server-side script to answer the request of the custom filebrowser function! Let me give you an example to show you how server-side script and filebrowser script can interact. Remember that the location of this script will be the only "page" to be called since it will answer all requests accordingly be they a filebrowser window, a file upload or the editor itself.
[ script ]
1.) determine what to do (either from a value in the search string or from a POSTed value)
// "filebrowser"? "editor"? "file upload"? Let's see...
2.) get the according template (HTML) file
// "filebrowser"? OK. Get template and fill it with either images to select from
or possible pages/images to link to. Find out the needed information by taking
the value for "type" inside the search string
// I use a variable "cms_action" in my search string to react to requested actions... e.g.
"http://mydomain.com/mycms/script.php?cms_action=filebrowser&type=image&path=/images/products"
3.) modify the template file if necessary (like adding the HTML code of the page to be edited into the editor)
// OK. filebrowser needs to contain images because "type" in the search string was
set to "image". Get list of images to select from and insert it into the filebrowser
template HTML code.
4.) send template to browser
[ /script ]
Since you only need one single URL to get your information, the filebrowser window needs to call the server-side script rather than a static HTML file (like "pop_editor/browser.htm"). To get the URL correct all you need to do is to get the editor's URL since it is the one you also need for your filebrowser! This is why I used window.location.pathname in my script.
Now to what you wrote in your mail:
Code:
267function insertAction() {
268 var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
269 var elm = inst.getFocusElement();
270 var formObj = document.forms[0];
271 var src = formObj.src.value;Why don't you do it the way I described in the Wiki article? Don't meddle with "inst" and "editor_id" since you don't want to access the editor itself but a dialogue window's form elements! Please read my article more thoroughly, especially the part on how to return values to understand that your approach simply can't work!
Next time please provide more relevant information! My guess is that you use some kind of CMS which you want to modify...
Greetings from Germany and a Happy New Year!
Felix Riesterer.
Last edited by Felix Riesterer (2007-01-05 23:01:05)
Offline
#3 2007-01-06 18:42:06
- khoosys
- Member
- Registered: 2007-01-03
- Posts: 11
Re: Custom File Browser - "inst has no properties" error
Thanks for you reply Felix. Yes, it's better here on the forum, and as I stated in my post I did use your article.
A couple of things that might help get rid of some of the confusion (and incidentally not make us look quite as dim as you imply!):
1) {query} is a variable filled in by our server-side script. This changes on each page's file browser with additional stuff like directory location to use etc. So the javascript won't see {query} itself, but something like ?dir=single/104 .. along with other parameters to set up the server script. Sorry for not making this clear earlier, but I don't think it changes things anyway.
2) /pop_editor/browser.htm is not a static page in our system but one which uses php as a backend. It just happens to have an .htm extension. So it is incorrect to assume that we have put a static page behind a file browser. It doesn't change the problem anyway either because as I mentioned, one gets the problem with a blank page as well. Any it's always good to isolate an issue by reducing unknowns etc.
3) Regarding:
Why don't you do it the way I described in the Wiki article? Don't meddle with "inst" and "editor_id" since you don't want to access the editor itself but a dialogue window's form elements!
I was merely showing where the error in the functions.js code occured. I have not changed any of that stuff - or said that I had!
Ok back to the problem...
Given that the only difference between what I have done and your example is that I have used our own {query} instead of cmsURL, why is there a fault on the underlying window when the "import" button is pressed when the browser pop window is opened.
Of course I had tried putting exactly your code in with cmsURL, but that also had the same problem because it only carries session info to the browser.
The point I am making is that even if one opens a blank window using your example (yes - this time it is a static one just to make the point!) I get the same error when then clicking "import"
To make it really clear what the issue when I try this:
1) Open link browser - click import (nothing in the image field). The popup closes with no problems. OK the link is rubbish and sets to / or something, but that's ok
2) Open link browser - click on custom browser (a blank html screen), using init as per your example. Then close the custom browser using usual window close box. Then click "import" button and you get the error I am refering to.
I am using the php compressor for tinyMCE. Is this interfering in any way.
I also use prototype and scriptaculous on the underlying editor window - but loading those in a particular order also gets rid of the errors with editor not otherwise working.
Thanks
Dr Stephen Khoo
BTW khoosys is only my screen name.
Offline
#4 2007-01-07 07:20:13
- Felix Riesterer
- Administrator
- From: Germany
- Registered: 2005-12-30
- Posts: 3901
- Website
Re: Custom File Browser - "inst has no properties" error
Hi Dr Stephen Khoo!
khoosys wrote:
get rid of some of the confusion (and incidentally not make us look quite as dim as you imply!)
Sorry if I gave you this impression but lately I found many people here asking for help who had very little understanding of JavaScript. Your code had a few things in it which made me wonder why, and by not adding any explanatory comments I couldn't understand what these things were supposed to be or do or - and here comes the unintended implication - what made you put these things into your code in the first place. Again I apologize for my misunderstanding of your posted material and for my misjudgement.
khoosys wrote:
To make it really clear what the issue when I try this:
1) Open link browser - click import (nothing in the image field). The popup closes with no problems. OK the link is rubbish and sets to / or something, but that's ok
2) Open link browser - click on custom browser (a blank html screen), using init as per your example. Then close the custom browser using usual window close box. Then click "import" button and you get the error I am refering to.
I see, the "inst has no properties" error. OK. And it occurs where exactly? I think I know...
Hmm, you still haven't answered my question about the piece of code you sent me in your mail:
Code:
267function insertAction() {
268 var inst = tinyMCE.getInstanceById(tinyMCE.getWindowArg('editor_id'));
269 var elm = inst.getFocusElement();
270 var formObj = document.forms[0];
271 var src = formObj.src.value;I really believe that the error must be here since everything else looks alright. Where exactly is this portion of code? Is it in your filebrowser popup or is it in a plugin of yours? To clarify things you might want to debug whether "editor_id" contains a valid ID _every_ time this function is executed.
Otherwise I'm out of ideas.
khoosys wrote:
BTW khoosys is only my screen name.
Yes, and since you signed your post with "Stephen" I should have called you by that instead of by your screen name. This time I won't make the same mistake again. ![]()
Greetings from Germany,
Felix Riesterer.
Offline
#5 2007-01-08 12:04:00
- khoosys
- Member
- Registered: 2007-01-03
- Posts: 11
Re: Custom File Browser - "inst has no properties" error
Hi Felix,
Sorry if I gave you this impression but lately I found many people here asking for help who had very little understanding of JavaScript. Your code had a few things in it which made me wonder why, and by not adding any explanatory comments I couldn't understand what these things were supposed to be or do or - and here comes the unintended implication - what made you put these things into your code in the first place. Again I apologize for my misunderstanding of your posted material and for my misjudgement.
Accepted. I think this is one of the hazards of providing a popular on-line guide.
I see, the "inst has no properties" error. OK. And it occurs where exactly? I think I know...
Hmm, you still haven't answered my question about the piece of code you sent me in your mail:
It's in functions.js - as I said. Part of tinyMCE code. I haven't altered it, but just show the line numbers where the error occurs.
I shall try a couple of things:
1) reload the tinyMCE files to see if something has got mucked up in our installation somewhere.
2) if this fails to solve it - give you an online example. At the moment it is only on our local development linux server. I could arrange access to that.
Are you able to reproduce the error on your system - even with a blank popup window?
Are we missing something obvious like a variable declaration on the popup?
Thanks for you help. Much appreciated!
Stephen
Offline
#6 2007-01-15 21:28:31
- bodgekaloopie
- Member
- Registered: 2007-01-12
- Posts: 2
Re: Custom File Browser - "inst has no properties" error
I'm trying to add this function but I have no JavaScript experience.
I've almost got the function working, but am getting the debug errors. Although I have tried many different ways, I can't figure out how to customize the field_name, url, type and win fields that the function calls.
Any help will be appreciated!
Offline
#7 2007-01-16 00:50:38
- neonox
- Member
- From: Europe/Germany/Hessen/Fulda
- Registered: 2007-01-15
- Posts: 20
Re: Custom File Browser - "inst has no properties" error
Solution is here http://tinymce.moxiecode.com/punbb/view … hp?id=5698
Offline
#8 2007-01-16 04:01:53
- Felix Riesterer
- Administrator
- From: Germany
- Registered: 2005-12-30
- Posts: 3901
- Website
Re: Custom File Browser - "inst has no properties" error
Hi!
So the advimage plugin has a bug! Since I don't use it I couldn't reproduce the error. Thanks to neonox the bug has been found.
Greetings from Germany,
Felix Riesterer.
Offline
#9 2007-01-16 20:39:37
- bodgekaloopie
- Member
- Registered: 2007-01-12
- Posts: 2
Re: Custom File Browser - "inst has no properties" error
Thanks, neonox.
I followed the instructions in the post that you linked to, but when I click on the browse icon, I don't get a list of files, I just get a copy of the current web page that I am on.
This leads me to believe that there is something in the code I need to customize that I am missing.![]()
Following is my script code:
Code:
<script language="javascript" type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "advanced",
plugins : "table,advhr,advimage,advlink,preview,print,contextmenu,ibrowser",
theme_advanced_buttons1_add : "ibrowser",
theme_advanced_buttons2_add : "separator,preview,separator,forecolor",
theme_advanced_buttons2_add_before: "cut,copy,paste,separator",
theme_advanced_buttons3_add_before : "tablecontrols,separator",
theme_advanced_buttons3_add : "advhr,separator,print",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_path_location : "bottom",
file_browser_callback : 'myFileBrowser',
extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|size|color|style],span[class|align|style]",
external_link_list_url : "example_data/example_link_list.js",
external_image_list_url : "example_data/example_image_list.js",
flash_external_list_url : "example_data/example_flash_list.js"
});
function myFileBrowser (field_name, url, type, win) {
//alert("Field_Name: " + field_name + "\nURL: " + url + "\nType: " + type + "\nWin: " + win); // debug/testing
var fileBrowserWindow = new Array();
/* If you work with sessions in PHP and your client doesn't accept cookies you might need to carry
the session name and session ID in the request string (can look like this: "?PHPSESSID=88p0n70s9dsknra96qhuk6etm5").
These lines of code extract the necessary parameters and add them back to the filebrowser URL again. */
var cmsURL = window.location.pathname; // script URL
var searchString = window.location.search; // possible parameters
if (searchString.length < 1) {
// add "?" to the URL to include parameters (in other words: create a search string because there wasn't one before)
searchString = "?";
}
fileBrowserWindow["file"] = cmsURL + searchString + "&type=" + type; // PHP session ID is now included if there is one at all
fileBrowserWindow["title"] = "File Browser";
fileBrowserWindow["width"] = "420";
fileBrowserWindow["height"] = "400";
fileBrowserWindow["close_previous"] = "no";
tinyMCE.openWindow(fileBrowserWindow, {
window : win,
input : field_name,
resizable : "yes",
inline : "yes"
});
return false;
}
function mySubmit() {
var URL = document.my_form.my_field.value;
var win = tinyMCE.getWindowArg("window");
// insert information now
win.document.getElementById(tinyMCE.getWindowArg("input")).value = URL;
// for image browsers: update image dimensions
if (win.getImageData) win.getImageData();
// close popup window
tinyMCEPopup.close();
}
</script>Thanks for any help you are willing to offer.
Offline
#10 2007-01-16 21:59:23
- Felix Riesterer
- Administrator
- From: Germany
- Registered: 2005-12-30
- Posts: 3901
- Website
Re: Custom File Browser - "inst has no properties" error
bodgekaloopie wrote:
but when I click on the browse icon, I don't get a list of files, I just get a copy of the current web page that I am on.
function myFileBrowser (field_name, url, type, win) { [code taken from wiki article - unaltered]
The code of the wiki article assumes that depending on some additional parameters the server-side script (which is your part to develop!) serves different HTML documents under the same URL. This is why this line
var cmsURL = window.location.pathname; // script URL
is written like this. It directly leads to the same URL the editor itself was loaded from.
I don't know how much you know about Javascript, HTML and server-side scripting languages so I can't give you any more elaborate hints.
You need to know how your server-side script works. If you haven't written it yourself then I strongly recommend that you contact the author(s)!
It is in the nature of a custom filebrowser that it needs server-side scripting in order to work dynamically. If you are happy with a static list of files that can be chosen from a drop down list then this setting might be of interest for you (which means that you can forget all about this custom filebrowser completely!): external link list
Greetings from Germany,
Felix Riesterer.
Offline
© 2003-2010