PageSourceSearch

https://the016.com/application/modules/Activity/externals/scripts/core.js?c=84

js the016.com collected 2026-10-03 22:11:17 UTC 18,702 bytes, 668 lines download raw bytes

1
2/* $Id: core.js 10182 2014-04-29 23:52:40Z andres $ */
3
4
5
6(function() { // START NAMESPACE
7var $ = 'id' in document ? document.id : window.$;
8
9
10
11en4.activity = {
12  editComposers : new Hash(),
13  load : function(next_id, subject_guid){
14    if( en4.core.request.isRequestActive() ) return;
15
16    $('feed_viewmore').style.display = 'none';
17    $('feed_loading').style.display = '';
18
19    en4.core.request.send(new Request.HTML({
20      url : en4.core.baseUrl + 'activity/widget/feed',
21      data : {
22        //format : 'json',
23        'maxid' : next_id,
24        'feedOnly' : true,
25        'nolayout' : true,
26        'subject' : subject_guid
27      }
28      /*
29      onSuccess : function(){
30        $('feed_viewmore').style.display = '';
31        $('feed_loading').style.display = 'none';
32      }*/
33    }), {
34      'element' : $('activity-feed'),
35      'updateHtmlMode' : 'append'
36    });
37  },
38
39  like : function(action_id, comment_id) {
40    en4.core.request.send(new Request.JSON({
41      url : en4.core.baseUrl + 'activity/index/like',
42      data : {
43        format : 'json',
44        action_id : action_id,
45        comment_id : comment_id,
46        subject : en4.core.subject.guid
47      }
48    }), {
49      //'element' : $('activity-item-'+action_id),
50      //'updateHtmlMode': 'comments'
51      'element' : $('comment-likes-activity-item-'+action_id),
52      'updateHtmlMode': 'comments2'
53    });
54  },
55
56  unlike : function(action_id, comment_id) {
57    en4.core.request.send(new Request.JSON({
58      url : en4.core.baseUrl + 'activity/index/unlike',
59      data : {
60        format : 'json',
61        action_id : action_id,
62        comment_id : comment_id,
63        subject : en4.core.subject.guid
64      }
65    }), {
66      //'element' : $('activity-item-'+action_id),
67      //'updateHtmlMode': 'comments'
68      'element' : $('comment-likes-activity-item-'+action_id),
69      'updateHtmlMode': 'comments2'
70    });
71  },
72
73  comment : function(formData) {
74    if( formData.body.trim() == '' ) {
75      return;
76    }
77
78    en4.core.request.send(new Request.JSON({
79      format: 'json',
80      url : en4.core.baseUrl + 'activity/index/comment',
81      data : formData,
82    }), {
83      'element' : $('comment-likes-activity-item-' + formData.action_id),
84      'updateHtmlMode': 'comments2'
85    });
86  },
87
88  viewComments : function(action_id){
89    en4.core.request.send(new Request.JSON({
90      url : en4.core.baseUrl + 'activity/index/viewComment',
91      data : {
92        format : 'json',
93        action_id : action_id,
94        nolist : true
95      }
96    }), {
97      'element' : $('activity-item-'+action_id),
98      'updateHtmlMode': 'comments'
99      //'element' : $('comment-likes-activity-item-'+action_id),
100    });
101  },
102
103  viewLikes : function(action_id){
104    en4.core.request.send(new Request.JSON({
105      url : en4.core.baseUrl + 'activity/index/viewLike',
106      data : {
107        format : 'json',
108        action_id : action_id,
109        nolist : true
110      }
111    }), {
112      'element' : $('activity-item-'+action_id),
113      'updateHtmlMode': 'comments'
114    });
115  },
116
117  hideNotifications : function(reset_text) {
118    en4.core.request.send(new Request.JSON({
119      'url' : en4.core.baseUrl + 'activity/notifications/hide'
120    }));
121    $('updates_toggle').set('html', reset_text).removeClass('new_updates');
122    $('update_count').removeClass('minimenu_update_count_bubble_active');
123    /*
124    var notify_link = $('core_menu_mini_menu_updates_count').clone();
125    $('new_notification').destroy();
126    notify_link.setAttribute('id', 'core_menu_mini_menu_updates_count');
127    notify_link.innerHTML = "0 updates";
128    notify_link.inject($('core_menu_mini_menu_updates'));
129    $('core_menu_mini_menu_updates').setAttribute('id', '');
130    */
131    if($('notifications_main')){
132      var notification_children = $('notifications_main').getChildren('li');
133      notification_children.each(function(el){
134          el.setAttribute('class', '');
135      });
136    }
137
138    if($('notifications_menu')){
139      var notification_children = $('notifications_menu').getChildren('li');
140      notification_children.each(function(el){
141          el.setAttribute('class', '');
142      });
143    }
144    //$('core_menu_mini_menu_updates').setStyle('display', 'none');
145  },
146
147  updateNotifications : function() {
148    if( en4.core.request.isRequestActive() ) return;
149    en4.core.request.send(new Request.JSON({
150      url : en4.core.baseUrl + 'activity/notifications/update',
151      data : {
152        format : 'json'
153      },
154      onSuccess : this.showNotifications.bind(this)
155    }));
156  },
157
158  showNotifications : function(responseJSON){
159    if (responseJSON.notificationCount>0){
160      $('updates_toggle').set('html', responseJSON.text).addClass('new_updates');
161    }
162  },
163
164  markRead : function (action_id){
165    en4.core.request.send(new Request.JSON({
166      url : en4.core.baseUrl + 'activity/notifications/test',
167      data : {
168        format     : 'json',
169        'actionid' : action_id
170      }
171    }));
172  },
173
174  cometNotify : function(responseObject){
175    $('core_menu_mini_menu_updates').style.display = '';
176    $('core_menu_mini_menu_updates_count').innerHTML = responseObject.text;
177  },
178
179  post : function (composeInstance, event) {
180    event.stop();
181    var formData = composeInstance.getForm().toQueryString().parseQueryString();
182    en4.core.request.send(new Request.JSON({
183      url: composeInstance.getForm().get('action'),
184      data: formData,
185      format: 'json',
186      onComplete: function (resp) {
187        if(!resp.status) {
188          $('fail_msg').style.display = "block";
189          return;
190        }
191
192        if (!$('activity-feed')) {
193          new Element('ul', {
194            'id': 'activity-feed',
195            'class': 'feed'
196          }).inject(document.getElement('.layout_activity_feed').getElementById('fail_msg'), 'after');
197          $('no-feed-tip').destroy();
198        }
199
200        if (window._activityUpdateHandler !== undefined) {
201          window._activityUpdateHandler.options.next_id = resp.action_id;
202          window._activityUpdateHandler.getFeedUpdate(window._activityUpdateHandler.options.next_id, true);
203        } else {
204          new ActivityUpdateHandler({
205            'baseUrl' : en4.core.baseUrl,
206            'basePath' : en4.core.basePath,
207            'identity' : 4,
208            'subject_guid' : en4.core.subject.guid
209          }).getFeedUpdate(resp.action_id, true);
210        }
211
212        $('token').value = resp.formToken;
213        // Remove the params values after submit
214        composeInstance.plugins.each(function(plugin) {
215          plugin.reset();
216        });
217        composeInstance.reset();
218      }
219    }), {
220      force: true,
221    });
222  },
223  bindEditFeed: function(action_id, composerOptions) {
224    if( $('activity-item-' + action_id).getElement('.compose-container') ) {
225      this.bindEditLink(action_id);
226      return;
227    }
228    var editComposeInstance = new Composer('feed-edit-body-' + action_id, {
229      lang: composerOptions.lang,
230      hashtagEnabled : composerOptions.hashtagEnabled,
231      hideSubmitOnBlur: false,
232      allowEmptyWithoutAttachment: composerOptions.allowEmptyWithoutAttachment,
233      submitCallBack: function(composeInstance, event) {
234        event.stop();
235        var params = composeInstance.getForm().toQueryString().parseQueryString();
236        en4.core.request.send(new Request.JSON({
237          url: editComposeInstance.getForm().get('action'),
238          data: $merge({
239            format: 'json',
240            subject: en4.core.subject.guid
241          },params),
242          method: 'POST',
243          onRequest: function() {
244            editComposeInstance.getForm().getElementById('fieldset-buttons').setStyle('display', 'none');
245            en4.core.loader.inject(editComposeInstance.getForm().getElementById('buttons-wrapper'));
246          },
247          onSuccess: function() {
248            $('activity-item-' + action_id).getElement('.compose-container').destroy();
249          }
250        }), {
251          'force': true,
252          'element': $('activity-item-' + action_id),
253          'updateHtmlMode': 'comments'
254        });
255      }
256    });
257    this.editComposers[action_id] = editComposeInstance;
258    if( editComposeInstance._supportsContentEditable() ) {
259      editComposeInstance.setContent(editComposeInstance.elements.body.get('html').replace(/(\r\n?|\n)/ig, "<br>"));
260    }
261    document.store('editComposeInstanceActivity' + action_id, edit
261ComposeInstance);
262
263    this.bindEditLink(action_id);
264    $('activity-item-' + action_id).getElement('.feed-edit-content-cancel').addEvent('click', function(event) {
265      var el = $(event.target);
266      var parent = el.getParent('.activity-item');
267      parent.getElement('.feed_item_body_edit_content').setStyle('display', 'none');
268      parent.getElement('.feed_item_body_content').setStyle('display', 'block');
269    });
270  },
271  bindEditLink : function (action_id) {
272    if (!$('activity-item-' + action_id).getElement('.feed_item_option_edit')) {
273      return;
274    }
275    var self = this;
276    $('activity-item-' + action_id).getElement('.feed_item_option_edit').addEvent('click', function(event) {
277      var el = $(event.target);
278      var parent = el.getParent('.activity-item');
279      parent.getElement('.feed_item_body_content').setStyle('display', 'none');
280      parent.getElement('.feed_item_body_edit_content').setStyle('display', 'block');
281      self.editComposers[action_id].focus();
282      self.editComposers[action_id].placeCaretAtEnd();
283    });
284  }
285};
286
287NotificationUpdateHandler = new Class({
288
289  Implements : [Events, Options],
290  options : {
291      debug : false,
292      baseUrl : '/',
293      identity : false,
294      delay : 5000,
295      minDelay : 5000,
296      maxDelay : 600000,
297      delayFactor : 1.5,
298      admin : false,
299      idleTimeout : 600000,
300      last_id : 0,
301      subject_guid : null
302    },
303
304  state : true,
305
306  activestate : 1,
307
308  fresh : true,
309
310  lastEventTime : false,
311
312  title: document.title,
313
314  initialize : function(options) {
315    this.setOptions(options);
316    this.options.minDelay = this.options.delay;
317  },
318
319  start : function() {
320    this.state = true;
321
322    // Do idle checking
323    this.idleWatcher = new IdleWatcher(this, {timeout : this.options.idleTimeout});
324    this.idleWatcher.register();
325    this.addEvents({
326      'onStateActive' : function() {
327        this.activestate = 1;
328        this.state= true;
329      }.bind(this),
330      'onStateIdle' : function() {
331        this.activestate = 0;
332        this.state = false;
333      }.bind(this)
334    });
335
336    this.loop();
337  },
338
339  stop : function() {
340    this.state = false;
341  },
342
343  updateNotifications : function() {
344    if( en4.core.request.isRequestActive() ) return;
345    en4.core.request.send(new Request.JSON({
346      url : en4.core.baseUrl + 'activity/notifications/update',
347      data : {
348        format : 'json'
349      },
350      onSuccess : this.showNotifications.bind(this)
351    }));
352  },
353
354  showNotifications : function(responseJSON){
355    if (responseJSON.notificationCount>0){
356      this.options.delay = this.options.minDelay;
357        if (!$('updates_toggle')) {
358            return;
359        }
360      $('updates_toggle').set('html', responseJSON.text).addClass('new_updates');
361      $('update_count').set('html', responseJSON.notificationCount).addClass('minimenu_update_count_bubble_active');
362    } else {
363      this.options.delay = Math.min(this.options.maxDelay, this.options.delayFactor * this.options.delay);
364    }
365  },
366
367  loop : function() {
368    if( !this.state) {
369      this.loop.delay(this.options.delay, this);
370      return;
371    }
372
373    try {
374      this.updateNotifications().addEvent('complete', function() {
375        this.loop.delay(this.options.delay, this);
376      }.bind(this));
377    } catch( e ) {
378      this.loop.delay(this.options.delay, this);
379      this._log(e);
380    }
381  },
382
383  // Utility
384
385  _log : function(object) {
386    if( !this.options.debug ) {
387      return;
388    }
389
390    // Firefox is dumb and causes problems sometimes with console
391    try {
392      if( typeof(console) && $type(console) ) {
393        console.log(object);
394      }
395    } catch( e ) {
396      // Silence
397    }
398  }
399});
400
401//(function(){
402
403  en4.activity.compose = {
404
405    composers : {},
406
407    register : function(object){
408      name = object.getName();
409      this.composers[name] = object;
410    },
411
412    deactivate : function(){
413      for( var x in this.composers ){
414        this.composers[x].deactivate();
415      }
416      return this;
417    }
418
419  };
420
421
422  en4.activity.compose.icompose = new Class({
423
424    Implements: [Events, Options],
425
426    name : false,
427
428    element : false,
429
430    options : {},
431
432    initialize : function(element, options){
433      this.element = $(element);
434      this.setOptions(options);
435    },
436
437    getName : function(){
438      return this.name;
439    },
440
441    activate : function(){
442      en4.activity.compose.deactivate();
443    },
444
445    deactivate : function(){
446
447    }
448  });
449
450//})();
451
452ActivityUpdateHandler = new Class({
453
454  Implements : [Events, Options],
455  options : {
456      debug : true,
457      baseUrl : '/',
458      identity : false,
459      delay : 5000,
460      admin : false,
461      idleTimeout : 600000,
462      last_id : 0,
463      next_id : null,
464      subject_guid : null,
465      showImmediately : false
466    },
467
468  state : true,
469
470  activestate : 1,
471
472  fresh : true,
473
474  lastEventTime : false,
475
476  title: document.title,
477
478  //loopId : false,
479
480  initialize : function(options) {
481    this.setOptions(options);
482  },
483
484  start : function() {
485    this.state = true;
486
487    // Do idle checking
488    this.idleWatcher = new IdleWatcher(this, {timeout : this.options.idleTimeout});
489    this.idleWatcher.register();
490    this.addEvents({
491      'onStateActive' : function() {
492        this._log('activity loop onStateActive');
493        this.activestate = 1;
494        this.state = true;
495      }.bind(this),
496      'onStateIdle' : function() {
497        this._log('activity loop onStateIdle');
498        this.activestate = 0;
499        this.state = false;
500      }.bind(this)
501    });
502    this.loop();
503    //this.loopId = this.loop.periodical(this.options.delay, this);
504  },
505
506  stop : function() {
507    this.state = false;
508  },
509
510  checkFeedUpdate : function(action_id, subject_guid){
511    if( en4.core.request.isRequestActive() ) return;
512
513    function getAllElementsWithAttribute(attribute) {
514      var matchingElements = [];
515      var values = [];
516      var allElements = document.getElementsByTagName('*');
517      for (var i = 0; i < allElements.length; i++) {
518        if (allElements[i].getAttribute(attribute)) {
519          // Element exists with attribute. Add to array.
520          matchingElements.push(allElements[i]);
521          values.push(allElements[i].getAttribute(attribute));
522          }
523        }
524      return values;
525    }
526    var list = getAllElementsWithAttribute('data-activity-feed-item');
527    this.options.last_id = Math.max.apply( Math, list );
528    min_id = parseInt(this.options.last_id) + 1;
529
530    var req = new Request.HTML({
531      url : en4.core.baseUrl + 'widget/index/name/activity.feed',
532      data : {
533        'format' : 'html',
534        'minid' : min_id,
535        'feedOnly' : true,
536        'nolayout' : true,
537        'subject' : this.options.subject_guid,
538        'getUpdate' : true
539      }
540    });
541    en4.core.request.send(req, {
542      'element' : $('activity-feed'),
543      'updateHtmlMode' : 'prepend'
544      }
545    );
546
547
548
549    req.addEvent('complete', function() {
550      (function() {
551        if( this.options.showImmediately && $('feed-update').getChildren().length > 0 ) {
552          $('feed-update').setStyle('display', 'none');
553          $('feed-update').empty();
554          this.getFeedUpdate(this.options.next_id);
555          }
556        }).delay(50, this);
557    }.bind(this));
558
559
560
561   // Start LOCAL STORAGE STUFF
562   if(localStorage) {
563     var pageTitle = document.title;
564     //@TODO Refill Locally Stored Activity Feed
565
566     // For each activity-item, get the item ID number Data attribute and add it to an array
567     var feed  = document.getElementById('activity-feed');
568     // For every <li> in Feed, get the Feed Item Attribute and add it to an array
569     var items = feed.getElementsByTagName("li");
570     var itemObject = { };
571     // Loop through each item in array to get the InnerHTML of each Activity Feed Item
572     var c = 0;
573     for (var i = 0; i < items.length; ++i) {
574       if(items[i].getAttribute('data-activity-feed-item') != null){
575         var itemId = items[i].getAttribute('data-activity-feed-item');
576         itemObject[c] = {id: itemId, content : document.getElementById('activity-item-'+itemId).innerHTML };
577         c++;
578         }
579       }
580     // Serialize itemObject as JSON string
581     var activityFeedJSON = JSON.stringify(itemObject);
582     localStorage.setItem(pageTitle+'-activity-feed-widget', activityFeedJSON);
583   }
584
585
586   // Reconstruct JSON Object, Find Highest ID
587   if(localStorage.getItem(pageTitle+'-activity-feed-widget')) {
588     var storedFeedJSON = localStorage.getItem(pageTitle+'-activity-feed-widget');
589     var storedObj = eval ("(" + storedFeedJSON + ")");
590
591     //alert(storedObj[0].id); // Highest Feed ID
592    // @TODO use this at min_id when fetching new Activity Feed Items
593   }
594   // END LOCAL STORAGE STUFF
595
596
597   return req;
598  },
599
600  getFeedUpdate : function(last_id, force){
601    if( !force && en4.core.request.isRequestActive() ) return;
602    var min_id = parseInt(this.options.last_id) + 1;
603    this.options.last_id = last_id;
604    document.title = this.title;
605    var req = new Request.HTML({
606      url : en4.core.baseUrl + 'widget/index/name/activity.feed',
607      data : {
608        'format' : 'html',
609        'minid' : min_id,
610        'feedOnly' : true,
611        'nolayout' : true,
612        'getUpdate' : true,
613        'subject' : this.options.subject_guid
614      }
615    });
616    en4.core.request.send(req, {
617      'element' : $('activity-feed'),
618      'updateHtmlMode' : 'prepend',
619      force: !!force
620    });
621    return req;
622  },
623
624  loop : function() {
625    this._log('activity update loop start');
626
627    if( !this.state ) {
628      this.loop.delay(this.options.delay, this);
629      return;
630    }
631
632    try {
633      this.checkFeedUpdate().addEvent('complete', function() {
634        try {
635          this._log('activity loop req complete');
636          this.loop.delay(this.options.delay, this);
637        } catch( e ) {
638          this.loop.delay(this.options.delay, this);
639          this._log(e);
640        }
641      }.bind(this));
642    } catch( e ) {
643      this.loop.delay(this.options.delay, this);
644      this._log(e);
645    }
646
647    this._log('activity update loop stop');
648  },
649
650  // Utility
651  _log : function(object) {
652    if( !this.options.debug ) {
653      return;
654    }
655
656    try {
657      if( 'console' in window && typeof(console) && 'log' in console ) {
658        console.log(object);
659      }
660    } catch( e ) {
661      // Silence
662    }
663  }
664});
665
666
667
668})(); // END NAMESPACE

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.