Browse Source

Formatting

master
Chimo 4 years ago
parent
commit
5c1452e5dc
4 changed files with 149 additions and 119 deletions
  1. 10
    0
      .jscsrc
  2. 14
    0
      .jshintrc
  3. 4
    6
      hovercard.css
  4. 121
    113
      hovercard.js

+ 10
- 0
.jscsrc View File

@@ -0,0 +1,10 @@
1
+{
2
+	"preset": "jquery",
3
+	// Preset overrides
4
+	"requireCamelCaseOrUpperCaseIdentifiers": null,
5
+	"maximumLineLength": 500,
6
+	// Additional preset tightening
7
+	"requireBlocksOnNewline": true,
8
+	"requireSpaceBeforeBlockStatements": true,
9
+	"disallowMixedSpacesAndTabs": true
10
+}

+ 14
- 0
.jshintrc View File

@@ -0,0 +1,14 @@
1
+{
2
+	"boss": true,
3
+	"curly": true,
4
+	"eqeqeq": true,
5
+	"eqnull": true,
6
+	"expr": true,
7
+	"immed": true,
8
+	"noarg": true,
9
+	"undef": true,
10
+	"unused": true,
11
+	"jquery": true,
12
+	"browser": true,
13
+	"es3": true
14
+}

+ 4
- 6
hovercard.css View File

@@ -1,8 +1,8 @@
1 1
 .sn-hovercard {
2
-  background-color: #FFF;
2
+  background-color: #fff;
3 3
   border: 1px solid #000;
4 4
   border-radius: 5px;
5
-  box-shadow: 2px 2px 2px #CCC;
5
+  box-shadow: 2px 2px 2px #ccc;
6 6
   display: none;
7 7
   font-size: small;
8 8
   position: absolute;
@@ -32,8 +32,8 @@
32 32
 }
33 33
 
34 34
 .sn-hovercard .hc-actions {
35
-  background-color: #EEE;
36
-  border-top: 1px solid #CCC;
35
+  background-color: #eee;
36
+  border-top: 1px solid #ccc;
37 37
   border-radius: 0 0 5px 5px;
38 38
   padding: 5px;
39 39
 }
@@ -55,5 +55,3 @@
55 55
 #hc-profile {
56 56
   margin-bottom: 5px;
57 57
 }
58
-
59
-

+ 121
- 113
hovercard.js View File

