Question about code writing for javascript

Discussion forum for Extension Writers regarding Extension Development.
Post Reply
User avatar
Meis2M
Translator
Posts: 883
Joined: Wed Mar 03, 2010 11:32 am
Location: IR.Damghan
Name: میثم نوبری
Contact:

Question about code writing for javascript

Post by Meis2M » Thu Oct 24, 2019 6:38 pm

hi
i have a code

Code: Select all

				$this->template->assign_vars(array(
					'S_SEO_HTACCESS'	=> 1,
				));
this is my javascript and not working well. can you help me plz

Code: Select all

<!-- IF S_SEO_HTACCESS -->
<script type="text/javascript">
// <![CDATA[
$(document).ready(function() {
	var seo_rewrite_engines = {SEO_REWRITE_ENGINES};
	$(seo_rewrite_engines).each(function(i) {
		var engine = seo_rewrite_engines[i];
		if (!engine) {
			return true;
		}
		if ($("#" + engine + "_toggle").length) {
			$("#" + engine + "_toggle").on('click', function() {
				var $this = $("#" + engine + "_code");
				if ($this.is(":visible")) {
					$this.hide(300);
				} else {
					$this.show(300);
				}
			}).css({cursor:"pointer"});
			$("#" + engine + "_select").on('click', function() {
				var
					doc = document,
					text = doc.getElementById(engine + "_code_select"),
					range,
					selection;
				if (doc.body.createTextRange) { //ms
					range = doc.body.createTextRange();
					range.moveToElementText(text);
					range.select();
				} else if (window.getSelection) { //all others
					selection = window.getSelection();
					range = doc.createRange();
					range.selectNodeContents(text);
					selection.removeAllRanges();
					selection.addRange(range);
				}
			}).css({cursor:'pointer'});
		}
	});
});
// ]]>
</script>
phpBB persian international support
Ultimate SEO Friendly URL - Extension
Follow us in Instagram
Free upgrade and install extensions on your forum - drop me PM

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1178
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Question about code writing for javascript

Post by mrgoldy » Sun Oct 27, 2019 12:28 pm

