Page 6 of 8 FirstFirst ... 45678 LastLast
Results 51 to 60 of 80

Thread: Turn simple javascript code to a button

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

    Default

    Works like a charm John! Only one thing, still have the dot on the Normal Reply window and profiles. Now I just accidently discovered that people when the plugin was working had the same problem with the dots and button appearing where they didn't want it to. Seems a mod there made some CSS fixes like you did for the shoutbox and some work some don't with our code, again we now have a updated code that works;

    Here's what they did:
    Code:
    div.shoutbox.container.full a.button{display:none!important;
    }
    div.settings.content-box a.button{display:none!important;
    }
    div.personal.content-box a.button{display:none!important;
    }
    div.staff.content-box a.button{display:none!important;

    Now I changed them all to this and of course put them in the style sheet:

    Code:
    .shoutbox_form.content-box div {display: none;}
    .settings.content-box a.button{display:none;}
    .personal.content-box a.button{display:none;}
    .staff.content-box a.button{display:none;}
    The top two do work as we know the shoutbox one you created is just like the other code but two of the codes which are for the profile area do not work at all:


    Code:
    .personal.content-box a.button{display:none;}
    .staff.content-box a.button{display:none;}
    The second code which removed the dot from the Normal Reply posting page works but with what I call a delayed effect. In other words when you open the NR page the dot is there and in a few seconds it disappears in front of your eyes. I'm thinking it may have to do with the fact you made your code to remove the dots too even though it doesn't?

    Oh that code again is the second one:

    Code:
    .settings.content-box a.button{display:none;}
    Last edited by JRR; 04-25-2015 at 11:51 AM.

  2. #52
    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

    If it's delayed, it's probably not the css, rather the javascript code we added. Let me double check. OK, it looks like it is the javascript that's doing it:

    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 takes the dot away after the window loads. I did it that way because the css to hide it for this page would be cumbersome at best, and as I remembered, postimages initialized on window load, and you cannot take something away until it's there. But many browsers initialize postimages sooner. We can accelerate removal in browsers that create the dot sooner by checking for it more and at earlier times:

    Code:
    <script type="text/javascript">
    $('a[href^="javascript:postimage_upload("]').parent('div').remove();
    jQuery(function($){
    	$('a[href^="javascript:postimage_upload("]').parent('div').remove();
    	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>
    Now, I have a question for you. Is this a separate template? I ask because the script we just added looks like it's only on the normal replay page. If so, is the Insert Image link button on the normal reply page also unique to that page? If both of these are only on the normal reply page, the code can be simplified.
    - John
    ________________________

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

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

    Default

    Yes they are both on totally separate templates. I put one button in the QR template and the other one in the NR template plus the new javascript code at the bottom of the NR template only.

    Is the last code what I should put in with the last changes or just the high lighted part?

  4. #54
    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

    If the question is should the last script replace the other script, yes it should/would. But if this is a unique template, change the button to:

    Code:
    <a href="javascript:void(0);" onclick="postimage_upload(1);" class="button">Insert Image</a>
    and replace the script with:

    Code:
    <script type="text/javascript">
    $('a[href^="javascript:postimage_upload("]').parent('div').remove();
    jQuery(function($){
    	$('a[href^="javascript:postimage_upload("]').parent('div').remove();
    	$('a[onclick="postimage_upload(1);"]').on('click', function(){
    		if(!$('#menu-item-bbcode').hasClass('ui-active')){
    			$('#menu-item-bbcode a').get(0).onclick();
    		}
    	});
    	$(window).on('load', function(){$('a[href^="javascript:postimage_upload("]').parent('div').remove();});
    });
    </script>
    Last edited by jscheuer1; 04-25-2015 at 04:19 PM. Reason: simplify script more
    - John
    ________________________

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

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

    Default

    John inserted your last code and dot still disappears on a time delayed basis, may even be slower?

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

    Default

    OK we were posting at the same time, will do now

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

    Default

    All done John and dot still disappears on a time delayed basis, it's actually taking more time to disappear now than before.

  8. #58
    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

    Yep. does seem that way, let's use this script instead then:

    Code:
    <script type="text/javascript">
    jQuery(function($){
    	$('a[onclick="postimage_upload(1);"]').on('click', function(){
    		if(!$('#menu-item-bbcode').hasClass('ui-active')){
    			$('#menu-item-bbcode a').get(0).onclick();
    		}
    	});
    	$(window).on('load', function(){$('a[href^="javascript:postimage_upload("]').parent('div').remove();});
    });
    </script>
    And I have another idea - to stop postimages from creating the dot in the first place. I'll let you know when I write it out.
    - John
    ________________________

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

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

    Default

    Ok John got it changed and awaiting your instructions.

  10. #60
    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

    Alright, I just deleted a post because I found a way to test it, and it didn't work. This works in testing. Add this script right after the postimage script (highlighted as shown):

    Code:
    		<script type="text/javascript" src="http://mod.postimage.org/website-english-family.js" charset="utf-8"></script>
    <script type="text/javascript">
    if(window.addEventListener){window.removeEventListener('DOMContentLoaded',postimage_insert,false);}else if(window.attachEvent){window.detachEvent('onload',postimage_insert);}
    </script>
    		<script type="text/javascript">
    if(/postimage_id/.test(location.href)){location.href = 'about:blank';}
    </script>
    That should work for all pages. If it does we can get rid of all the styles that were added for hiding the dot and postimage link (keep the styles we added for the time script and edit/delete buttons). Also, the script for the normal reply can be simplified further. Before we do any of that though, let's make sure the above works for the normal reply.
    Last edited by jscheuer1; 04-25-2015 at 06:28 PM. Reason: detail
    - 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
  •