aboutsummaryrefslogtreecommitdiffstats
path: root/app/assets/javascripts/bootstrap-tab.js
blob: 26c9ece753fb18c587ad283986f48de286410edd (plain)
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
/* ========================================================
 * bootstrap-tab.js v2.0.1
 * http://twitter.github.com/bootstrap/javascript.html#tabs
 * ========================================================
 * Copyright 2012 Twitter, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ======================================================== */


!function( $ ){

  "use strict"

 /* TAB CLASS DEFINITION
  * ==================== */

  var Tab = function ( element ) {
    this.element = $(element)
  }

  Tab.prototype = {

    constructor: Tab

  , show: function () {
      var $this = this.element
        , $ul = $this.closest('ul:not(.dropdown-menu)')
        , selector = $this.attr('data-target')
        , previous
        , $target

      if (!selector) {
        selector = $this.attr('href')
        selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
      }

      if ( $this.parent('li').hasClass('active') ) return

      previous = $ul.find('.active a').last()[0]

      $this.trigger({
        type: 'show'
      , relatedTarget: previous
      })

      $target = $(selector)

      this.activate($this.parent('li'), $ul)
      this.activate($target, $target.parent(), function () {
        $this.trigger({
          type: 'shown'
        , relatedTarget: previous
        })
      })
    }

  , activate: function ( element, container, callback) {
      var $active = container.find('> .active')
        , transition = callback
            && $.support.transition
            && $active.hasClass('fade')

      function next() {
        $active
          .removeClass('active')
          .find('> .dropdown-menu > .active')
          .removeClass('active')

        element.addClass('active')

        if (transition) {
          element[0].offsetWidth // reflow for transition
          element.addClass('in')
        } else {
          element.removeClass('fade')
        }

        if ( element.parent('.dropdown-menu') ) {
          element.closest('li.dropdown').addClass('active')
        }

        callback && callback()
      }

      transition ?
        $active.one($.support.transition.end, next) :
        next()

      $active.removeClass('in')
    }
  }


 /* TAB PLUGIN DEFINITION
  * ===================== */

  $.fn.tab = function ( option ) {
    return this.each(function () {
      var $this = $(this)
        , data = $this.data('tab')
      if (!data) $this.data('tab', (data = new Tab(this)))
      if (typeof option == 'string') data[option]()
    })
  }

  $.fn.tab.Constructor = Tab


 /* TAB DATA-API
  * ============ */

  $(function () {
    $('body').on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
      e.preventDefault()
      $(this).tab('show')
    })
  })

}( window.jQuery );
ss="w"> *message, int len, int away ) { struct msn_switchboard *sb; struct msn_data *md = gc->proto_data; if( ( sb = msn_sb_by_handle( gc, who ) ) ) { return( msn_sb_sendmessage( sb, message ) ); } else { struct msn_message *m; char buf[1024]; /* Create a message. We have to arrange a usable switchboard, and send the message later. */ m = g_new0( struct msn_message, 1 ); m->who = g_strdup( who ); m->text = g_strdup( message ); /* FIXME: *CHECK* the reliability of using spare sb's! */ if( ( sb = msn_sb_spare( gc ) ) ) { debug( "Trying to use a spare switchboard to message %s", who ); sb->who = g_strdup( who ); g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who ); if( msn_sb_write( sb, buf, strlen( buf ) ) ) { /* He/She should join the switchboard soon, let's queue the message. */ sb->msgq = g_slist_append( sb->msgq, m ); return( 1 ); } } debug( "Creating a new switchboard to message %s", who ); /* If we reach this line, there was no spare switchboard, so let's make one. */ g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId ); if( !msn_write( gc, buf, strlen( buf ) ) ) { g_free( m->who ); g_free( m->text ); g_free( m ); return( 0 ); } /* And queue the message to md. We'll pick it up when the switchboard comes up. */ md->msgq = g_slist_append( md->msgq, m ); /* FIXME: If the switchboard creation fails, the message will not be sent. */ return( 1 ); } return( 0 ); } static GList *msn_away_states( struct gaim_connection *gc ) { GList *l = NULL; int i; for( i = 0; msn_away_state_list[i].number > -1; i ++ ) l = g_list_append( l, (void*) msn_away_state_list[i].name ); return( l ); } static char *msn_get_status_string( struct gaim_connection *gc, int number ) { const struct msn_away_state *st = msn_away_state_by_number( number ); if( st ) return( (char*) st->name ); else return( "" ); } static void msn_set_away( struct gaim_connection *gc, char *state, char *message ) { char buf[1024]; struct msn_data *md = gc->proto_data; const struct msn_away_state *st; if( strcmp( state, GAIM_AWAY_CUSTOM ) == 0 ) st = msn_away_state_by_name( "Away" ); else st = msn_away_state_by_name( state ); if( !st ) st = msn_away_state_list; md->away_state = st; g_snprintf( buf, sizeof( buf ), "CHG %d %s\r\n", ++md->trId, st->code ); msn_write( gc, buf, strlen( buf ) ); } static void msn_set_info( struct gaim_connection *gc, char *info ) { msn_set_display_name( set_find( &gc->acc->set, "display_name" ), info ); } static void msn_get_info(struct gaim_connection *gc, char *who) { /* Just make an URL and let the user fetch the info */ serv_got_crap( gc, "%s\n%s: %s%s", _("User Info"), _("For now, fetch yourself"), PROFILE_URL, who ); } static void msn_add_buddy( struct gaim_connection *gc, char *who ) { msn_buddy_list_add( gc, "FL", who, who ); } static void msn_remove_buddy( struct gaim_connection *gc, char *who, char *group ) { msn_buddy_list_remove( gc, "FL", who ); } static int msn_chat_send( struct gaim_connection *gc, int id, char *message ) { struct msn_switchboard *sb = msn_sb_by_id( gc, id ); if( sb ) return( msn_sb_sendmessage( sb, message ) ); else return( 0 ); } static void msn_chat_invite( struct gaim_connection *gc, int id, char *msg, char *who ) { struct msn_switchboard *sb = msn_sb_by_id( gc, id ); char buf[1024]; if( sb ) { g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who ); msn_sb_write( sb, buf, strlen( buf ) ); } } static void msn_chat_leave( struct gaim_connection *gc, int id ) { struct msn_switchboard *sb = msn_sb_by_id( gc, id ); if( sb ) msn_sb_write( sb, "OUT\r\n", 5 ); } static int msn_chat_open( struct gaim_connection *gc, char *who ) { struct msn_switchboard *sb; struct msn_data *md = gc->proto_data; char buf[1024]; if( ( sb = msn_sb_by_handle( gc, who ) ) ) { debug( "Converting existing switchboard to %s to a groupchat", who ); msn_sb_to_chat( sb ); return( 1 ); } else { struct msn_message *m; if( ( sb = msn_sb_spare( gc ) ) ) { debug( "Trying to reuse an existing switchboard as a groupchat with %s", who ); g_snprintf( buf, sizeof( buf ), "CAL %d %s\r\n", ++sb->trId, who ); if( msn_sb_write( sb, buf, strlen( buf ) ) ) { msn_sb_to_chat( sb ); return( 1 ); } } /* If the stuff above failed for some reason: */ debug( "Creating a new switchboard to groupchat with %s", who ); /* Request a new switchboard. */ g_snprintf( buf, sizeof( buf ), "XFR %d SB\r\n", ++md->trId ); if( !msn_write( gc, buf, strlen( buf ) ) ) return( 0 ); /* Create a magic message. This is quite hackish, but who cares? :-P */ m = g_new0( struct msn_message, 1 ); m->who = g_strdup( who ); m->text = g_strdup( GROUPCHAT_SWITCHBOARD_MESSAGE ); /* Queue the magic message and cross your fingers. */ md->msgq = g_slist_append( md->msgq, m ); return( 1 ); } return( 0 ); } static void msn_keepalive( struct gaim_connection *gc ) { msn_write( gc, "PNG\r\n", strlen( "PNG\r\n" ) ); } static void msn_add_permit( struct gaim_connection *gc, char *who ) { msn_buddy_list_add( gc, "AL", who, who ); } static void msn_rem_permit( struct gaim_connection *gc, char *who ) { msn_buddy_list_remove( gc, "AL", who ); } static void msn_add_deny( struct gaim_connection *gc, char *who ) { struct msn_switchboard *sb; msn_buddy_list_add( gc, "BL", who, who ); /* If there's still a conversation with this person, close it. */ if( ( sb = msn_sb_by_handle( gc, who ) ) ) { msn_sb_destroy( sb ); } } static void msn_rem_deny( struct gaim_connection *gc, char *who ) { msn_buddy_list_remove( gc, "BL", who ); } static int msn_send_typing( struct gaim_connection *gc, char *who, int typing ) { if( typing ) return( msn_send_im( gc, who, TYPING_NOTIFICATION_MESSAGE, strlen( TYPING_NOTIFICATION_MESSAGE ), 0 ) ); else return( 1 ); } static char *msn_set_display_name( set_t *set, char *value ) { account_t *acc = set->data; struct gaim_connection *gc = acc->gc; struct msn_data *md; char buf[1024], *fn; /* Double-check. */ if( gc == NULL ) return NULL; md = gc->proto_data; if( strlen( value ) > 129 ) { serv_got_crap( gc, "Maximum name length exceeded" ); return NULL; } fn = msn_http_encode( value ); g_snprintf( buf, sizeof( buf ), "REA %d %s %s\r\n", ++md->trId, gc->username, fn ); msn_write( gc, buf, strlen( buf ) ); g_free( fn ); /* Returning NULL would be better, because the server still has to confirm the name change. However, it looks a bit confusing to the user. */ return value; } void msn_init() { struct prpl *ret = g_new0(struct prpl, 1); ret->name = "msn"; ret->login = msn_login; ret->acc_init = msn_acc_init; ret->close = msn_close; ret->send_im = msn_send_im; ret->away_states = msn_away_states; ret->get_status_string = msn_get_status_string; ret->set_away = msn_set_away; ret->set_info = msn_set_info; ret->get_info = msn_get_info; ret->add_buddy = msn_add_buddy; ret->remove_buddy = msn_remove_buddy; ret->chat_send = msn_chat_send; ret->chat_invite = msn_chat_invite; ret->chat_leave = msn_chat_leave; ret->chat_open = msn_chat_open; ret->keepalive = msn_keepalive; ret->add_permit = msn_add_permit; ret->rem_permit = msn_rem_permit; ret->add_deny = msn_add_deny; ret->rem_deny = msn_rem_deny; ret->send_typing = msn_send_typing; ret->handle_cmp = g_strcasecmp; register_protocol(ret); }