-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.summary-07.js
1106 lines (935 loc) · 36.7 KB
/
jquery.summary-07.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/** @file
*
* A simple jQuery widget to present an article along with summarization
* information about that article.
*
* Requires:
* jquery.js
* jquery-ui.js
* jquery.delegateHoverIntent.js
*
* ui.checkbox.js
* ui.sentence.js
*/
(function($) {
/** @brief Summary widget */
$.fn.summary = function(options) {
options = options || {};
return this.each(function() {
var $el = $(this);
$el.data('summary', new $.Summary( $el, options ));
});
};
/** @brief The Summary class */
$.Summary = function($el, options) {
return this.init($el, options);
};
$.Summary.prototype = {
options: {
src: null, // The URL of the original source
metadata: null, /* The URL of the
* summarization/characterization metadata
*/
threshold: { // The desired min/max threshold
min: -1, // If -1,-1, dynamically determine the
max: -1 // threshold based upon 'showSentences'
},
filter: 'normal', // The initial filter (tagged,starred)
showSentences: 5, /* The minimum number of sentences to
* present
*/
quickTag: true, // Using quick tag?
rankOpacity: 0.3, // The default opacity for rank items
animSpeed: 200 // Speed (in ms) of animations
},
/** @brief Initialize this new instance.
* @param el The jQuery DOM element.
* @param options Initialization options.
*
* @return this for a fluent interface.
*/
init: function(el, options) {
var self = this;
var opts = $.extend(true, {}, self.options, options);
self.element = el;
self.options = opts;
self.metadata = null;
self.state = []; // Sentence state based upon their DOM index
var $gp = self.element.parent().parent();
self.$control = $gp.find('.control-pane');
self.$tags = $gp.find('.tags-pane');
self.$threshold = self.$control.find('.threshold');
self.$thresholdValues = self.$threshold.find('.values');
// Initialize any widgets
self.$buttons = self.$control.find('.buttons button').button();
self.$filters = self.$control.find('.filter :checkbox');
self.$options = self.$control.find('.options :checkbox');
/*********************************************************
* controls:threshold
*
*/
self.$control.find('.buttons .expansion').buttonset();
/*********************************************************
* controls:filters
*
*/
var $tagged = self.$filters.filter('#filter-tagged');
var $starred = self.$filters.filter('#filter-starred');
$tagged.checkbox({
cssOn: 'su-icon su-icon-tag-blue',
cssOff: 'su-icon su-icon-tag',
titleOn: 'click to remove filter',
titleOff: 'click to filter',
hideLabel: true
});
$starred.checkbox({
cssOn: 'su-icon su-icon-star-blue',
cssOff: 'su-icon su-icon-star',
titleOn: 'click to remove filter',
titleOff: 'click to filter',
hideLabel: true
});
/*********************************************************
* controls:options
*
*/
var globalOpts = self._getOptions();
var $quickTag = self.$options.filter('#options-quickTag');
$.ui.sentence.options.quickTag = globalOpts.quickTag;
$quickTag.checkbox({
cssOn: 'su-icon su-icon-tagQuick',
cssOff: 'su-icon su-icon-tagQuick-blue',
titleOn: 'click to enable',
titleOff: 'click to disable',
hideLabel: true,
/* Since we use the 'quickTag' icon as an indicator, the logic is a
* little backwards. If the checkbox is NOT checked, we're in
* 'quick' mode, otherwise, 'normal' mode.
*/
checked: (! globalOpts.quickTag )
});
/*********************************************************
* Show the initialized control.
*
*/
self.$control.show();
// Bind events
self._bindEvents();
// Kick off the retrieval of the metadata
self.element.addClass('loading');
var getMetadata = $.get(opts.metadata);
getMetadata.done(function( data ) {
self.metadata = data;
// Perform the initial rendering of the xml
self.render();
self.element.removeClass('loading');
});
getMetadata.fail(function() {
alert("Cannot retrieve metadata '"+ opts.metadata +"'");
});
},
/** @brief Invoked to cleanup this widget. */
destroy: function() {
self._unbindEvents();
},
/** @brief Render the summary information over the main article.
*/
render: function() {
var self = this;
var opts = self.options;
// If we have NOT retrieved the XML meta-data, no rendering.
if (self.metadata === null) { return; }
/* Disable put since we're performing an initial render based upon
* the incoming XML AND any serialized state
*/
self._noPut = true;
// Retrieve the filter state for the current meta-data URL
var state = self._getState(opts.metadata);
if (state)
{
opts.threshold.min = state.threshold.min;
opts.threshold.max = state.threshold.max;
opts.filter = state.filter;
self.state = (state.state ? state.state : []);
}
// Renter the XML
self.renderXml( self.metadata );
// Find all sentences and bucket them based upon 'rank'
self.$p = self.element.find('p');
self.$s = self.$p.find('.sentence');
self.$kws = self.element.find('.keyword');
self.ranks = [];
/* Instantiate the ui.sentence widgets using any parallel serialized
* state.
*/
self.$s.each(function(idex) {
var $el = $(this);
var config = ( self.state.length > idex
? self.state[idex]
: null );
// Instantiate the sentence using the serialized state (if any)
$el.sentence( config );
var rank = $el.sentence('option', 'rank');
if (self.ranks[rank] === undefined) { self.ranks[rank] = []; }
self.ranks[rank].push($el);
});
var threshold = opts.threshold;
if ((opts.threshold.min < 0) || (opts.threshold.max < 0))
{
threshold = self._computeThreshold();
self.origThreshold = threshold;
}
/* Ensure the filter is properly set (without a refresh).
* The refresh will take place when we set the threshold.
*/
self._changeFilter(opts.filter, true);
self.threshold( threshold.min, threshold.max);
// Re-enable put
self._noPut = false;
},
/** @brief Given XML content, convert it to stylable HTML.
* @param xml The XML to render.
*
*/
renderXml: function(xml) {
var self = this;
var opts = self.options;
var $xml = $( xml );
/* Convert the XML to HTML that can be styled.
*
* First, handle any <header>, adding a <header> element BEFORE this
* element.
*/
var $header = $('<header />').appendTo( self.element );
var $doc = $xml.find('document');
var src = $doc.attr('src');
if (src) { opts.src = src; }
$doc.children().each(function() {
var $el = $(this);
switch (this.nodeName)
{
case 'title':
var $h1 = $('<h1 />');
if (opts.src !== null)
{
var $a = $('<a />')
.attr('href', opts.src)
.text( $el.text() )
.appendTo($h1);
}
else
{
$h1.text( $el.text() );
}
$header.append( $h1 );
break;
case 'published':
var str = $el.find('date').text() +' '
+ $el.find('time').text();
var date = new Date(str);
var $time = $('<time />')
.attr('datetime', date.toISOString())
.attr('pubdate', true)
.text(str)
.appendTo($header);
break;
case 'keywords':
// Process any XML <keyword> elements
$('#tmpl-header-keywords')
.tmpl({ keywords: $el.find('keyword') })
.appendTo($header);
break;
case 'body':
// Process any XML <section> elements
$el.find('section').each(function() {
// Leave this for later
var $div = $('<section />')
.appendTo( self.element );
// Convert the XML <p> to an HTML <p>
$(this).find('p').each(function() {
var $p = $('<p />')
.appendTo($div);
// Convert the XML <s> to an HTML <div>
$(this).find('s').each(function() {
var $s = $(this);
var rank = parseFloat($s.attr('rank'));
/* If there is one or more <w> element that does
* NOT have a 'keyword' attribute, don't create
* elements for raw text, just for <w> elements.
*/
var ignoreText = ($s.find('w:not([keyword])')
.length > 0);
if (isNaN(rank)) { rank = 0; }
/* Treat the rank as an integer percentile
* (0 .. 100).
*/
rank = parseInt(rank * 100, 10);
var $sEl = $('#tmpl-sentence')
.tmpl( {rank: rank} )
.appendTo($p);
var $sC = $sEl.find('.content');
/* Mark the sentence with information about whether
* it contains ONLY word elements or if text spans
* contain multiple words.
*/
$sEl.attr('wordElements', ignoreText);
$sEl.find('.rank')
.css('opacity', opts.rankOpacity);
// Assemble the HTML from the XML
$.each(this.childNodes, function() {
var $node = $(this);
switch (this.nodeName)
{
case '#text':
if (ignoreText === true)
{
// Ignore
return;
}
// Fall through
case 'w':
if ($node.attr('keyword'))
{
$('#tmpl-sentence-keyword')
.tmpl( {
keyword:$node.attr('keyword'),
text: $node.text()
} )
.appendTo( $sC );
}
else
{
$('#tmpl-sentence-text')
.tmpl( {
text: $node.text()
} )
.appendTo( $sC );
}
break;
case 'keyword':
$('#tmpl-sentence-keyword')
.tmpl( {
keyword:$node.attr('name'),
text: $node.text()
} )
.appendTo( $sC );
break;
}
});
});
});
});
break;
default:
$header.append( $el );
break;
}
});
},
/** @brief Change the rank threshold.
* @param min The minimum threshold.
* @param max The maximum threshold.
*/
threshold: function( min, max) {
var self = this;
var opts = self.options;
var isExpand = (min < opts.threshold.min);
// Update the threshold and threshold value presentation
opts.threshold.min = min;
opts.threshold.max = max;
self.refresh( isExpand );
},
/** @brief Refresh the presentation based upon the current filter and
* thresholds.
* @param isExpand Is this an
* expansion (true),
* contraction (false) or
* neither (undefined).
*
*/
refresh: function(isExpand) {
var self = this;
var opts = self.options;
var str = opts.threshold.min +' - ' + opts.threshold.max;
self.$thresholdValues.text( str );
/* Initially mark all sentences as 'NOT highlighted' and all
* paragraphs as 'NOT shown'
*/
self.$s.addClass('noHighlight');
if (opts.filter === 'normal')
{
// Show only sentences within the threshold range
for (var idex = opts.threshold.max;
idex >= opts.threshold.min;
idex--)
{
var ar = self.ranks[idex];
if (ar === undefined) { continue; }
var nItems = ar.length;
for (var jdex = 0; jdex < nItems; jdex++)
{
// Mark this sentence as TO BE highlighted
var $s = ar[jdex];
$s.addClass('toHighlight')
.removeClass('noHighlight');
}
}
}
else
{
if (opts.filter.indexOf('tagged') >= 0)
{
/* Show ALL sentences containing one or more tags regardless of
* threshold
*/
self.$s.filter( ':has(.tagged)' )
.addClass('toHighlight')
.removeClass('noHighlight');
}
if (opts.filter.indexOf('starred') >= 0)
{
// Show ALL starred sentences regardless of threshold
self.$s.filter( '.starred' )
.addClass('toHighlight')
.removeClass('noHighlight');
}
}
/* Hide expansion controls for sentences that have no siblings that
* would be expanded.
*/
self.$s.sentence('option', 'noExpansion', false);
self.$p.each(function() {
var $p = $(this);
var $ss = $p.find('.sentence');
if ($ss.length === 1)
{
// Only one sentence period -- Always hide
$ss.sentence('option', 'noExpansion', true);
return;
}
$ss.each(function() {
var $s = $(this);
var $pS = $s.prev();
var $nS = $s.next();
if ($pS.length < 1)
{
// First sentence
if ($s.hasClass('noHighlight') || // is NOT highlighted
($nS.length < 1) || // No next
$nS.hasClass('toHighlight')) // Next is highlighted
{
$s.sentence('option', 'noExpansion', true);
}
}
else if ($nS.length < 1)
{
// Last sentence
if ($s.hasClass('noHighlight') || // is NOT highlighted
($pS.length < 1) || // No previous
$pS.hasClass('toHighlight')) // Prev is highlighted
{
$s.sentence('option', 'noExpansion', true);
}
}
else if ( $pS.hasClass('toHighlight') &&// Prev is highlighted
$nS.hasClass('toHighlight') ) // Next is highlighted
{
$s.sentence('option', 'noExpansion', true);
}
});
});
self.$s
// Hide sentences
.filter('.noHighlight')
.removeClass('noHighlight')
.sentence('unhighlight')
.end()
// Show sentences
.filter('.toHighlight')
.removeClass('toHighlight')
.sentence('highlight');
self._putState();
},
/******************************************************************
* "Private" methods
*
*/
/** @brief Retrieve the current view state.
* @param url The URL to retrieve view state for [ opts.metadata ];
*/
_getState: function(url) {
var self = this;
var opts = self.options;
if (url === undefined) { url = opts.metadata; }
return $.jStorage.get(url);
},
/** @brief Store the current view state.
* @param url The URL to retrieve view state for [ opts.metadata ];
*/
_putState: function(url) {
var self = this;
var opts = self.options;
if (self._noPut === true) { return; }
if (url === undefined) { url = opts.metadata; }
// Remember the current settings
var state = {
threshold: opts.threshold,
filter: opts.filter,
state: self.state // Sentence state
};
$.jStorage.set(url, state);
},
/** @brief Retrieve global options.
*/
_getOptions: function() {
var self = this;
var opts = self.options;
var globalOpts = $.jStorage.get('options:/');
if (! globalOpts)
{
globalOpts = {
quickTag: false
};
}
return globalOpts;
},
/** @brief Store the current global options.
*/
_putOptions: function(url) {
var self = this;
var opts = self.options;
if (self._noPut === true) { return; }
// Remember the current settings
var opts = {
quickTag: opts.quickTag
};
$.jStorage.set('options:/', opts);
},
/** @brief Compute the thresholds based upon opts.showSentences.
*
* @return The new threshold object {min: , max: }
*/
_computeThreshold: function() {
var self = this;
var opts = self.options;
var num = 0;
var threshold = {
min: -1,
max: 100
};
/* Find the highest rank that will include at least opts.showSentences
* sentences.
*/
for (var idex = self.ranks.length - 1; idex > 0; idex--)
{
var ar = self.ranks[idex];
if (ar === undefined) { continue; }
num += ar.length;
if (num > opts.showSentences)
{
threshold.min = Math.floor(idex / 10) * 10;
break;
}
}
return threshold;
},
/** @brief Change the filter value.
* @param filter The new value ('normal', 'tagged', 'starred').
* @param noRefresh If true, do NOT perform a refresh.
*
* @return this for a fluent interface.
*/
_changeFilter: function(filter, noRefresh) {
var self = this;
var opts = self.options;
var $buttons = self.$control.find( '[name=threshold-up],'
+ '[name=threshold-down]');
var filters = (filter
? filter.split(/\s*,\s*/)
: [ 'normal' ]);
$.each(filters, function() {
switch (this.toString())
{
case 'tagged':
$buttons.button('disable');
break;
case 'starred':
$buttons.button('disable');
break;
case 'normal':
default:
filter = 'normal';
$buttons.button('enable');
self.$filters.checkbox('uncheck');
/*
self.$control.find('#filter-normal')
.attr('checked', true)
.button('refresh');
// */
break;
}
});
// Set the filter value
opts.filter = filter;
self.element.removeClass('starred tagged normal')
.addClass(filters.join(' '));
if (noRefresh !== true)
{
// Re-apply the current threshold
self.refresh();
}
return self;
},
/** @brief Set the caret/cursor position within the given element
* @param $el The jQuery/DOM element representing the input control;
* @param pos The desired caret/cursor position;
*/
_bindEvents: function() {
var self = this;
var opts = self.options;
var $parent = self.element.parent();
var $gp = $parent.parent();
/*************************************************************
* Handle clicks on the page-level control buttons.
*
*/
$gp.delegate('.controls input, .controls button', 'click',
function() {
var $el = $(this);
var name = $el.attr('name');
var newMin = opts.threshold.min;
switch (name)
{
case 'threshold-all':
// Set the threshold.min
opts.threshold.min = 0;
// Force 'filter' to 'normal' as well
self._changeFilter();
break;
case 'threshold-reset':
// Reset the threshold.min
if (self.origThreshold === undefined)
{
self.origThreshold = self._computeThreshold();
}
opts.threshold.min = self.origThreshold.min;
// Remove all aging
self.$s.removeClass( 'old-0 old-1 old-2 old-3 old-4 '
+'old-5 old-6 old-7 old-8')
.removeData('age');
// Force 'filter' to 'normal' as well
self._changeFilter();
break;
case 'threshold-down':
// Decrease the minimum threshold
if (newMin > 9) { newMin -= 10; }
self.threshold(newMin, opts.threshold.max);
break;
case 'threshold-up':
// Increase the minimum threshold
if (newMin < (opts.threshold.max - 9)) { newMin += 10; }
self.threshold(newMin, opts.threshold.max);
break;
}
});
/*************************************************************
* Handle changes to the filter and option controls (triggered
* by the ui.checkbox widget).
*
*/
$gp.delegate('.controls .filter, .controls .options', 'change',
function(e, type) {
var $el = $(e.target);
var name = $el.attr('name');
switch (name)
{
case 'filter':
// Assemble the filter as the value of all filter checkboxes
var filter = self.$filters
.map(function() {
return $(this).checkbox('val');
});
self._changeFilter( $.makeArray(filter).join(',') );
break;
case 'quickTag':
/* Since we use the 'quickTag' icon as an indicator, the logic
* is a little backwards. If the checkbox is NOT checked,
* we're in 'quick' mode, otherwise, 'normal' mode.
*/
opts.quickTag = (! $el.checkbox('val') );
$.ui.sentence.options.quickTag = opts.quickTag;
self._putOptions();
break;
}
});
/*************************************************************
* Hover over a keyword changes the color of all keywords
*
*/
$gp.delegateHoverIntent('.keyword', function(e) {
var $kw = $(this);
if ((e.type === 'hover-in') && $kw.hasClass('ui-state-highlight'))
{
// Ignore hover over keywords that are already highlighted
return;
}
var name = $kw.attr('name');
var $kws = self.$kws.filter('[name='+ name +']');
switch (e.type)
{
case 'hover-out':
$kws.removeClass('keyword-hover');
break;
case 'hover-in':
$kws.addClass('keyword-hover');
break;
}
});
/*************************************************************
* Hover over a rank increases the opacity of them all
*
*/
$parent.delegateHoverIntent('.rank', function(e) {
var $el = $(this);
//console.log('.rank hover: '+ e.type);
switch (e.type)
{
case 'hover-out':
// Remove the opacity change for all ranks
self.$s.find('.rank').css('opacity', opts.rankOpacity);
/* Don't let the 'hover-out' propagate so other hover-based
* events won't be inadvertantly triggered
* (e.g. sentence controls hidden).
*/
e.stopPropagation();
break;
case 'hover-in':
self.$s.find('.rank').css('opacity', 1.0);
break;
}
});
/*************************************************************
* Click handler for non-highlighted/hidden sentences
*
*/
$parent.delegate('p', 'click', function(e) {
// '.sentence:not(.highlight,.expanded,.expansion)',
var $p = $(this);
var $t = $(e.target);
var $s;
if ( (! $t.is('p')) && (! $t.hasClass('sentence')) )
{
$t = $t.parents('.sentence:first');
}
if ($t.hasClass('sentence'))
{
if ($t.sentence('isVisible'))
{
// IGNORE clicks on visible sentences
return;
}
// A sentence that isn't currently "visible"
$s = $t;
}
else
{
// Find the sentence nearest the click
var $ss = $p.find('.sentence');
$ss.each(function() {
var $el = $(this);
var bounds = $el.offset();
// Expand the bounds slightly
bounds.top -= 2;
bounds.left -= 2;
bounds.right = bounds.left + $el.width() + 4;
bounds.bottom = bounds.top + $el.height() + 4;
if ( (e.pageX >= bounds.left) &&
(e.pageX <= bounds.right) &&
(e.pageY >= bounds.top) &&
(e.pageY <= bounds.bottom) )
{
$s = $el;
return false;
}
});
if (($s === undefined) || ($s.sentence('isVisible')))
{
/* The final target sentence is either unidentified or
* already visible -- IGNORE
*/
return;
}
}
if ($s.sentence('option', 'noExpansion'))
{
// Is there a highlighted neighbor near by?
var $sib = $s.siblings('.highlight:first');
if ($sib.length < 1)
{
/* No highlighted neighbor. Use the nearest neighbor that
* does NOT have
* '.hide-expand' (from
* ui.sentenct.options.css.noExpansion)
*/
$sib = $s.siblings(':not(.hide-expand):first');
if ($sib.length < 1)
{
/* NO sentences without '.hide-expand'
* Remove 'hide-expand' from the target and toggle
* it.
*/
$s.sentence('option', 'noExpansion', false);
$sib = $s;
}
}
$sib.sentence('toggleOption', 'expanded');
}
else
{
$s.sentence('toggleOption', 'expanded');
}
});
/*************************************************************
* Clicking on a keyword shows all sentences with that keyword
*
*/
$parent.delegate('header .keyword', 'click', function() {
var $kw = $(this);
var toggleOn = (! $kw.hasClass('ui-state-highlight'));
var name = $kw.attr('name');
var $kws = $parent.find('article p .keyword');
var $hl = $kws.filter('[name='+ name +']');
if (toggleOn)
{
// Make any sentence currently visible "older"
self.$s.filter('.highlight,.expansion').older( opts );
// Highlight the keyword control
$kw.addClass('ui-state-highlight');
/* For each keyword that should be highlighted, highlight it
* and ensure that it's containing sentence and paragraph are
* visible.
*/
$hl.each(function() {
var $el = $(this);
var $s = $el.parents('.sentence:first');
var $p = $s.parent();
$el.addClass('ui-state-highlight');
$s.addClass('keyworded', opts.animSpeed);
});
}
else
{
/* For each keyword that should be un-highlighted, un-highlight
* it and then re-apply threshold to ensure a proper filter
*/
$hl.each(function() {
var $el = $(this);
var $s = $el.parents('.sentence:first');
var $p = $s.parent();
$el.removeClass('ui-state-highlight');
var nLeft = $s.find('.keyword.ui-state-highlight').length;
if (nLeft < 1)
{
// No more keywords in this sentence
$s.removeClass('keyworded', opts.animSpeed);
}
});
// Remove any 'old' class
self.$s.filter('[class*=" old"]').younger( opts );
// Remove the highlight from the keyword control
$kw.removeClass('ui-state-highlight');
}
});
/*************************************************************
* Handle any 'sentence-change' events.
*
*/
$parent.delegate('.sentence', 'sentence-change', function(e, type) {
var $s = $(this);