Well, with nothing to go on other than 'it doesnt work well' (which isn't much), I will start guessing and suggest trying to wrap it in a jQuery declaring function.

Code: Select all

<script>
	(function($) {
		$(function() {
			var seo_rewrite_engines = {SEO_REWRITE_ENGINES};
			// etc..
		}):
	});
</script>
Moreover, you probably copied the second part of your code from somewhere, as all of a sudden you dropped back to vanilla javascript.
Anyways, you really need to specify a bit more what is working and what isn't, what the exact culprit is.

User avatar
Meis2M
Translator
Posts: 883
Joined: Wed Mar 03, 2010 11:32 am
Location: IR.Damghan
Name: میثم نوبری
Contact:

Re: Question about code writing for javascript

Post by Meis2M » Sun Nov 03, 2019 9:38 am

is there any wrong code that is not compatible with 3.2?

Code: Select all

			case 'server':
			$this->template->assign_vars(array(
					'S_SEO_HTACCESS'	=> 1,
				));
				$display_vars['title'] = 'ACP_REWRITE_CONF';
            	$display_vars['description'] =  $this->language->lang('ACP_REWRITE_CONF_EXPLAIN') . '</p><hr/><p><b>' . $this->user->lang('ACP_PHPBB_SEO_VERSION') . ' : ' . $this->modrtype_lang['link'] . ' - ( ' . $this->modrtype_lang['forumlink'] . ' )</b></p><p>';
				$display_vars['vars'] = array();
				$display_vars['vars']['legend1'] = 'ACP_REWRITE_CONF';
				if ($this->core->seo_path['phpbb_script'] && !$this->core->seo_opt['virtual_root'])
				{
					$display_vars['vars']['rbase'] = array('lang' => 'SEO_SERVER_CONF_RBASE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true);
				}
				$display_vars['vars']['save'] = array('lang' => 'SEO_SERVER_CONF_SAVE', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true);
				$display_vars['vars']['more_options'] = array('lang' => 'SEO_MORE_OPTION', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true);
				$this->new_config['save'] = false;
				$cfg_array = ($this->request->is_set('config')) ? utf8_normalize_nfc($this->request->variable('config', array('' => ''), true)) : $this->new_config;
				$this->new_config['more_options'] = isset($cfg_array['more_options']) ? $cfg_array['more_options'] : false;
				$this->new_config['slash'] = isset($cfg_array['slash']) ? $cfg_array['slash'] : false;
				$this->new_config['wslash'] = isset($cfg_array['wslash']) ? $cfg_array['wslash'] : false;
				$this->new_config['rbase'] = isset($cfg_array['rbase']) ? $cfg_array['rbase'] : false;

				if ($this->new_config['more_options'])
				{
					$display_vars['vars']['slash'] = array('lang' => 'SEO_SERVER_CONF_SLASH', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true);
					$display_vars['vars']['wslash'] = array('lang' => 'SEO_SERVER_CONF_WSLASH', 'validate' => 'bool', 'type' => 'radio:yes_no', 'explain' => true);
				}

				// Dirty yet simple templating
				$display_vars['description'] = $this->language->lang('ACP_REWRITE_CONF_EXPLAIN') . $this->seo_server_conf();

	

				break;
phpBB persian international support
Ultimate SEO Friendly URL - Extension
Follow us in Instagram
Free upgrade and install extensions on your forum - drop me PM

Paul
Infrastructure Team Leader
Infrastructure Team Leader
Posts: 25454
Joined: Sat Dec 04, 2004 3:44 pm
Location: The netherlands.
Name: Paul Sohier
Contact:

Re: Question about code writing for javascript

Post by Paul » Sun Nov 03, 2019 9:51 am

You will need to explain a bit more. We are not going to debug your code.
Knock knock
Race condition
Who's there?

My BlogMy Photosmy phpBB Extensionscustom phpBB work & Development

User avatar
Meis2M
Translator
Posts: 883
Joined: Wed Mar 03, 2010 11:32 am
Location: IR.Damghan
Name: میثم نوبری
Contact:

Re: Question about code writing for javascript

Post by Meis2M » Sun Nov 03, 2019 10:01 am

in my extension https://github.com/phpbb-seo in acp i have a problem, in phpBB 3.1 when going to ACP = phpBB-seo (Tab) = Server Config there was .htaccess codes that we can copy it and paste into .htacess in root, but in phpBB 3.2 .htaccess codes not appear again !

https://github.com/phpbb-seo/usu/blob/8 ... u.php#L324
https://github.com/phpbb-seo/usu/blob/8 ... .php#L1102
phpBB persian international support
Ultimate SEO Friendly URL - Extension
Follow us in Instagram
Free upgrade and install extensions on your forum - drop me PM

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1178
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Question about code writing for javascript

Post by mrgoldy » Sun Nov 03, 2019 10:17 pm

well, it looks like you create the htaccess text and assign it to $display_vars['description'], overriding the value set above.
However, this variable is never assigned to the template, so it will not be displayed.

User avatar
Meis2M
Translator
Posts: 883
Joined: Wed Mar 03, 2010 11:32 am
Location: IR.Damghan
Name: میثم نوبری
Contact:

Re: Question about code writing for javascript

Post by Meis2M » Mon Nov 04, 2019 7:15 am

mrgoldy wrote:
Sun Nov 03, 2019 10:17 pm
well, it looks like you create the htaccess text and assign it to $display_vars['description'], overriding the value set above.
However, this variable is never assigned to the template, so it will not be displayed.

i think my problem is in below pulls right?
https://github.com/phpbb-seo/usu/pull/14
https://github.com/phpbb-seo/usu/pull/13
https://github.com/phpbb-seo/usu/pull/15
phpBB persian international support
Ultimate SEO Friendly URL - Extension
Follow us in Instagram
Free upgrade and install extensions on your forum - drop me PM

User avatar
mrgoldy
Jr. Extension Validator
Posts: 1178
Joined: Tue Oct 06, 2009 7:34 pm
Location: The Netherlands
Name: Gijs
Contact:

Re: Question about code writing for javascript

Post by mrgoldy » Mon Nov 04, 2019 8:50 am

There are many problems with that code, but yes, pull #15 is the issue.
https://github.com/phpbb-seo/usu/pull/1 ... 4171c9L350
As there you change it from assigning it to a language variable (which isn't the right thing to do in the first place), to an unassigned variable.
You will have to use something like this in php
$this->template->assign_var('MY_HTACCESS_FILE', $this->seo_server_conf());
And then the following in template:
{{ lang('ACP_REWRITE_CONF_EXPLAIN', MY_HTACCESS_FILE) }}

Post Reply

Return to “Extension Writers Discussion”