<commit_before>function isOnly(data,key) {
	var count = 0;
	for(i in data) {
		count++;
		if(count>1) return false;
	};
	return (data !== undefined) && (data[key] !== undefined) && (count == 1);
}

window.livedesk.init = function() {
    var self = this;
    var loadJQ = false;
    var giveBack$ = false;
    contentPath = self.contentPath === undefined? '': self.contentPath;
    
    if (typeof jQuery == 'undefined') {
        loadJQ = true;
    } else {
        if(parseFloat($().jquery) < 1.7) {
            loadJQ = true;
            //relinquish control of $ variable
            giveBack$ = true;
        }
    }
    
    if (loadJQ) {
        self.loadScript('//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', function(){
            if (typeof $.gizmo == 'undefined') {
                self.loadScript(contentPath+'gizmo.js', function(){
                    self.preLoad(giveBack$);
                });
            } else {
                self.preLoad(giveBack$);
            }
        })
    } else {
        if (typeof $.gizmo == 'undefined') {			
            self.loadScript(contentPath+'gizmo.js', function(){
                self.preLoad(giveBack$);
            })
        } else {
            self.preLoad(giveBack$);
        }
    }
};
	
window.livedesk.loadScript = function (src, callback) {
		var script = document.createElement("script")
		script.type = "text/javascript";
		if (script.readyState) { //IE
			script.onreadystatechange = function () {
				if (script.readyState == "loaded" || script.readyState == "complete") {
					script.onreadystatechange = null;
					callback();
				}
			};
		} else { //Others
			script.onload = function () {
				callback();
			};
		}
		script.src = src;
		document.getElementsByTagName("head")[0].appendChild(script);
	};
window.livedesk.preLoad = function (giveBack$) {
    if (giveBack$) {
        var jq_17 = $.noConflict(true);
        this.startLoading(jq_17);
    } else {
        this.startLoading(jQuery);
    }
};
window.livedesk.startLoading = function($) {
		var 
		User = $.gizmo.Model.extend({}),
/*		PostType = $.gizmo.Model.extend({}),
		AuthorPerson = $.gizmo.Model.extend({}),
		PostBlog = $.gizmo.Model.extend({}),
		Author = $.gizmo.Model.extend({}),
*/		
		Post = $.gizmo.Model.extend
		({
			defaults:
			{
				Creator: User
			},
			services: {
				'flickr': true,
				'google': true,
				'twitter': true,
				'facebook': true,
				'youtube': true
			},
			/**
			* Get css class based on type
			*
			* @return {string}
			*/
			getClass: function() {
				switch (this.get('Type').Key) {
					case 'wrapup':
						return 'wrapup';
						break;

					case 'quote':
						return 'quotation';
						break;

					case 'advertisement':
						return 'advertisement';
						break;

					default:
						if (this.isService()) {
							return 'service';
						}

						return 'tw';
				}
			},
			/**
			* Test if post is from service
			*
			* @return {bool}
			*/
			isService: function() {
				return this.get('AuthorName') in this.services;
			},

			/**
			* Test if post is quote
			*
			* @return {bool}
			*/
			isQuote: function() {
				return this.getClass() == 'quotation';
			},
			twitter: {
				link: {
					anchor: function(str) 
					{
						return str.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function(m) 
						{
							m = m.link(m);
							m = m.replace('href="','target="_blank" href="');
							return m;
						});
					},
					user: function(str) 
					{
						return str.replace(/[@]+[A-Za-z0-9-_]+/g, function(us) 
						{
							var username = us.replace("@","");
				
							us = us.link("http://twitter.com/"+username);
							us = us.replace('href="','target="_blank" onclick="loadProfile(\''+username+'\');return(false);"  href="');
							return us;
						});
					},
					tag: function(str) 
					{
						return str.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) 
						{
							var tag = t.replace(" #"," %23");
							t = t.link("http://summize.com/search?q="+tag);
							t = t.replace('href="','target="_blank" href="');
							return t;
						});
					},
					all: function(str)
					{
						str = this.anchor(str);
						str = this.user(str);
						str = this.tag(str);
						return str;
					}
				}
			}
		}),
		AutoCollection = $.gizmo.Collection.extend({
			timeInterval: 10000,
			idInterval: 0,
			_latestCId: 0,
                        
			setIdInterval: function(fn){
				this.idInterval = setInterval(fn, this.timeInterval);
				return this;
			},
			getMaximumCid: function(data){
				for(i=0, count=data.list.length; i<count; i++) {
					var CId = parseInt(data.list[i].get('CId'))
					if( !isNaN(CId) && (this._latestCId < CId) )
						this._latestCId = CId;
				}
			},
			auto: function(){                                
				var self = this, requestOptions = {data: {'cId.since': this._latestCId}, headers: {'X-Filter': 'CId'}};
				if(this._latestCId === 0) delete requestOptions.data;
				this.triggerHandler('beforeUpdate');
				$.gizmo.Collection.prototype.sync.call(this,requestOptions).done(function(data){
					self.getMaximumCid(self.parse(data));
				});
				return this;
			},
			pause: function(){
				var self = this;
				clearInterval(self.idInterval);
				return this;
			},
			sync: function(){
				var self = this;
				this.auto().pause().setIdInterval(function(){self.auto();});
			}
		});
        Posts = AutoCollection.extend({
            model: Post
        }),
       
        Blog = $.gizmo.Model.extend
        ({
            defaults: 
            {
                //Post: Posts,
                PostPublished: Posts
                //PostUnpublished: Posts
            }
        });
        
        var i=0,
        PostItemView = $.gizmo.View.extend
        ({
            init: function()
            {
                        var self = this;
                        self.xfilter = 'DeletedOn, Order, Id, CId, Content, CreatedOn, Type, AuthorName, Author.Source.Name, Author.Source.Id, IsModified, ' +
                                                           'AuthorPerson.EMail, AuthorPerson.FirstName, AuthorPerson.LastName, AuthorPerson.Id';				
                        self.model
                                .on('read', self.render, self)
                                .on('update', function(evt, data){
                                        if(isOnly(data, 'CId')) {
                                                self.model.xfilter(self.xfilter).sync(); //
                                        }
                                        else
                                                self.render(evt, data);
                                })
                                .on('delete', self.remove, self)
                                .xfilter(self.xfilter)
                                .sync();
			},
			remove: function()
			{
				var self = this;
				self.tightkNots();
				self.el.remove();
				return self;			
			},
			/**
			 * Method used to remake connection in the post list ( dubled linked list )
			 *   when the post is removed from that position
			 */
			tightkNots: function()
			{
				if(this.next !== undefined)
					this.next.prev = this.prev;
				if(this.prev !== undefined)
					this.prev.next = this.next;				
			},
                        itemTemplate: function(item, content, time, Avatar)
			{
				// Tw------------------------------------------------------------------------------------------------
				var returned = '';
                                var itemClass = item.getClass();
                                var author = item.get('AuthorName');
                                var annotBefore = '';
                                var annotAfter = '';
                                if (item.data.hasOwnProperty('Meta')) {
                                    var Meta = item.data.Meta;
                                    if ( typeof Meta == 'string') {
                                        Meta = JSON.parse(Meta);
                                    }
                                    if ( Meta.hasOwnProperty('annotation') ) {
                                        if( typeof Meta.annotation === 'string' ) {
                                            annotAfter = '<div class="editable annotation">' + Meta.annotation + '</div>';   
                                        } else {
                                            annotBefore = '<div class="editable annotation">' + Meta.annotation[0] + '</div>';
                                            annotAfter = '<div class="editable annotation">' + Meta.annotation[1] + '</div>';
                                        }
                                    }
                                }
								avatarString = '';
                                if(Avatar.length > 0) {
                                    avatarString = '<figure><img src="' + Avatar + '" ></figure>';
                                }                                
                                switch (itemClass) {
                                    case 'tw':
                                    case 'service':
                                        returned += annotBefore;
										returned += avatarString;
                                        returned +=  '<div class="result-content">';
                                        returned +=     '<div class="result-text">' + content + '</div>';
                                        returned +=     '<p class="attributes"><i class="source-icon"></i> by ' + item.get('AuthorName');
                                        returned +=         '<time>' + time + '</time>';
                                        returned +=     '</p>';
                                        returned += '</div>';
                                        returned += annotAfter;
                                        
                                        break;
                                    case 'quotation':
                                        returned += avatarString;
										returned +=  '<div class="result-content">';
                                        returned +=     '<div class="result-text">' + content + '</div>';
                                        returned +=     '<p class="attributes">by ' + item.get('AuthorName');
                                        returned +=         '<time>' + time + '</time>';
                                        returned +=     '</p>';
                                        returned += '</div>';
                                        break;
                                    case 'wrapup':
                                        returned += '<span class="big-toggle"></span>';
                                        returned += '<h3>' + content + '</h3>';
                                        break;
                                    case 'advertisement':
                                        returned += content;
                                        
                                }
                               return returned;
			},
                        toggleWrap: function(e) {
                            //e.preventDefault();
                            this._toggleWrap($(e).closest('li').first());
                        },
                        _toggleWrap: function(item) {
                            if (item.hasClass('open')) {
                                item.removeClass('open').addClass('closed');
                                item.nextUntil('.wrapup').hide();
                            } else {
                                item.removeClass('closed').addClass('open');<commit_msg>NR-320 : livedesk embed - don't collapse wrapped items if the web page is from a permalink<commit_after>function isOnly(data,key) {
	var count = 0;
	for(i in data) {
		count++;
		if(count>1) return false;
	};
	return (data !== undefined) && (data[key] !== undefined) && (count == 1);
}

window.livedesk.init = function() {
    var self = this;
    var loadJQ = false;
    var giveBack$ = false;
    contentPath = self.contentPath === undefined? '': self.contentPath;
    
    if (typeof jQuery == 'undefined') {
        loadJQ = true;
    } else {
        if(parseFloat($().jquery) < 1.7) {
            loadJQ = true;
            //relinquish control of $ variable
            giveBack$ = true;
        }
    }
    
    if (loadJQ) {
        self.loadScript('//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js', function(){
            if (typeof $.gizmo == 'undefined') {
                self.loadScript(contentPath+'gizmo.js', function(){
                    self.preLoad(giveBack$);
                });
            } else {
                self.preLoad(giveBack$);
            }
        })
    } else {
        if (typeof $.gizmo == 'undefined') {			
            self.loadScript(contentPath+'gizmo.js', function(){
                self.preLoad(giveBack$);
            })
        } else {
            self.preLoad(giveBack$);
        }
    }
};
	
window.livedesk.loadScript = function (src, callback) {
		var script = document.createElement("script")
		script.type = "text/javascript";
		if (script.readyState) { //IE
			script.onreadystatechange = function () {
				if (script.readyState == "loaded" || script.readyState == "complete") {
					script.onreadystatechange = null;
					callback();
				}
			};
		} else { //Others
			script.onload = function () {
				callback();
			};
		}
		script.src = src;
		document.getElementsByTagName("head")[0].appendChild(script);
	};
window.livedesk.preLoad = function (giveBack$) {
    if (giveBack$) {
        var jq_17 = $.noConflict(true);
        this.startLoading(jq_17);
    } else {
        this.startLoading(jQuery);
    }
};
window.livedesk.startLoading = function($) {
		var 
		User = $.gizmo.Model.extend({}),
/*		PostType = $.gizmo.Model.extend({}),
		AuthorPerson = $.gizmo.Model.extend({}),
		PostBlog = $.gizmo.Model.extend({}),
		Author = $.gizmo.Model.extend({}),
*/		
		Post = $.gizmo.Model.extend
		({
			defaults:
			{
				Creator: User
			},
			services: {
				'flickr': true,
				'google': true,
				'twitter': true,
				'facebook': true,
				'youtube': true
			},
			/**
			* Get css class based on type
			*
			* @return {string}
			*/
			getClass: function() {
				switch (this.get('Type').Key) {
					case 'wrapup':
						return 'wrapup';
						break;

					case 'quote':
						return 'quotation';
						break;

					case 'advertisement':
						return 'advertisement';
						break;

					default:
						if (this.isService()) {
							return 'service';
						}

						return 'tw';
				}
			},
			/**
			* Test if post is from service
			*
			* @return {bool}
			*/
			isService: function() {
				return this.get('AuthorName') in this.services;
			},

			/**
			* Test if post is quote
			*
			* @return {bool}
			*/
			isQuote: function() {
				return this.getClass() == 'quotation';
			},
			twitter: {
				link: {
					anchor: function(str) 
					{
						return str.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function(m) 
						{
							m = m.link(m);
							m = m.replace('href="','target="_blank" href="');
							return m;
						});
					},
					user: function(str) 
					{
						return str.replace(/[@]+[A-Za-z0-9-_]+/g, function(us) 
						{
							var username = us.replace("@","");
				
							us = us.link("http://twitter.com/"+username);
							us = us.replace('href="','target="_blank" onclick="loadProfile(\''+username+'\');return(false);"  href="');
							return us;
						});
					},
					tag: function(str) 
					{
						return str.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) 
						{
							var tag = t.replace(" #"," %23");
							t = t.link("http://summize.com/search?q="+tag);
							t = t.replace('href="','target="_blank" href="');
							return t;
						});
					},
					all: function(str)
					{
						str = this.anchor(str);
						str = this.user(str);
						str = this.tag(str);
						return str;
					}
				}
			}
		}),
		AutoCollection = $.gizmo.Collection.extend({
			timeInterval: 10000,
			idInterval: 0,
			_latestCId: 0,
                        
			setIdInterval: function(fn){
				this.idInterval = setInterval(fn, this.timeInterval);
				return this;
			},
			getMaximumCid: function(data){
				for(i=0, count=data.list.length; i<count; i++) {
					var CId = parseInt(data.list[i].get('CId'))
					if( !isNaN(CId) && (this._latestCId < CId) )
						this._latestCId = CId;
				}
			},
			auto: function(){                                
				var self = this, requestOptions = {data: {'cId.since': this._latestCId}, headers: {'X-Filter': 'CId'}};
				if(this._latestCId === 0) delete requestOptions.data;
				this.triggerHandler('beforeUpdate');
				$.gizmo.Collection.prototype.sync.call(this,requestOptions).done(function(data){
					self.getMaximumCid(self.parse(data));
				});
				return this;
			},
			pause: function(){
				var self = this;
				clearInterval(self.idInterval);
				return this;
			},
			sync: function(){
				var self = this;
				this.auto().pause().setIdInterval(function(){self.auto();});
			}
		});
        Posts = AutoCollection.extend({
            model: Post
        }),
       
        Blog = $.gizmo.Model.extend
        ({
            defaults: 
            {
                //Post: Posts,
                PostPublished: Posts
                //PostUnpublished: Posts
            }
        });
        
        var i=0,
        PostItemView = $.gizmo.View.extend
        ({
            init: function()
            {
                        var self = this;
                        self.xfilter = 'DeletedOn, Order, Id, CId, Content, CreatedOn, Type, AuthorName, Author.Source.Name, Author.Source.Id, IsModified, ' +
                                                           'AuthorPerson.EMail, AuthorPerson.FirstName, AuthorPerson.LastName, AuthorPerson.Id';				
                        self.model
                                .on('read', self.render, self)
                                .on('update', function(evt, data){
                                        if(isOnly(data, 'CId')) {
                                                self.model.xfilter(self.xfilter).sync(); //
                                        }
                                        else
                                                self.render(evt, data);
                                })
                                .on('delete', self.remove, self)
                                .xfilter(self.xfilter)
                                .sync();
			},
			remove: function()
			{
				var self = this;
				self.tightkNots();
				self.el.remove();
				return self;			
			},
			/**
			 * Method used to remake connection in the post list ( dubled linked list )
			 *   when the post is removed from that position
			 */
			tightkNots: function()
			{
				if(this.next !== undefined)
					this.next.prev = this.prev;
				if(this.prev !== undefined)
					this.prev.next = this.next;				
			},
                        itemTemplate: function(item, content, time, Avatar)
			{
				// Tw------------------------------------------------------------------------------------------------
				var returned = '';
                                var itemClass = item.getClass();
                                var author = item.get('AuthorName');
                                var annotBefore = '';
                                var annotAfter = '';
                                if (item.data.hasOwnProperty('Meta')) {
                                    var Meta = item.data.Meta;
                                    if ( typeof Meta == 'string') {
                                        Meta = JSON.parse(Meta);
                                    }
                                    if ( Meta.hasOwnProperty('annotation') ) {
                                        if( typeof Meta.annotation === 'string' ) {
                                            annotAfter = '<div class="editable annotation">' + Meta.annotation + '</div>';   
                                        } else {
                                            annotBefore = '<div class="editable annotation">' + Meta.annotation[0] + '</div>';
                                            annotAfter = '<div class="editable annotation">' + Meta.annotation[1] + '</div>';
                                        }
                                    }
                                }
								avatarString = '';
                                if(Avatar.length > 0) {
                                    avatarString = '<figure><img src="' + Avatar + '" ></figure>';
                                }                                
                                switch (itemClass) {
                                    case 'tw':
                                    case 'service':
                                        returned += annotBefore;
										returned += avatarString;
                                        returned +=  '<div class="result-content">';
                                        returned +=     '<div class="result-text">' + content + '</div>';
                                        returned +=     '<p class="attributes"><i class="source-icon"></i> by ' + item.get('AuthorName');
                                        returned +=         '<time>' + time + '</time>';
                                        returned +=     '</p>';
                                        returned += '</div>';
                                        returned += annotAfter;
                                        
                                        break;
                                    case 'quotation':
                                        returned += avatarString;
										returned +=  '<div class="result-content">';
                                        returned +=     '<div class="result-text">' + content + '</div>';
                                        returned +=     '<p class="attributes">by ' + item.get('AuthorName');
                                        returned +=         '<time>' + time + '</time>';
                                        returned +=     '</p>';
                                        returned += '</div>';
                                        break;
                                    case 'wrapup':
                                        returned += '<span class="big-toggle"></span>';
                                        returned += '<h3>' + content + '</h3>';
                                        break;
                                    case 'advertisement':
                                        returned += content;
                                        
                                }
                               return returned;
			},
                        toggleWrap: function(e) {
                            //e.preventDefault();
                            this._toggleWrap($(e).closest('li').first());
                        },
                        _toggleWrap: function(item) {
                            if (item.hasClass('open')) {
                                var collapse = true;
                                var hash = window.location.hash;
                                if ( hash.length > 0) {
                                    item.nextUntil('.wrapup').each(function(){
                                        if ('#' + $(this).find('a').attr('name') == hash) {
                                            collapse = false;
                                        }
                                    });
                                }
                                if ( collapse ) {
                                    item.removeClass('open').addClass('closed');
                                    item.nextUntil('.wrapup').hide();
                                } else {
                                    //don't collapse wrap'
                                }
                            } else {
                                item.removeClass('closed').addClass('open');
{'fraction_non_alphanumeric': 0.1451492537313433, 'fraction_numerical': 0.003150912106135987, 'mean_word_length': 1.1079262431180634, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 70, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 156, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6101096', 'n_tokens_mistral': 7358, 'n_tokens_neox': 5997, 'n_words': 1174}