@@ -47,26 +47,82 @@ function redirectWithParam(key, value) {
47
47
}
48
48
}
49
49
50
- jQuery ( function ( ) {
51
- jQuery ( "#suggest-friends" ) . tokenInput ( ajaxurl + "?fb-friends=1&action=fb_friend_page_autocomplete&autocompleteNonce=" + FBNonce . autocompleteNonce , {
52
- theme : "facebook" ,
53
- preventDuplicates : true ,
54
- hintText : "Type to find a friend." ,
55
- animateDropdown : false ,
56
- noResultsText : "No friend found." ,
57
- } ) ;
58
- } ) ;
50
+ function fbShowDebugInfo ( ) {
51
+ jQuery ( "#debug-output" ) . show ( ) ;
52
+ }
59
53
60
- jQuery ( function ( ) {
61
- jQuery ( "#suggest-pages" ) . tokenInput ( ajaxurl + "?fb-pages=1&action=fb_friend_page_autocomplete&autocompleteNonce=" + FBNonce . autocompleteNonce , {
62
- theme : "facebook" ,
63
- preventDuplicates : true ,
64
- hintText : "Type to find a page." ,
65
- animateDropdown : false ,
66
- noResultsText : "No page found." ,
67
- } ) ;
68
- } ) ;
54
+ // avoid collisions
55
+ var FB_WP = FB_WP || { } ;
56
+ FB_WP . admin = {
57
+ friend_suggest : { hint :"Type to find a friend." , noresults :"No friend found." } , // TODO: override me with translations
58
+ page_suggest : { hint :"Type to find a page." , noresults :"No page found." } ,
59
+ short_number : function ( num ) {
60
+ if ( num > 1000000 ) {
61
+ return Math . round ( ( num / 1000000 ) ) . toString ( ) + "m" ;
62
+ } else if ( num > 1000 ) {
63
+ return Math . round ( ( num / 1000 ) , 0 ) . toString ( ) + "k" ;
64
+ }
69
65
70
- function fbShowDebugInfo ( ) {
71
- jQuery ( '#debug-output' ) . show ( ) ;
72
- }
66
+ return num ;
67
+ } ,
68
+ token_input : { // loopj jquery-token-input
69
+ friends : function ( ) {
70
+ jQuery ( "#suggest-friends" ) . tokenInput ( ajaxurl + "?" + jQuery . param ( { "fb-friends" :1 , "action" :"fb_friend_page_autocomplete" , "autocompleteNonce" :FBNonce . autocompleteNonce } ) , {
71
+ theme : "facebook" ,
72
+ preventDuplicates : true ,
73
+ hintText : FB_WP . admin . friend_suggest . hint ,
74
+ animateDropdown : false ,
75
+ noResultsText : FB_WP . admin . friend_suggest . noresults ,
76
+ resultsFormatter : function ( friend ) {
77
+ // we want at least a name
78
+ if ( friend . name === undefined ) {
79
+ return "" ;
80
+ }
81
+ var li = jQuery ( "<li />" ) ;
82
+ // picture served in HTTP scheme
83
+ // no mixed content just to make the list item pretty
84
+ if ( document . location . protocol === "http:" && friend . uid !== undefined ) {
85
+ li . append ( jQuery ( "<img />" ) . attr ( { width :25 , height :25 , src :"http://graph.facebook.com/" + friend . uid + "/picture?width=25&height=25" , alt :friend . name } ) . css ( "margin-right" , "2em" ) ) ;
86
+ }
87
+ li . append ( jQuery ( "<span />" ) . text ( friend . name ) . text ( ) ) ;
88
+ return jQuery ( "<ul />" ) . append ( li ) . html ( ) ;
89
+ }
90
+ } ) ;
91
+ } ,
92
+ pages : function ( ) {
93
+ jQuery ( "#suggest-pages" ) . tokenInput ( ajaxurl + "?" + jQuery . param ( { "fb-pages" :1 , "action" :"fb_friend_page_autocomplete" , "autocompleteNonce" :FBNonce . autocompleteNonce } ) , {
94
+ theme : "facebook" ,
95
+ preventDuplicates : true ,
96
+ hintText : FB_WP . admin . page_suggest . hint ,
97
+ animateDropdown : false ,
98
+ minChars : 2 ,
99
+ noResultsText : FB_WP . admin . page_suggest . noresults ,
100
+ resultsFormatter : function ( page ) {
101
+ // we want at least a name
102
+ if ( page . name === undefined ) {
103
+ return "" ;
104
+ }
105
+ var li = jQuery ( "<li />" ) ;
106
+ // account for no image or image inclusion causing mixed scheme
107
+ if ( document . location . protocol === "http:" && page . image !== undefined ) {
108
+ li . append ( jQuery ( "<img />" ) . attr ( { width :25 , height :25 , src :page . image , alt :page . name } ) . css ( "margin-right" , "2em" ) ) ;
109
+ }
110
+ var text = page . name ;
111
+ if ( page . likes !== undefined ) {
112
+ text = text + " (" + FB_WP . admin . short_number ( page . likes ) + " likes)" ;
113
+ }
114
+ li . append ( jQuery ( "<span />" ) . text ( text ) . text ( ) ) ;
115
+ return jQuery ( "<ul />" ) . append ( li ) . html ( ) ;
116
+ }
117
+ } ) ;
118
+ }
119
+ } ,
120
+ init : function ( ) {
121
+ FB_WP . admin . token_input . friends ( ) ;
122
+ FB_WP . admin . token_input . pages ( ) ;
123
+ }
124
+ } ;
125
+
126
+ jQuery ( function ( ) {
127
+ FB_WP . admin . init ( ) ;
128
+ } ) ;
0 commit comments