@@ -1,167 +1,175 @@
1
-(function ($) {
2
-    // private
3
-    function buildHTML(data, group) {
4
-        var at = '',
5
-            desc = 'Description',
6
-            notices = '',
7
-            latest = '',
8
-            subs = 'members',
1
+( function( $ ) {
2
+    /* private */
3
+    function buildHTML( data, group ) {
4
+        var at = "",
5
+            desc = "Description",
6
+            notices = "",
7
+            latest = "",
8
+            subs = "members",
9 9
             html,
10
-            uid = (new Date).getTime();
10
+            uid = new Date().getTime();
11 11
 
12 12
         // Redefine some things if we're dealing with @user
13
-        if (!group) {
14
-            at   = '@';
15
-            desc = 'Bio';
16
-            subs = 'subscribers';
17
-            notices = '<span class="hc-notices">\
18
-                    <span class="hc-count">' + data.statuses_count + '</span> notices,\
19
-                    </span>';
20
-            latest = '<h3>Latest</h3>\
21
-                <span class="hc-status">' + data.status.text + '</span>';
13
+        if ( !group ) {
14
+            at   = "@";
15
+            desc = "Bio";
16
+            subs = "subscribers";
17
+            notices = "<span class='hc-notices'>" +
18
+                    "<span class='hc-count'>" + data.statuses_count + "</span> notices," +
19
+                    "</span>";
20
+            latest = "<h3>Latest</h3>" +
21
+                "<span class='hc-status'>" + data.status.text + "</span>";
22 22
         }
23 23
 
24
-        html = '<div class="sn-hovercard">\
25
-                  <div class="hc-content">\
26
-                    <h2>' + (data.name || data.fullname) + '</h2>\
27
-                    <a href="' + (data.statusnet_profile_url || data.url) + '">' + at + (data.screen_name || data.fullname) + '\
28
-                      <img src="' + (data.profile_image_url || data.stream_logo) + '" />\
29
-                    </a>\
30
-                    <p class="hc-stats">\
31
-                      ' + notices + '\
32
-                      <span class="hc-subs">\
33
-                        <span class="hc-count">' + (data.friends_count || data.member_count) + '</span> ' + subs + '\
34
-                      </span>\
35
-                    </p>\
36
-                    <h3>' + desc + '</h3>\
37
-                    <span class="hc-bio">' + (data.description || '') + '</span>\
38
-                    ' + latest + '\
39
-                  </div>\
40
-                  <div class="hc-actions"><a href="#" class="hc-follow">subscribe</a>\
41
-                  <div class="hc-follow-form">\
42
-                    <form>\
43
-                      <fieldset>\
44
-                        <label for="hc-profile-' + uid + '">Your Accound ID</label>\
45
-                        <input id="hc-profile-' + uid + '" type="text" placeholder="e.g. user@identi.ca" />\
46
-                        <input type="hidden" name="profile" value="' + (data.statusnet_profile_url || data.url) + '" />\
47
-                        <button type="submit">Subscribe</button>\
48
-                      </fieldset>\
49
-                    </form>\
50
-                  </div>\
51
-                </div>\
52
-              </div>';
24
+        html = "<div class='sn-hovercard'>" +
25
+                  "<div class='hc-content'>" +
26
+                    "<h2>" + ( data.name || data.fullname ) + "</h2>" +
27
+                    "<a href='" + ( data.statusnet_profile_url || data.url ) + "'>" + at + ( data.screen_name || data.fullname ) +
28
+                      "<img src='" + ( data.profile_image_url || data.stream_logo ) + "' />" +
29
+                    "</a>" +
30
+                    "<p class='hc-stats'>" + notices +
31
+                      "<span class='hc-subs'>" +
32
+                        "<span class='hc-count'>" + ( data.friends_count || data.member_count ) + "</span> " + subs +
33
+                      "</span>" +
34
+                    "</p>" +
35
+                    "<h3>" + desc + "</h3>" +
36
+                    "<span class='hc-bio'>" + ( data.description || "" ) + "</span>" + latest +
37
+                  "</div>" +
38
+                  "<div class='hc-actions'><a href='#' class='hc-follow'>subscribe</a>" +
39
+                  "<div class='hc-follow-form'>" +
40
+                    "<form>" +
41
+                      "<fieldset>" +
42
+                        "<label for='hc-profile-" + uid + "'>Your Accound ID</label>" +
43
+                        "<input id='hc-profile-" + uid + "' type='text' placeholder='e.g. user@identi.ca' />" +
44
+                        "<input type='hidden' name='profile' value='" + ( data.statusnet_profile_url || data.url ) + "' />" +
45
+                        "<button type='submit'>Subscribe</button>" +
46
+                      "</fieldset>" +
47
+                    "</form>" +
48
+                  "</div>" +
49
+                "</div>" +
50
+              "</div>";
53 51
 
54 52
         return html;
55 53
     }
56 54
 
57
-    function buildCard(data, $link) {
58
-        $link.on('mouseenter', function () {
59
-            setTimeout(function () {
60
-                $('.sn-hovercard').hide(); // Only show one hovercard at a time
61
-                $link.data('sn-hovercard').show();
62
-            }, 400);
63
-        });
55
+    function buildCard( data, $link ) {
56
+        $link.on( "mouseenter", function() {
57
+            setTimeout( function() {
58
+                $( ".sn-hovercard" ).hide(); /* Only show one hovercard at a time */
59
+                $link.data( "sn-hovercard" ).show();
60
+            }, 400 );
61
+        } );
64 62
 
65 63
         var offset = $link.offset(),
66
-            group  = ($link.text().charAt(0) === '!'),
67
-            html   = buildHTML(data, group);
68
-
69
-        html = $(html).appendTo('body')
70
-            .on('mouseleave', function () { setTimeout(function () { html.hide(); }, 400); })
71
-            .css({top: offset.top, left: offset.left});
72
-
73
-        html.find('.hc-follow').on('click', function (e) {
64
+            group  = ( $link.text().charAt( 0 ) === "!" ),
65
+            html   = buildHTML( data, group );
66
+
67
+        html = $( html ).appendTo( "body" )
68
+            .on( "mouseleave", function() {
69
+                setTimeout( function() {
70
+                    html.hide();
71
+                }, 400 );
72
+            } )
73
+            .css( { top: offset.top, left: offset.left } );
74
+
75
+        html.find( ".hc-follow" ).on( "click", function( e ) {
74 76
             e.preventDefault();
75
-            $(this).parent().find('.hc-follow-form').slideToggle();
76
-        });
77
+            $( this ).parent().find( ".hc-follow-form" ).slideToggle();
78
+        } );
77 79
 
78
-        html.find('form').on('submit', function (e) {
80
+        html.find( "form" ).on( "submit", function( e ) {
79 81
             e.preventDefault();
80 82
 
81
-            var $form   = $(this),
82
-                $input  = $form.find('input[type=text]'),
83
-                profile = $input.val().split('@');
83
+            var $form   = $( this ),
84
+                $input  = $form.find( "input[type=text]" ),
85
+                profile = $input.val().split( "@" );
84 86
 
85
-            if (profile.length !== 2) {
86
-                // TODO: show error msg
87
-                $input.css('border', '1px solid #F00');
87
+            if ( profile.length !== 2 ) {
88
+                /* TODO: show error msg */
89
+                $input.css( "border", "1px solid #f00" );
88 90
             } else {
89
-                profile = profile[1];
90
-                if (!group) {
91
-                    $form.attr('action', 'http://' + profile + '/main/ostatussub');
91
+                profile = profile[ 1 ];
92
+                if ( !group ) {
93
+                    $form.attr( "action", "http://" + profile + "/main/ostatussub" );
92 94
                 } else {
93
-                    $form.attr('action', 'http://' + profile + '/main/ostatusgroup');
95
+                    $form.attr( "action", "http://" + profile + "/main/ostatusgroup" );
94 96
                 }
95 97
                 this.submit();
96 98
             }
97
-        });
99
+        } );
98 100
 
99
-        $link.data('sn-hovercard', html); // Could use ARIA instead
100
-        $link.trigger('mouseenter');      // Initial show() after we got the data
101
+        $link.data( "sn-hovercard", html ); /* Could use ARIA instead */
102
+        $link.trigger( "mouseenter" );      /* Initial show() after we got the data */
101 103
     }
102 104
 
103 105
     function buildErrorCard() {
104
-       // TODO
106
+       /* TODO */
105 107
     }
106 108
 
107
-    function getData(e) {
108
-        var $this = $(this),
109
-            id    = $this.text().substr(1),
110
-            group = ($this.text().charAt(0) === '!'),
111
-            patt  = group ? new RegExp('group\/' + id + '$') : new RegExp(id + '$'),
112
-            url   = $this.attr('href').replace(patt, ''),
113
-            api   = group ? '/api/statusnet/groups/show.json?id=' + id : '/api/users/show.json?id=' + id;
109
+    function getData() {
110
+        var $this = $( this ),
111
+            id    = $this.text().substr( 1 ),
112
+            group = ( $this.text().charAt( 0 ) === "!" ),
113
+            patt  = group ? new RegExp( "group\/" + id + "$" ) : new RegExp( id + "$" ),
114
+            url   = $this.attr( "href" ).replace( patt, "" ),
115
+            api   = group ? "/api/statusnet/groups/show.json?id=" + id : "/api/users/show.json?id=" + id;
114 116
 
115 117
         // NOTE:  Doesn't support api at non-default locations
116 118
         // FIXME: This (probably) fails if a single-user instance is installed in a subdir that matches the user's nickname
117
-        $.getJSON(url + api) // Fancy URL
118
-            .success(function (data) { buildCard(data, $this); })
119
-            .error(function () { // Try non-fancy URL
120
-                $.getJSON(url + '/index.php' + api)
121
-                    .success(function (data) { buildCard(data, $this); })
122
-                    .error(function () { buildErrorCard(); });
123
-            });
119
+        $.getJSON( url + api ) /* Fancy URL */
120
+            .success( function( data ) {
121
+                buildCard( data, $this );
122
+            } )
123
+            .error( function() { /* Try non-fancy URL */
124
+                $.getJSON( url + "/index.php" + api )
125
+                    .success( function( data ) {
126
+                        buildCard( data, $this );
127
+                    } )
128
+                    .error( function() {
129
+                        buildErrorCard();
130
+                    } );
131
+            } );
124 132
     }
125 133
 
126 134
     // public
127 135
     var methods = {
128
-        init: function (options) {
129
-            return this.each(function () {
130
-                var $this = $(this),
136
+        init: function() {
137
+            return this.each( function() {
138
+                var $this = $( this ),
131 139
                     $collection;
132 140
 
133
-                if ($this.is('a[href]')) {
141
+                if ( $this.is( "a[href]" ) ) {
134 142
                     $collection = $this;
135 143
                 } else {
136
-                    $collection = $this.find('a[href]');
144
+                    $collection = $this.find( "a[href]" );
137 145
                 }
138 146
 
139
-                if ($collection) {
140
-                    $collection.each(function () {
141
-                        if ($(this).text().match(/@\w+/)) {
142
-                            $(this).one('mouseenter', getData);
143
-                        } else if ($(this).text().match(/!\w+/)) {
144
-                            $(this).one('mouseenter', getData);
147
+                if ( $collection ) {
148
+                    $collection.each( function() {
149
+                        if ( $( this ).text().match( /@\w+/ ) ) {
150
+                            $( this ).one( "mouseenter", getData );
151
+                        } else if ( $( this ).text().match( /!\w+/ ) ) {
152
+                            $( this ).one( "mouseenter", getData );
145 153
                         }
146
-                    });
154
+                    } );
147 155
                 }
148
-            });
156
+            } );
149 157
         }
150 158
     };
151 159
 
152 160
     // Method calling logic
153
-    $.fn.SnHoverCard = function (method) {
161
+    $.fn.SnHoverCard = function( method ) {
154 162
         var elm;
155 163
 
156
-        if (methods[method]) {
157
-            elm = methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
158
-        } else if (typeof method === 'object' || !method) {
159
-            elm = methods.init.apply(this, arguments);
164
+        if ( methods[ method ] ) {
165
+            elm = methods[method].apply( this, Array.prototype.slice.call( arguments, 1 ) );
166
+        } else if ( typeof method === "object" || !method ) {
167
+            elm = methods.init.apply( this, arguments );
160 168
         } else {
161
-            $.error('Method ' +  method + ' does not exist on jQuery.SnHoverCard');
169
+            $.error( "Method " +  method + " does not exist on jQuery.SnHoverCard" );
162 170
         }
163 171
 
164 172
         return elm;
165 173
     };
166 174
 
167
-}(jQuery));
175
+}( jQuery ) );

Loading…
Cancel
Save