-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjquery.summary-05.js
1774 lines (1499 loc) · 56.7 KB
/
jquery.summary-05.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
* rangy.js
* rangy/seializer.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'
},
view: 'normal', // The initial view (normal,tagged,starred)
showSentences: 5, /* The minimum number of sentences to
* present
*/
lineHeight: -1, /* The height of a single line
* (measured in renderXml() if -1);
*/
useColor: false, // Color sentences based upon rank?
useFolding: false, // Fold empty paragraphs?
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.starred = [];
self.notes = [];
var $gp = self.element.parent().parent();
self.$control = $gp.find('.control-pane');
self.$notes = $gp.find('.notes-pane');
self.$threshold = self.$control.find('.threshold');
self.$thresholdValues = self.$threshold.find('.values');
// Initialize any widgets
self.$control.find('.show,.buttons').buttonset();
rangy.init();
self.cssTag = rangy.createCssClassApplier(
'ui-state-default tagged', {
normalize: true,
elementTagName: 'em'
});
self.cssSelect = rangy.createCssClassApplier('selected', {
normalize: true,
elementTagName: 'em'
});
// Bind events
self._bindEvents();
// Kick off the retrieval of the metadata
var getMetadata = $.get(opts.metadata);
self.element.addClass('loading');
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; }
// Retrieve the view state for the current meta-data URL
var state = self._getState(opts.metadata);
var notes = [];
if (state)
{
opts.threshold.min = state.threshold.min;
opts.threshold.max = state.threshold.max;
opts.view = state.view;
self.starred = (state.starred ? state.starred : []);
if (state.notes) { notes = state.notes; }
}
// 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 = [];
self.$s.each(function() {
var $el = $(this);
var rank = parseInt($el.attr('rank'), 10);
if (isNaN(rank)) { return; }
if (self.ranks[rank] === undefined) { self.ranks[rank] = []; }
if (opts.useColor !== false)
{
// Adjust the color of the sentence based upon the rank
var base = (opts.useColor === true
? 221
: opts.useColor);
var red = base - Math.ceil( base * (rank / 100) );
var green = red;
var blue = red;
var color = 'rgb('+ red +','+ green +','+ blue +')';
$el.css({color:color});
}
self.ranks[rank].push($el);
});
var threshold = opts.threshold;
if ((opts.threshold.min < 0) || (opts.threshold.max < 0))
{
threshold = self._computeThreshold();
self.origThreshold = threshold;
}
// If there were previously starred sentences, mark them now
if (self.starred.length > 0)
{
// Remove any current star markings and apply those indicated by
// self.starred
self.$s.removeClass('starred');
$.each(self.starred, function(idex, val) {
if (val === true)
{
var $s = $( self.$s.get(idex) );
$s.addClass('starred');
}
});
}
// If there were previous tags, mark them now
if (notes.length > 0)
{
var nNotes = notes.length;
self._noPut = true;
for (var idex = 0; idex < nNotes; idex++)
{
var curNotes = notes[idex];
if (! curNotes) { continue; }
var notesInst = new $.Notes( curNotes );
var $tagged = self._addNotes( notesInst.getRange(),
notesInst,
true );
}
self._noPut = false;
}
/* Ensure the view is properly set (without a refresh).
* The refresh will take place when we set the threshold.
*/
self._changeView(opts.view, true);
self.threshold( threshold.min, threshold.max);
},
/** @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 (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');
$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':
$('#tmpl-sentence-text')
.tmpl( {node:$node} )
.appendTo( $sC );
break;
case 'keyword':
$('#tmpl-sentence-keyword')
.tmpl( {node:$node} )
.appendTo( $sC );
break;
}
});
if (opts.lineHeight < 1)
{
opts.lineHeight = $sEl.height();
}
});
});
});
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 view 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.view === 'tagged')
{
/* Show ALL sentences containing one or more tags regardless of
* threshold
*/
self.$s.filter( ':has(.tagged)' )
.addClass('toHighlight')
.removeClass('noHighlight');
}
else if (opts.view === 'starred')
{
// Show ALL starred sentences regardless of threshold
self.$s.filter( '.starred' )
.addClass('toHighlight')
.removeClass('noHighlight');
}
else
{
// 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');
}
}
}
/* Hide expansion controls for sentences that have no siblings that
* would be expanded.
*/
self.$s.removeClass('hide-expand');
self.$p.each(function() {
var $p = $(this);
var $ss = $p.find('.sentence');
if ($ss.length === 1)
{
// Only one sentence period -- Always hide
$ss.addClass('hide-expand');
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.addClass('hide-expand');
}
}
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.addClass('hide-expand');
}
}
else if ( $pS.hasClass('toHighlight') &&// Prev is highlighted
$nS.hasClass('toHighlight') ) // Next is highlighted
{
$s.addClass('hide-expand');
}
});
});
if (opts.useFolding)
{
// Find all paragraphs that contain ONLY '.noHighlight' entries
self.$p.removeClass('folded')
.filter(':not(:has(.toHighlight))')
.addClass('folded').each(function() {
var $p = $(this);
var len = $p.text().length;
$p.css('height', len / 100 +'px');
});
}
// Hide sentences
self.$s.filter('.noHighlight')
.removeClass('noHighlight highlight expanded expansion',
opts.animSpeed * 2,
function() {
var $s = $(this);
if ($s.data('isHighlighted'))
{
$s.younger()
.removeData('isHighlighted');
}
// Hide any associated notes
self._syncNotesPosition( $s );
});
// Show sentences
self.$s.filter('.toHighlight')
.removeClass('toHighlight')
.addClass('highlight', opts.animSpeed * 2, function() {
var $s = $(this);
// Remove any per-sentence expansion indicators.
$s.removeClass('expanded expansion');
// If the current senntence was already highlighted...
if ($s.data('isHighlighted'))
{
// Already highlighted so we need to adjust the age
// expanding (older)
// contracting (younger)
if (isExpand === true)
{
// older
$s.older();
}
else if (isExpand === false)
{
// younger
$s.younger();
}
}
// Sync the position of associated notes
self._syncNotesPosition( $s );
$s.data('isHighlighted', true);
});
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 (url === undefined) { url = opts.metadata; }
// Remember the current settings
var state = {
threshold: opts.threshold,
view: opts.view,
starred: self.starred,
notes: self.notes
};
$.jStorage.set(url, state);
},
/** @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 Given a jQuery DOM sentence element (.sentence), determine
* whether or not it is fully "visible".
* @param $s The jQuery DOM sentence element
*
* @return true | false
*/
_isVisible: function($s) {
return ($s.filter('.highlight,.expanded,.expansion,.keyworded')
.length > 0);
},
/** @brief Given a jQuery DOM sentence element (.sentence),
* turn ON the 'star' setting.
* @param $s The jQuery DOM sentence element
*
*/
_starOn: function($s) {
var self = this;
var opts = self.options;
// Locate the paragraph/sentence number
var sNum = self.$s.index($s);
$s.addClass('starred');
self.starred[sNum] = true;
return this;
},
/** @brief Given a jQuery DOM sentence element (.sentence),
* turn OFF the 'star' setting.
* @param $s The jQuery DOM sentence element
*
*/
_starOff: function($s) {
var self = this;
var opts = self.options;
// Locate the paragraph/sentence number
var sNum = self.$s.index($s);
$s.removeClass('starred');
self.starred[sNum] = false;
return this;
},
/** @brief Given a jQuery DOM sentence element (.sentence),
* toggle the 'star' setting.
* @param $s The jQuery DOM sentence element
*
*/
_toggleStar: function($s) {
var self = this;
// (un)Star this sentence
if ($s.hasClass('starred'))
{
self._starOff($s);
}
else
{
self._starOn($s);
}
return this;
},
/** @brief Sync the position of any notes associated with the provided
* sentence.
* @param $s The jQuery DOM element representing the target sentence.
*/
_syncNotesPosition: function($s) {
var self = this;
var opts = self.options;
var visible = self._isVisible($s);
$s.find('.tagged').each(function() {
var $tagged = $(this);
var $notes = $tagged.data('notes-associate');
if (! $notes)
{
$tagged.removeData('notes-associate');
$tagged.removeClass('.tagged');
return;
}
$notes.notes( (visible ? 'show' : 'hide') );
});
},
/** @brief For every "visible" sentence, ensure that any associated notes
* are properly positioned along side.
*/
_syncNotesPositions: function() {
var self = this;
var opts = self.options;
self.$s.each(function() {
self._syncNotesPosition( $(this) );
});
},
/** @brief Given a jQuery DOM sentence (.sentence), expand it.
* @param $s The jQuery DOM sentence element
*/
_expand: function($s) {
var self = this;
var opts = self.options;
var $p = $s.parents('p:first');
var $el = $s.find('.controls .expand');
var $prev = $s.prev();
var $next = $s.next();
var completionsNeeded = 1;
var expandDone = function() {
var $this = $(this);
$this.addClass('expansion');
$this.css('display', '');
$el.attr('title', 'collapse');
if ( --completionsNeeded < 1)
{
self._syncNotesPositions();
}
};
if ($s.data('isExpanding') || $s.hasClass('expanded'))
{
// Already (being) expanded
return;
}
// Mark this sentence as being expanded
$s.data('isExpanding', true);
$s.addClass('expanded', opts.animSpeed, expandDone);
if (opts.useFolding)
{
if ($p.hasClass('folded'))
{
$p.removeClass('folded')
.addClass('un-folded');
}
}
// If the previous sibling is NOT visible...
if (! self._isVisible( $prev ) )
{
completionsNeeded++;
$prev.addClass('expansion', opts.animSpeed, expandDone);
}
// If the next sibling NOT is visible...
if (! self._isVisible( $next ) )
{
completionsNeeded++;
$next.addClass('expansion', opts.animSpeed, expandDone);
}
// Remove our marker indicating that this sentence is being expanded
$s.removeData('isExpanding');
return this;
},
/** @brief Given a jQuery DOM sentence (.sentence), collapse it.
* @param $s The jQuery DOM sentence element
*/
_collapse: function($s) {
var self = this;
var opts = self.options;
var $p = $s.parents('p:first');
var $el = $s.find('.controls .expand');
var $prev = $s.prev();
var $next = $s.next();
var completionsNeeded = 1;
var collapseDone = function() {
if ( --completionsNeeded > 0) { return; }
$s.removeClass('expansion');
if (! $s.hasClass('highlight'))
{
/* The target sentence is NOT highlighted, so ensure that
* sentence controls are hidden and NOT in "hover mode" and any
* selection controls are removed.
*/
$s.removeClass('ui-hover');
$s.find('.controls .su-icon').css('opacity', '');
$s.find('.selection-controls').remove();
}
// Change the expand/contract title back to "expand"
$el.attr('title', 'expand');
if (opts.useFolding)
{
if ($p.hasClass('un-folded'))
{
/* If this was the last expanded sentence in this
* paragraph, change the paragraph marking BACK to 'folded'
*/
if ($p.find(':has(.highlight))').length < 1)
{
$p.removeClass('un-folded')
.addClass('folded');
}
}
}
self._syncNotesPositions();
// Mark collapse completed
$s.removeData('isCollapsing');
};
var collapseExpansion = function($sib) {
completionsNeeded++;
$sib.removeClass('expansion', opts.animSpeed, collapseDone);
if ($sib.hasClass('expanded'))
{
self._collapse($sib);
}
};
if ($s.data('isCollapsing'))
{
// This sentence is already being collapsed
return;
}
if ($s.hasClass('expanded'))
{
$s.removeClass('expanded', opts.animSpeed);
}
else if (! $s.hasClass('expansion'))
{
return;
}
// Mark this sentence as being collapsed
$s.data('isCollapsing', true);
// If the previous sibling is visible...
if ($prev.hasClass('expansion'))
{
collapseExpansion($prev);
}
// If the next sibling is visible...
if ($next.hasClass('expansion'))
{
collapseExpansion($next);
}
collapseDone();
return this;
},
/** @brief Given a jQuery DOM sentence element (.sentence),
* toggle the expand/collapse setting.
* @param $s The jQuery DOM sentence element
*
*/
_toggleExpand: function($s) {
var self = this;
var opts = self.options;
var $el = $s.find('.controls .expand');
if ($s.hasClass('expanded'))
{
// Collapse
self._collapse($s);
}
else
{
// Expand
self._expand($s);
}
return this;
},
/** @brief Change the view value.
* @param view The new value ('normal', 'tagged', 'starred').
* @param noRefresh If true, do NOT perform a refresh.
*
* @return this for a fluent interface.
*/
_changeView: function(view, noRefresh) {
var self = this;
var opts = self.options;
var $buttons = self.$control.find( '[name=threshold-up],'
+ '[name=threshold-down]');
switch (view)
{
case 'tagged':
$buttons.button('disable');
self.$control.find('#view-tagged')
.attr('checked', true)
.button('refresh');
break;
case 'starred':
$buttons.button('disable');
self.$control.find('#view-starred')
.attr('checked', true)
.button('refresh');
break;
case 'normal':
default:
view = 'normal';
$buttons.button('enable');
self.$control.find('#view-normal')
.attr('checked', true)
.button('refresh');
break;
}
// Set the view value
opts.view = view;
self.element.removeClass('starred tagged normal')
.addClass(view);
if (noRefresh !== true)
{
// Re-apply the current threshold
self.refresh();
}
return self;
},
/** @brief Given a rangy selection object, generate a corresponding
* summary range string.
* @param sel The rangy selection object. If not provided,
* retrieve the current rangy selection.
*
* @return A range string of the form 'ss/se:so,es/ee:eo'.
*/
_generateRange: function(sel) {
if (sel === undefined) { sel = rangy.getSelection(); }
var self = this;
var opts = self.options;
var ranges = sel.getAllRanges();
/* Compute the indices of the sentences, .text/.keyword
* children, and text offsents.
*/
var start = ranges[0];
var end = ranges[ ranges.length - 1];
/* A sentence range is the sentence index, child index,
* and offset in the form:
* si/ci:offset
*
* Grab the start and end sentence along with an array of
* sentences between the two.
*/
var $sStart = $(start.startContainer).parents('.sentence:first');
var $sEnd = $(end.endContainer).parents('.sentence:first');
var sRange = {
start: self.$s.index( $sStart ) +'/'
+ rangy.serializePosition(
start.startContainer,
start.startOffset,
$sStart.find('.content')[0]),
end: self.$s.index( $sEnd ) +'/'
+ rangy.serializePosition(
end.endContainer,
end.endOffset,
$sEnd.find('.content')[0])
};
console.log("_generateRange: "+ sRange.start +','+ sRange.end);
return sRange.start +','+ sRange.end;
},
/** @brief Given a range object from _generateRange(), create a new
* $.Notes object to associate with all items within the range.
* The elements within the range will also be wrapped in one or
* more '.tagged' containers.
* @param range A range string from _generateRange()
* @param notes If provided, a $.Notes instance representing the
* existing notes;
* @param hide If true, hide the notes widget once created.
*