Advertisement:

Calling javascript after pressing preview

Aloittaja bosbeles, elokuu 03, 2013, 08:14:47 AP

« edellinen - seuraava »

bosbeles

I want to write a mod to call a js function after preview button is clicked.
I want my change to be independent from any template.

Which files should I look for?

Thanks.

PS. I'm a newby.

Sir Osis of Liver


The code for post 'Preview' button is in GenericControls.template.php -



if ($editor_context['preview_type'])
echo '
<input type="submit" name="preview" value="', isset($editor_context['labels']['preview_button']) ? $editor_context['labels']['preview_button'] : $txt['preview'], '" tabindex="', $context['tabindex']++, '" onclick="', $editor_context['preview_type'] == 2 ? 'return event.ctrlKey || previewPost();' : 'return submitThisOnce(this);', '" accesskey="p" class="button_submit" />';



The preview itself is in Post.template.php.

When in Emor, do as the Snamors.
                              - D. Lister

bosbeles

Thanks for your answer.
I manually add the following line into Post.template and it works.


echo ' ...
   function onDocSent(XMLDoc)
  {
...

if (typeof(smf_codeFix) != \'undefined\')
smf_codeFix();
                MathJax.Hub.Queue(["Typeset",MathJax.Hub]); // I want to add this
   }';



But I don't know the proper way to create a mod for this.
I wrote a mod called mathjax4smf. It is pending for approval.
My mod is only adding script tag of hxxp:www.mathjax.org/ [nonactive]
So it is simple and proper to add followings to Load.php.


<id>
bosbeles:mathjax4smf
</id>

<version>
1.0
</version>

<edit file>
$sourcedir/Load.php
</edit file>

<search for>
call_integration_hook('integrate_load_theme');
</search for>

<add after>
$context['insert_after_template'] .= '<script type="text/x-mathjax-config;">
  MathJax.Hub.Config({
extensions: ["tex2jax.js"],
jax: ["input/TeX", "output/HTML-CSS"],
tex2jax: {
  inlineMath: [ ["$","$"]],
  displayMath: [ ["$$","$$"]],
  processEscapes: true
},
asciimath2jax: {
  delimiters: ...
},
"HTML-CSS": { availableFonts: ["TeX"], scale: 110 }
  });
</script>
<script type="text/javascript"
   src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_HTMLorMML">
</script>';
</add after>



But due to the nature of preview, the preview_body refresh itself. So the Javascript expression  MathJax.Hub.Queue(["Typeset",MathJax.Hub]); should be called after the preview_body changed.
How can I add this preview issue to my mod?

Advertisement: