Page 5 of 8 FirstFirst ... 34567 ... LastLast
Results 41 to 50 of 80

Thread: Turn simple javascript code to a button

  1. #41
    Join Date
    Oct 2013
    Posts
    169
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    OK after giving this some thought I would say that the QR is a child to a degree so by explaining how it works with the NR I think you can determine a course of action if any.

    First of all the QR in PB is very plain Jane with only a Post Quick Reply button if you don't dress it up. By saying this I mentioned plugin. On the test forum I went and turned the Plugin off that gives it the same menu buttons as the NR. I just for kicks left the Smiley button there as it is a plugin too. The plugin that creates the menu button works only in the BBCode way unlike the NR that has a Preview mode as I mentioned. I even changed the Reply button to Normal Reply via a javascript header code. The buttons and features in the NR are all integrated into PB coding and they have it where one cannot see/modify those functions I do believe.

    There is one what I would call crossover connection between the QR and NR as in this. for instance if you start typing in the QR and even use the new Insert Image function we just added you can let the URL link post and then you can click on the NR button and the content in the QR will transfer to the NR window and when the image URL link transfers it will be posted in the preview mode when you do so, meaning you will see the photo instead of the link.

    ON the test forum I left the Add Attachment button, it works identically to our image host button except it goes to PB server storage where they have put maximum storage limits on. With all of this said I'm certain that the QR and NR are separate identities and one can look at the last code I posted for you which is the entire NR template and see they use <div> class control buttons to connect to their internal programming for the NR.

    But here is something that I also now know, remember I mentioned that the image source host that we used for this button has been made into a plugin? So you'll say why are we doing all this crap when you could have just installed the plugin and I can answer that easily. One the author of the plugin has long ago disappeared and only the plugin authors can offer support if some have problems and problems have risen such as it simply doesn't work with many forums, a few but the plugin working can also be determined by what a forum owner has or doesn't have on their forum? Lots of people begged the author to help with no success.

    Secondly one is allowed only so many plugins and then it's time to buy more......and plugins slow down your forum speed while template modifications and header/footer codes have very little impact. Knowing this people work hard to stay away from plugins when they can use other means. Back to what I said I know and it's this, the plugin does create a Insert Image button in the QR and NR posting window that works exactly the same way as the button we just installed so it can be done, how? I don't know.

    I have a fellow scooter friend that has a forum where he is using this plugin, he says at times it seems to quit working but for the most part it's ok, as I said there are forums where it will not work at all.

    http://49ccscoot.proboards.com/

    I don't know if you can sign up as a guest here, I'm betting you have to have a full account if you were to want to see it.

    I'm guessing the plugin author somehow knew how to link his plugin coding to the Preview mode of the NR coding and I did discover that when you open the image host window grab you image and then hit Upload it posts a link in the NR just like it does in the QR, it's identical in that aspect, so it can indeed be done.
    Last edited by JRR; 02-27-2015 at 04:17 PM.

  2. #42
    Join Date
    Oct 2013
    Posts
    169
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    When you return John I have some new/helpful info on this.

  3. #43
    Join Date
    Oct 2013
    Posts
    169
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Has John totally disappeared?

  4. #44
    Join Date
    Oct 2013
    Posts
    169
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    John this image button is still working great and I would still love to get it to work in the Normal Reply spot. By using the F12 function when using this image uploader I can come up with this code that we are now using that works:


    Code:
    if (typeof postimage_lang === 'undefined') {
    	var postimage_lang = "english";
    	var postimage_add_text = "Add image to post";
    
    	function postimage_query_string(postimage_search_name) {
    		if (window.location.hash) {
    			postimage_query = window.location.hash.substring(1).split("&");
    			for (postimage_i = 0; postimage_i < postimage_query.length; postimage_i++) {
    				postimage_string_data = postimage_query[postimage_i].split("=");
    				if (postimage_string_data[0] == postimage_search_name) {
    					postimage_string_data.shift();
    					return unescape(postimage_string_data.join("="));
    				}
    			}
    		}
    		return void(0);
    	}
    	if (opener) {
    		var postimage_text = postimage_query_string("postimage_text");
    		if (postimage_text) {
    			var postimage_id = postimage_query_string("postimage_id");
    			var postimage_area = opener.document.getElementsByTagName('textarea');
    			for (var postimage_i = 0; postimage_i < postimage_area.length; postimage_i++) {
    				if (postimage_i == postimage_id) {
    					break;
    				}
    			}
    			if (opener.editorHandlemessage && opener.editorHandlemessage.bRichTextEnabled) {
    				opener.editorHandlemessage.insertText(postimage_text + "<br /><br />", false);
    			} else {
    				postimage_area[postimage_i].value = postimage_area[postimage_i].value + postimage_text;
    			}
    			opener.focus();
    			window.close();
    		}
    	}
    	function postimage_insert() {
    		var postimage_area = document.getElementsByTagName('textarea');
    		for (var postimage_i = 0; postimage_i < postimage_area.length; postimage_i++) {
    			if (!postimage_area[postimage_i].name.match(/username_list|search|recipients/i)) {
    				postimage_div = document.createElement('div');
    				postimage_open = document.createElement('a');
    				postimage_open.innerHTML = postimage_add_text;
    				postimage_open.href = "javascript:postimage_upload(" + postimage_i + ");";
    				postimage_span = document.createElement('span');
    				postimage_span.innerHTML = " • ";
    				postimage_div.appendChild(document.createElement('br'));
    				postimage_div.appendChild(postimage_span);
    				postimage_div.appendChild(postimage_open);
    				postimage_div.appendChild(document.createElement('br'));
    				if (postimage_area[postimage_i].nextSibling) {
    					postimage_area[postimage_i].parentNode.insertBefore(postimage_div, postimage_area[postimage_i].nextSibling);
    				} else {
    					postimage_area[postimage_i].parentNode.appendChild(postimage_div);
    				}
    			}
    		}
    	}
    	function postimage_upload(areaid) {
    		window.open("http://postimage.org/index.php?mode=website&areaid=" + areaid + "&hash=1&lang=" + postimage_lang + "&code=&content=family&forumurl=" + escape(document.location.href), "postimage", "resizable=yes,width=500,height=400");
    		return void(0);
    	}
    	if (typeof postimage_text === 'undefined') {
    		if (window.addEventListener) {
    			window.addEventListener('DOMContentLoaded', postimage_insert, false);
    		} else if (window.attachEvent) {
    			window.attachEvent('onload', postimage_insert);
    		}
    	}
    }
    Now at one time a person made what PB calls a plugin to make this work and by doing so it worked in both spots the QR and the NR but for whatever reason the plugin stopped working and the author has totally disappeared giving no support for this plugin. When I use the F12 function with the plugin installed I get this code which one can see is somewhat different for the top code and I'm assuming it's coded to allow for use in the Normal Reply spot?
    Code:
    // MOD Title: Simple Image Upload
    // MOD Author: Sium < admin@postimage.org > (N/A) http://postimage.org/
    // MOD Version: 1.4.0
    
    var postimage_lang = proboards.plugin.get('simple_image_upload').settings.language;
    var postimage_add_text = proboards.plugin.get('simple_image_upload').settings.text;
    
    function postimage_query_string(postimage_search_name) {
    	if (window.location.hash) {
    		postimage_query = window.location.hash.substring(1).split("&");
    		for (postimage_i = 0; postimage_i < postimage_query.length; postimage_i++) {
    			postimage_string_data = postimage_query[postimage_i].split("=");
    			if (postimage_string_data[0] == postimage_search_name) {
    				postimage_string_data.shift();
    				return unescape(postimage_string_data.join("="));
    			}
    		}
    	}
    	return false;
    }
    function postimage_isVisible(e) {
    	return e.offsetWidth > 0 || e.offsetHeight > 0;
    }
    function postimage_isWysiwyg(e) {
    	return (e.className).indexOf('wysiwyg') > -1;
    }
    if (opener) {
    	var postimage_text = postimage_query_string("postimage_text");
    	if (postimage_text) {
    		var postimage_id = postimage_query_string("postimage_id");
    		var postimage_area = opener.document.getElementsByTagName('textarea');
    		for (var postimage_i = 0; postimage_i < postimage_area.length; postimage_i++) {
    			if (postimage_i == postimage_id) {
    				break;
    			}
    		}
    		if (postimage_isWysiwyg(postimage_area[postimage_i])) {
    			var wysiwygId = '#' + postimage_area[postimage_i].id;
    			opener.$(wysiwygId).wysiwyg('setContent', opener.$(wysiwygId).wysiwyg('getContent') + postimage_text);
    		} else {
    			postimage_area[postimage_i].value = postimage_area[postimage_i].value + postimage_text;
    		}
    		opener.focus();
    		window.close();
    	}
    }
    function postimage_insert() {
    	var postimage_area = document.getElementsByTagName('textarea');
    	for (var postimage_i = 0; postimage_i < postimage_area.length; postimage_i++) {
    		if (!postimage_area[postimage_i].name.match(/username_list|search|recipients/i)) {
    			if (postimage_isVisible(postimage_area[postimage_i]) || postimage_isWysiwyg(postimage_area[postimage_i])) {
    				postimage_open = document.createElement('a');
    				postimage_open.id = 'postimage';
    				postimage_open.innerHTML = postimage_add_text;
    				postimage_open.href = "javascript:void(0)";
    				postimage_open.setAttribute('onclick', "window.open('http://postimage.org/index.php?mode=proboards&areaid=" + postimage_i + "&hash=1&lang=" + postimage_lang + "&code=" + proboards.plugin.get('simple_image_upload').settings.bbcode + "&content=" + proboards.plugin.get('simple_image_upload').settings.content + "&forumurl='+escape(document.location.href),'postimage','resizable=yes,width=500,height=400');return false;");
    				postimage_open.setAttribute('class', "button");
    				postimage_open.style.margin = "0px 0px 8px 0px";
    				postimage_open.style.display = "table";
    				postimage_area[postimage_i].parentNode.insertBefore(postimage_open, postimage_area[postimage_i]);
    				if (postimage_isWysiwyg(postimage_area[postimage_i])) {
    					break;
    				}
    			}
    		}
    	}
    }
    if (window.addEventListener) {
    	window.addEventListener('DOMContentLoaded', postimage_insert, false);
    } else if (window.attachEvent) {
    	window.attachEvent('onload', postimage_insert);
    }

    Is there a possibility to make this work in both spots? Thanks

  5. #45
    Join Date
    Oct 2013
    Posts
    169
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Just checking to see if you can look at this again John?

  6. #46
    Join Date
    Oct 2013
    Posts
    169
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Maybe now you have time to look at this again?

  7. #47
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,497
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I will probably have time, but I'm not as confident on this one because we have no control over the actual script. I am encouraged because the postimage link showed up in the shoutbox area without us even asking it to. But I think the way the postimage script works is it fires its setup routines onload of the page or the dom. When that happens, the quick reply editor and the shout editor are visible on the page. To get it to insert itself, make itself available to the full editor we would probably have to get it to setup once the full editor is there. Add to that the fact that the full editor has two modes and that the way postimage works is only appropriate to its bbcode mode I think. In full reply mode you can always use the native image tool. I know, it doesn't seem as robust.

    One thing I notice, when I launch full reply, I still see the postimage button from the quick editor. At the very least we should hide that while the full editor is visible.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #48
    Join Date
    Oct 2013
    Posts
    169
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    Yes John this dot shows up there and go to your profile on the test forum and you'll see it shows up there too. Hit Profile, Edit Profile, then click on Personal and scroll down to the bottom of the page and you'll actually see it twice. I tried some style sheet codes like the one you made to get rid of them but no luck. Is there a way we can make a code to get rid of them all in one code? I have these dots on my forums where I am using this now.

    Also I had a thought, scary I know LOL. I was thinking that it might be possible to go back to image.org and make another button code and put it in the Normal Reply template separate from the QR one? In other words have two codes doing the same thing in different spots? Or if they interfere have a code that blocks one from the other? We know at one time the plugin put this in both spots on the forum, for various reasons it's pretty much quit. PB has had lot's of updates since that time and new browser versions have also came about. The author has disappeared and no one can touch the plugin so the only way this will ever come to be is by someone else making it happen.

    Thanks

  9. #49
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,497
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I dunno if you read my last post or not, but I think I was wrong (so I deleted that post) and I think I've figured this out. It's a little tricky - First I want to do some more testing.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  10. #50
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,497
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    OK, I think Ive got it. Postimages only works in full reply if it is in bbcode view. And it needs to use 1 instead of 0 for the onclick event. So put this script as close to the end of the body as possible:

    Code:
    <script type="text/javascript">
    jQuery(function($){
    	if(/\/post\/new\/\d+/.test(window.location.href)){
    		$('a[onclick="postimage_upload(0);"]').on('click', function(){
    			if(!$('#menu-item-bbcode').hasClass('ui-active')){
    				$('#menu-item-bbcode a').get(0).onclick();
    			}
    			postimage_upload(1);
    		}).get(0).onclick = function(){};
    	}
    	$(window).on('load', function(){$('a[href^="javascript:postimage_upload("]').parent('div').remove();});
    });
    </script>
    It should make sure that the full reply is in bbcode mode if the postimage button is clicked and will change the 0 to 1 for the full reply editor, and it should also get rid of the dot on all pages
    Last edited by jscheuer1; 04-25-2015 at 06:21 AM. Reason: improvement
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Similar Threads

  1. Please write a simple javascript code for me
    By laperashvili in forum JavaScript
    Replies: 2
    Last Post: 06-18-2012, 03:10 PM
  2. adding rollover button to javascript code
    By Repatilian in forum JavaScript
    Replies: 6
    Last Post: 12-04-2011, 10:28 AM
  3. Help with javascript code to make next and previous button dissapear
    By ajmancilla in forum Looking for such a script or service
    Replies: 1
    Last Post: 02-07-2011, 03:00 PM
  4. Looking for a simple Javascript code for a web board
    By donelian in forum Looking for such a script or service
    Replies: 1
    Last Post: 08-15-2007, 10:24 PM
  5. How to turn a menu into a javascript file?
    By Eternal_Howl in forum JavaScript
    Replies: 4
    Last Post: 07-23-2007, 07:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •