xles / hyphenator

Automatically exported from code.google.com/p/hyphenator
GNU General Public License v3.0
0 stars 0 forks source link

How to remove hiding? #208

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi.

CONTEXT
Using jquery.expander.js (https://github.com/kswedberg/jquery-expander) in 
order to display just a snippet of a given text. User can then use a "read 
more" button in order to expand and reveal all text. 

PROBLEM
Hidden text is no hyphenated; it has a class named "hyphenatorXXXhide" ("XXX" 
is a number).

TRIALS
Properties which seem relevant: intermediatestate, selectorfunction, unhide
Using the mergeAndPack tool I have tried:
1. Defining intermediatestate property to visible’ prevents the adding of the 
class hyphenatorXXXhide but text is still not hyphenated.
2. Using selectorfunction with the function given as a draft propted an error: 
“contextWindow is not defined”.
3. Did not find how to use the “unhide” property with the tool.

VERSION
4.0 on mac

Any idea what to do here? Thanks!

Original issue reported on code.google.com by waw...@gmail.com on 31 Dec 2014 at 6:05

GoogleCodeExporter commented 9 years ago
Hi

Thanks for the report.
Unfortunately I don't know a quick solution for that issue, yet.
But I will look at it these days.

Please update to the current version 4.3.0 
(https://code.google.com/p/hyphenator/#October_17,_2014), although I don't 
expect it to solve the problem. But I will base on this current version.

Thanks,
Mathias

Original comment by mathiasn...@gmail.com on 31 Dec 2014 at 7:26

GoogleCodeExporter commented 9 years ago
I was able to reproduce the bug on my machine. Looks like a very nice example 
of a Race Condition.

(My understandings of jQuery and the Expander Plugin are not very deep, so I'm 
not sure if the following is correct.)

Both – Hyphenator.js and the Expander Plugin – are run when the document is 
'ready'. Hyphenator.js does this check when Hyphenator.run() is called. The 
Expander Plugin is called in $(document).ready(). The bug you described occurs 
when the elements Hyphenator.js registered for hyphenation are changed by the 
Exander Plugin before they are actually hyphenated by Hyphenator.js.

For now there are two solutions to avoid this:
A) Call expander() when Hyphenator.js has finished
or
B) Call Hyphenator.run() after expander() has run.

A)
Hyphenator.config({
    'onhyphenationdonecallback': function () {
        $('.expand').expander();
    }
});

B)
$(document).ready(function() {
    $('.expand').expander();
    Hyphenator.run();
});

Since you are using the MergeAndPack-Tool I recommend to use solution B). In 
this case make sure to remove Hyphenator.run() from the output produced by 
MergeAndPack (it's typically the last call).

Hope this helps.

Best regards,
Mathias

PS: I currently can't think of a fix in Hyphenator.js, since we can't 'lock' 
the elements Hyphenator.js is up to hyphenate. But I'll keep this issue open 
for later review.
(Maybe it just needs some documentation.)

Original comment by mathiasn...@gmail.com on 1 Jan 2015 at 10:42

GoogleCodeExporter commented 9 years ago
Hi Mathias and thank you for both your jet fast attention to this issue and 
even taking the time to come up with solutions; this is not something to be 
taken for granted. Thanks also for actually giving code samples.

I have followed your instructions carefully regarding **solution B** but did 
not have any luck; that is, "Hyphenator.run();" does not make the trick - 
nothing is hyphenated.

I then found another call of "Hyphenator.run();" in the generated script - just 
after "Hyphenator.config(Hyphenator.getConfigFromURI());". I have tried to 
delete it, as well - still, no luck.

By the way, as I am using the MergeAndPack tool, I am not sure which version it 
runs (cannot recall why I have decided that I have version 4.0 when first 
posting).

Just to make add that the context I am using it is within Drupal but I do not 
think it matters. Here is the code I use:

Drupal.behaviors.expanderReadMore = {
  attach: function (context, settings) {
    $(document).ready(function() {
      $('.readmore-sameline, .views-field-field-alternative-name').expander({
        slicePoint: 120,
        // more properties here...
      });

      Hyphenator.run();
    });
  }
};

And the generated script, in case it make any sense to read is here: 
http://pastebin.com/21CsX7cH

Thanks again, Amir

Original comment by waw...@gmail.com on 2 Jan 2015 at 2:07

GoogleCodeExporter commented 9 years ago
Hi

This time it took a little longer…

Your code looks fine and it worked for me.

The code you pasted in pastebin has two problems:
a) you set minwordlength to 1o (one followed by the letter o) instead of 10, so 
Javascript emits a parse error and Hyphenator.js doesn't execute.
b) Version X.Y.Z is the trunk version. This is the development version. Please 
use a stable version 
(https://hyphenator.googlecode.com/svn/tags/4.3.0/mergeAndPack.html)

Original comment by mathiasn...@gmail.com on 7 Jan 2015 at 1:47

GoogleCodeExporter commented 9 years ago
Hey Mathias, It works great! 
I have used now the stable version packing tool with the link you gave. 

I will update if I have any news...

Great help - thanks a lot!

Amir

Original comment by waw...@gmail.com on 13 Jan 2015 at 10:42

GoogleCodeExporter commented 9 years ago

Original comment by mathiasn...@gmail.com on 14 Jan 2015 at 11:47