Commit cfc2f09e authored by PkSM3's avatar PkSM3

reamore library

parent 75a86b92
/*!
* Readmore.js jQuery plugin
* Author: @jed_foster
* Project home: jedfoster.github.io/Readmore.js
* Licensed under the MIT license
*/
;(function($) {
var readmore = 'readmore',
defaults = {
speed: 100,
maxHeight: 200,
heightMargin: 16,
moreLink: '<a href="#">Read More</a>',
lessLink: '<a href="#">Close</a>',
embedCSS: true,
sectionCSS: 'display: block; width: 100%;',
startOpen: false,
expandedClass: 'readmore-js-expanded',
collapsedClass: 'readmore-js-collapsed',
// callbacks
beforeToggle: function(){},
afterToggle: function(){}
},
cssEmbedded = false;
function Readmore( element, options ) {
this.element = element;
this.options = $.extend( {}, defaults, options);
$(this.element).data('max-height', this.options.maxHeight);
$(this.element).data('height-margin', this.options.heightMargin);
delete(this.options.maxHeight);
if(this.options.embedCSS && ! cssEmbedded) {
var styles = '.readmore-js-toggle, .readmore-js-section { ' + this.options.sectionCSS + ' } .readmore-js-section { overflow: hidden; }';
(function(d,u) {
var css=d.createElement('style');
css.type = 'text/css';
if(css.styleSheet) {
css.styleSheet.cssText = u;
}
else {
css.appendChild(d.createTextNode(u));
}
d.getElementsByTagName('head')[0].appendChild(css);
}(document, styles));
cssEmbedded = true;
}
this._defaults = defaults;
this._name = readmore;
this.init();
}
Readmore.prototype = {
init: function() {
var $this = this;
$(this.element).each(function() {
var current = $(this),
maxHeight = (current.css('max-height').replace(/[^-\d\.]/g, '') > current.data('max-height')) ? current.css('max-height').replace(/[^-\d\.]/g, '') : current.data('max-height'),
heightMargin = current.data('height-margin');
if(current.css('max-height') != 'none') {
current.css('max-height', 'none');
}
$this.setBoxHeight(current);
if(current.outerHeight(true) <= maxHeight + heightMargin) {
// The block is shorter than the limit, so there's no need to truncate it.
return true;
}
else {
current.addClass('readmore-js-section ' + $this.options.collapsedClass).data('collapsedHeight', maxHeight);
var useLink = $this.options.startOpen ? $this.options.lessLink : $this.options.moreLink;
current.after($(useLink).on('click', function(event) { $this.toggleSlider(this, current, event) }).addClass('readmore-js-toggle'));
if(!$this.options.startOpen) {
current.css({height: maxHeight});
}
}
});
$(window).on('resize', function(event) {
$this.resizeBoxes();
});
},
toggleSlider: function(trigger, element, event)
{
event.preventDefault();
var $this = this,
newHeight = newLink = sectionClass = '',
expanded = false,
collapsedHeight = $(element).data('collapsedHeight');
if ($(element).height() <= collapsedHeight) {
newHeight = $(element).data('expandedHeight') + 'px';
newLink = 'lessLink';
expanded = true;
sectionClass = $this.options.expandedClass;
}
else {
newHeight = collapsedHeight;
newLink = 'moreLink';
sectionClass = $this.options.collapsedClass;
}
// Fire beforeToggle callback
$this.options.beforeToggle(trigger, element, expanded);
$(element).animate({'height': newHeight}, {duration: $this.options.speed, complete: function() {
// Fire afterToggle callback
$this.options.afterToggle(trigger, element, expanded);
$(trigger).replaceWith($($this.options[newLink]).on('click', function(event) { $this.toggleSlider(this, element, event) }).addClass('readmore-js-toggle'));
$(this).removeClass($this.options.collapsedClass + ' ' + $this.options.expandedClass).addClass(sectionClass);
}
});
},
setBoxHeight: function(element) {
var el = element.clone().css({'height': 'auto', 'width': element.width(), 'overflow': 'hidden'}).insertAfter(element),
height = el.outerHeight(true);
el.remove();
element.data('expandedHeight', height);
},
resizeBoxes: function() {
var $this = this;
$('.readmore-js-section').each(function() {
var current = $(this);
$this.setBoxHeight(current);
if(current.height() > current.data('expandedHeight') || (current.hasClass($this.options.expandedClass) && current.height() < current.data('expandedHeight')) ) {
current.css('height', current.data('expandedHeight'));
}
});
},
destroy: function() {
var $this = this;
$(this.element).each(function() {
var current = $(this);
current.removeClass('readmore-js-section ' + $this.options.collapsedClass + ' ' + $this.options.expandedClass).css({'max-height': '', 'height': 'auto'}).next('.readmore-js-toggle').remove();
current.removeData();
});
}
};
$.fn[readmore] = function( options ) {
var args = arguments;
if (options === undefined || typeof options === 'object') {
return this.each(function () {
if ($.data(this, 'plugin_' + readmore)) {
var instance = $.data(this, 'plugin_' + readmore);
instance['destroy'].apply(instance);
}
$.data(this, 'plugin_' + readmore, new Readmore( this, options ));
});
} else if (typeof options === 'string' && options[0] !== '_' && options !== 'init') {
return this.each(function () {
var instance = $.data(this, 'plugin_' + readmore);
if (instance instanceof Readmore && typeof instance[options] === 'function') {
instance[options].apply( instance, Array.prototype.slice.call( args, 1 ) );
}
});
}
}
})(jQuery);
\ No newline at end of file
......@@ -182,7 +182,6 @@ function EdgeWeightFilter(sliderDivID , type_attrb , type , criteria) {
// criteria = "size"
if(partialGraph._core.graph.edges.length==0) {
$(sliderDivID).freshslider({
range: true,
step:1,
......@@ -192,11 +191,10 @@ function EdgeWeightFilter(sliderDivID , type_attrb , type , criteria) {
console.log(low, high);
}
});
return;
}
var filterparams = AlgorithmForSliders ( partialGraph._core.graph.edges , type_attrb , type , criteria)
var filterparams = AlgorithmForSliders ( Edges , type_attrb , type , criteria)
var steps = filterparams["steps"]
var finalarray = filterparams["finalarray"]
......@@ -204,7 +202,7 @@ function EdgeWeightFilter(sliderDivID , type_attrb , type , criteria) {
var lastvalue=("0-"+(steps-1));
pushFilterValue( sliderDivID , lastvalue )
//finished
$(sliderDivID).freshslider({
range: true,
......@@ -330,6 +328,7 @@ function EdgeWeightFilter(sliderDivID , type_attrb , type , criteria) {
}
});
}
......@@ -343,7 +342,7 @@ function NodeWeightFilter(sliderDivID , type_attrb , type , criteria) {
pr("\t\t\t\t\t\t[[ algorithm not applied "+sliderDivID+" ]]")
return;
}
// sliderDivID = "#sliderAEdgeWeight"
// type = "nodes1"
// type_attrb = "label"
......@@ -369,7 +368,7 @@ function NodeWeightFilter(sliderDivID , type_attrb , type , criteria) {
return;
}
var filterparams = AlgorithmForSliders ( partialGraph._core.graph.nodes , type_attrb , type , criteria)
var filterparams = AlgorithmForSliders ( Nodes , type_attrb , type , criteria)
var steps = filterparams["steps"]
var finalarray = filterparams["finalarray"]
......@@ -430,6 +429,7 @@ function NodeWeightFilter(sliderDivID , type_attrb , type , criteria) {
}
});
}
// Execution modes:
......@@ -440,9 +440,16 @@ function NodeWeightFilter(sliderDivID , type_attrb , type , criteria) {
function AlgorithmForSliders( elements , type_attrb , type , criteria) {
// // ( 1 )
// // get visible sigma nodes|edges
elems=elements.filter(function(e) {
var elems = [];/*=elements.filter(function(e) {
return e[type_attrb]==type;
});
});*/
for(var e in elements) {
// pr(elements[e])
// pr("\t"+type_attrb)
if( elements[e][type_attrb]==type )
elems.push(elements[e])
}
// // ( 2 )
// // extract [ "edgeID" : edgeWEIGHT ] | [ "nodeID" : nodeSIZE ]
......
......@@ -80,9 +80,8 @@ function sigmaLimits(){
altototal=$('#leftcolumn').height();
altofixtop=$('#fixedtop').height()
altodeftop=$('#defaultop').height()
if((anchototal-sidebar)>0)
$('#sigma-example').width(anchototal-sidebar);
$('#sigma-example').height(altototal-altofixtop-altodeftop-40);
$('#sigma-example').width(anchototal-sidebar);
$('#sigma-example').height(altototal-altofixtop-altodeftop-4);
pw=$('#sigma-example').width();
ph=$('#sigma-example').height();
......@@ -112,7 +111,7 @@ function bringTheNoise(pathfile,type){
// === resize topbar and tweakbar === //
var body=document.getElementsByTagName('body')[0];
body.style.paddingTop=$("#dafixedtop").height()+"px";
body.style.paddingTop="41px";
$("#changetype").click(function(){
......@@ -700,7 +699,7 @@ function SigmaLayouting( URL, DATA, NAME) {
dataType: 'jsonp',
async: true,
success : function(data) {
pr(data)
pr(data)
if(!isUndef(getUrlParam.seed))seed=getUrlParam.seed;
extractFromJson(data,seed);
......@@ -810,9 +809,10 @@ function SigmaLayouting( URL, DATA, NAME) {
// $("#sliderBEdgeWeight").html("");
// $("#sliderBNodeWeight").html("");
$("#category-B").show();
$("#colorGraph").hide();
EdgeWeightFilter("#sliderBEdgeWeight", "label" , "nodes2", "weight");
NodeWeightFilter ( "#sliderBNodeWeight" , "type" , "NGram" , "size");
$("#colorGraph").hide();
}
......
......@@ -386,9 +386,9 @@ function htmlfied_nodesatts(elems){
if(node.type==catSem){
information += '<li><b>' + node.label + '</b></li>';
google='<a href=http://www.google.com/#hl=en&source=hp&q=%20'+node.label.replace(" ","+")+'%20><img src="'+twjs+'img/google.png"></img></a>';
wiki = '<a href=http://en.wikipedia.org/wiki/'+node.label.replace(" ","_")+'><img src="'+twjs+'img/wikipedia.png"></img></a>';
flickr= '<a href=http://www.flickr.com/search/?w=all&q='+node.label.replace(" ","+")+'><img src="'+twjs+'img/flickr.png"></img></a>';
google='<a href=http://www.google.com/#hl=en&source=hp&q=%20'+node.label.replace(" ","+")+'%20><img src="'+'img/google.png"></img></a>';
wiki = '<a href=http://en.wikipedia.org/wiki/'+node.label.replace(" ","_")+'><img src="'+'img/wikipedia.png"></img></a>';
flickr= '<a href=http://www.flickr.com/search/?w=all&q='+node.label.replace(" ","+")+'><img src="'+'img/flickr.png"></img></a>';
information += '<li>'+google+"&nbsp;"+wiki+"&nbsp;"+flickr+'</li><br>';
semnodes.push(information)
}
......@@ -1583,9 +1583,9 @@ function changeToMeso(iwannagraph) {
socsemFlag=true;
}
// EdgeWeightFilter("#sliderBEdgeWeight", "label" , "nodes2", "weight");
// NodeWeightFilter ( "#sliderBNodeWeight" , "type" , "NGram" , "size")
// EdgeWeightFilter("#sliderAEdgeWeight", "label" , "nodes1", "weight");
$("#category-B").show();
EdgeWeightFilter("#sliderBEdgeWeight", "label" , "nodes2", "weight");
NodeWeightFilter ( "#sliderBNodeWeight" , "type" , "NGram" , "size");
$("#colorGraph").hide();
}
......@@ -1691,6 +1691,9 @@ function changeToMeso(iwannagraph) {
}
}
$("#category-B").show();
EdgeWeightFilter("#sliderBEdgeWeight", "label" , "nodes2", "weight");
NodeWeightFilter ( "#sliderBNodeWeight" , "type" , "NGram" , "size");
// EdgeWeightFilter("#sliderBEdgeWeight", "label" , "nodes2", "weight");
// NodeWeightFilter ( "#sliderBNodeWeight" , "type" , "NGram" , "size")
$("#colorGraph").hide();
......@@ -1737,6 +1740,11 @@ function changeToMacro(iwannagraph) {
createEdgesForExistingNodes(iwannagraph);
if(iwannagraph=="social") showMeSomeLabels(6);
else {
$("#category-B").show();
EdgeWeightFilter("#sliderBEdgeWeight", "label" , "nodes2", "weight");
NodeWeightFilter ( "#sliderBNodeWeight" , "type" , "NGram" , "size");
}
swMacro=true;
if (!is_empty(selections))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment