11/*==============================================================================================================================
2- | TOKENIZED TOPIC LIST
3- |
4- | Author Katherine Trunkey, Ignia LLC (Katherine.Trunkey@ignia.com)
5- | Client Ignia
6- | Project Topics Editor
7- |
8- | Purpose Provides a "class" wrapper with associated properties set as part of its constructor, as well the
9- | getTokenizedTopics() prototypical extension method, used for instantiating the Token-Input plugin.
10- |
11- >===============================================================================================================================
12- | Revisions Date Author Comments
13- | - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
14- | 04.11.15 Katherine Trunkey Moved Token-Input instantiation out of inline client-side code
15- | 04.14.15 Katherine Trunkey Refactored to TokenizedTopics class structure
16- \-----------------------------------------------------------------------------------------------------------------------------*/
2+ | Author Ignia, LLC
3+ | Client Ignia, LLC
4+ | Project Topics Library
5+ \=============================================================================================================================*/
176
187/*==============================================================================================================================
198| TOKENIZED TOPICS CLASS
9+ >-------------------------------------------------------------------------------------------------------------------------------
10+ | Provides a "class" wrapper with associated properties set as part of its constructor, as well the getTokenizedTopics()
11+ | prototypical extension method, used for instantiating the Token-Input plugin.
2012\-----------------------------------------------------------------------------------------------------------------------------*/
21- var TokenizedTopics = function ( ) {
13+ var TokenizedTopics = function ( ) {
2214
23- 'use strict' ;
15+ 'use strict' ;
2416
2517 /*----------------------------------------------------------------------------------------------------------------------------
2618 | Constructor/internal properties
2719 \---------------------------------------------------------------------------------------------------------------------------*/
28- this . selector = '' ;
29- this . scope = '' ;
30- this . attributeName = '' ;
31- this . attributeValue = '' ;
32- this . searchProperty = 'text' ;
33- this . queryParameter = 'Query' ;
34- this . selectedTopics = '' ;
35- this . resultLimit = '' ;
36- this . tokenLimit = 100 ;
37- this . isAutoPostBack = false ;
20+ this . selector = '' ;
21+ this . scope = '' ;
22+ this . attributeName = '' ;
23+ this . attributeValue = '' ;
24+ this . searchProperty = 'text' ;
25+ this . queryParameter = 'Query' ;
26+ this . selectedTopics = '' ;
27+ this . resultLimit = '' ;
28+ this . tokenLimit = 100 ;
29+ this . isAutoPostBack = false ;
3830
39- } ;
31+ } ;
4032
4133/*==============================================================================================================================
4234| GET TOKENIZED TOPICS (TOKENIZED TOPICS EXTENSION METHOD)
4335\-----------------------------------------------------------------------------------------------------------------------------*/
44- TokenizedTopics . prototype . getTokenizedTopics = function ( ) {
36+ TokenizedTopics . prototype . getTokenizedTopics = function ( ) {
4537
4638 /*----------------------------------------------------------------------------------------------------------------------------
4739 | Scope TokenizedTopics properties to local variable
4840 \---------------------------------------------------------------------------------------------------------------------------*/
49- var self = this ;
41+ var self = this ;
5042
5143 /*----------------------------------------------------------------------------------------------------------------------------
5244 | Build Topics.Json.aspx call URL
5345 \---------------------------------------------------------------------------------------------------------------------------*/
54- var topicsUrl = '/OnTopic/Json/' +
55- self . scope +
56- '?ShowRoot=true' +
57- '&FlattenStructure=true' +
58- '&UsePartialMatch=true' +
59- '&AttributeName=' + self . attributeName +
60- '&AttributeValue=' + self . attributeValue +
61- '&ResultLimit=' + self . resultLimit ;
46+ var topicsUrl = '/OnTopic/Json/' +
47+ self . scope +
48+ '?ShowRoot=true' +
49+ '&FlattenStructure=true' +
50+ '&UsePartialMatch=true' +
51+ '&AttributeName=' + self . attributeName +
52+ '&AttributeValue=' + self . attributeValue +
53+ '&ResultLimit=' + self . resultLimit ;
6254
6355 /*----------------------------------------------------------------------------------------------------------------------------
6456 | Initialize Token-Input with options set on TokenizedTopics
6557 \---------------------------------------------------------------------------------------------------------------------------*/
66- $ ( self . selector ) . tokenInput ( topicsUrl , {
67- propertyToSearch : this . searchProperty ,
68- queryParam : this . queryParameter ,
69- minChars : 3 ,
70- enableHTML : true ,
71- tokenLimit : self . tokenLimit ,
72- preventDuplicates : true ,
73- prePopulate : self . selectedTopics ,
74- theme : 'facebook' ,
75- onAdd : function ( item ) {
76- if ( ! self . isAutoPostBack ) return ;
77- $ ( "form" ) . validate ( ) . cancelSubmit = true ;
78- $ ( "form" ) . submit ( ) ;
79- } ,
80- resultsFormatter : function ( item ) {
81- var breadcrumbs = item . path ;
82- breadcrumbs = breadcrumbs . substring ( 0 , breadcrumbs . indexOf ( item . key ) ) . replace ( new RegExp ( ':' , 'g' ) , ': ' ) ;
83- breadcrumbs = breadcrumbs . replace ( new RegExp ( '([a-z])([A-Z])' , 'g' ) , '$1 $2' ) ;
84- if ( breadcrumbs . indexOf ( 'Root:' ) >= 0 ) {
85- breadcrumbs = breadcrumbs . substring ( breadcrumbs . indexOf ( 'Root:' ) + 5 ) ;
86- }
87- return '' +
88- '<li>' +
89- ' <small class="Breadcrumbs">' + breadcrumbs + '</small>' +
90- ' <div class="Selection">' + item . text + '</div>' +
91- '</li>' ;
58+ $ ( self . selector ) . tokenInput ( topicsUrl , {
59+ propertyToSearch : this . searchProperty ,
60+ queryParam : this . queryParameter ,
61+ minChars : 3 ,
62+ enableHTML : true ,
63+ tokenLimit : self . tokenLimit ,
64+ preventDuplicates : true ,
65+ prePopulate : self . selectedTopics ,
66+ theme : 'facebook' ,
67+ onAdd : function ( item ) {
68+ if ( ! self . isAutoPostBack ) return ;
69+ $ ( "form" ) . validate ( ) . cancelSubmit = true ;
70+ $ ( "form" ) . submit ( ) ;
71+ } ,
72+ resultsFormatter : function ( item ) {
73+ var breadcrumbs = item . path ;
74+ breadcrumbs = breadcrumbs . substring ( 0 , breadcrumbs . indexOf ( item . key ) ) . replace ( new RegExp ( ':' , 'g' ) , ': ' ) ;
75+ breadcrumbs = breadcrumbs . replace ( new RegExp ( '([a-z])([A-Z])' , 'g' ) , '$1 $2' ) ;
76+ if ( breadcrumbs . indexOf ( 'Root:' ) >= 0 ) {
77+ breadcrumbs = breadcrumbs . substring ( breadcrumbs . indexOf ( 'Root:' ) + 5 ) ;
9278 }
93- } ) ;
79+ return '' +
80+ '<li>' +
81+ ' <small class="Breadcrumbs">' + breadcrumbs + '</small>' +
82+ ' <div class="Selection">' + item . text + '</div>' +
83+ '</li>' ;
84+ }
85+ } ) ;
9486
95- } ;
87+ } ;
0 commit comments