Skip to content

Commit

Permalink
Merge pull request #22 from datopian/odni-upgrade
Browse files Browse the repository at this point in the history
ckanext-opendatani upgrade
  • Loading branch information
anuveyatsu authored Oct 8, 2021
2 parents 90aeafa + 4e92102 commit bffbf40
Show file tree
Hide file tree
Showing 48 changed files with 2,651 additions and 189 deletions.
1,113 changes: 1,113 additions & 0 deletions ckanext/opendatani/assets/css/theme.css

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions ckanext/opendatani/assets/js/groups.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$(document).ready(function(){
var defaults = {

exclude: [ 'rgb(0,0,0)', 'rgba(255,255,255)', 'rgb(255,255,255)' ],
yiqThreshold: 200,

};
$.adaptiveBackground.run(defaults)

});
41 changes: 41 additions & 0 deletions ckanext/opendatani/assets/js/home.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
$(document).ready(function(){
var defaults = {

exclude: [ 'rgb(0,0,0)', 'rgba(255,255,255)', 'rgb(255,255,255)' ],
yiqThreshold: 200,
parent: '.group',

};
$.adaptiveBackground.run(defaults)


// twitter
twitterFetcher.fetch({
"profile": {"screenName": 'opendatani'},
"domId": 'tweets',
"maxTweets": 5,
"enableLinks": true,
"customCallback":handleTweets,
});


function handleTweets(tweets){
var i=0;
var j=tweets.length;
var l="<ul class='carousel-inner'>";
while(i<j){
l+="<li class='item' id='tweet"+i+"'>"+tweets[i]+"</li>";
i++;
}
l+="</ul>";
document.getElementById("tweets").innerHTML=l;
var n=(j-1);

$( "#tweet0" ).addClass( "active" );

$('.carousel').carousel({
interval: 10000
})
}

});
136 changes: 136 additions & 0 deletions ckanext/opendatani/assets/js/jquery.adaptive-backgrounds.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
/*
* Tweaked version of adaptive-backgrounds.js
* https://github.com/mintcanary/jquery.adaptive-backgrounds.js
*/

/* jshint debug: true, expr: true */

;(function($){

/* Constants & defaults. */
var DATA_COLOR = 'data-ab-color';
var DATA_PARENT = 'data-ab-parent';
var DATA_CSS_BG = 'data-ab-css-background';
var EVENT_CF = 'ab-color-found';

var DEFAULTS = {
selector: '[data-adaptive-background]',
parent: null,
exclude: [ 'rgb(0,0,0)', 'rgba(255,255,255)' ],
normalizeTextColor: false,
normalizedTextColors: {
light: "#fff",
dark: "#000"
},
lumaClasses: {
light: "ab-light",
dark: "ab-dark"
},
yiqThreshold: '128'
};

// Include RGBaster - https://github.com/briangonzalez/rgbaster.js
/* jshint ignore:start */
!function(n){"use strict";var t=function(){return document.createElement("canvas").getContext("2d")},e=function(n,e){var a=new Image,o=n.src||n;"data:"!==o.substring(0,5)&&(a.crossOrigin="Anonymous"),a.onload=function(){var n=t("2d");n.drawImage(a,0,0);var o=n.getImageData(0,0,a.width,a.height);e&&e(o.data)},a.src=o},a=function(n){return["rgb(",n,")"].join("")},o=function(n){return n.map(function(n){return a(n.name)})},r=5,i=10,c={};c.colors=function(n,t){t=t||{};var c=t.exclude||[],u=t.paletteSize||i;e(n,function(e){for(var i=n.width*n.height||e.length,m={},s="",d=[],f={dominant:{name:"",count:0},palette:Array.apply(null,new Array(u)).map(Boolean).map(function(){return{name:"0,0,0",count:0}})},l=0;i>l;){if(d[0]=e[l],d[1]=e[l+1],d[2]=e[l+2],s=d.join(","),m[s]=s in m?m[s]+1:1,-1===c.indexOf(a(s))){var g=m[s];g>f.dominant.count?(f.dominant.name=s,f.dominant.count=g):f.palette.some(function(n){return g>n.count?(n.name=s,n.count=g,!0):void 0})}l+=4*r}if(t.success){var p=o(f.palette);t.success({dominant:a(f.dominant.name),secondary:p[0],palette:p})}})},n.RGBaster=n.RGBaster||c}(window);
/* jshint ignore:end */


/*
Our main function declaration.
*/
$.adaptiveBackground = {
run: function( options ){
var opts = $.extend({}, DEFAULTS, options);

/* Loop over each element, waiting for it to load
then finding its color, and triggering the
color found event when color has been found.
*/
$( opts.selector ).each(function(index, el){
var $this = $(this);

/* Small helper functions which applies
colors, attrs, triggers events, etc.
*/
var handleColors = function () {
var img = useCSSBackground() ? getCSSBackground() : $this[0];

RGBaster.colors(img, {
paletteSize: 20,
exclude: opts.exclude,
success: function(colors) {
$this.attr(DATA_COLOR, colors.dominant);
$this.trigger(EVENT_CF, { color: colors.dominant, palette: colors.palette });
}
});

};

var useCSSBackground = function(){
var attr = $this.attr( DATA_CSS_BG );
return (typeof attr !== typeof undefined && attr !== false);
};

var getCSSBackground = function(){
var str = $this.css('background-image');
var regex = /\(([^)]+)\)/;
var match = regex.exec(str)[1].replace(/"/g, '')
return match;
};

/* Subscribe to our color-found event. */
$this.on( EVENT_CF, function(ev, data){

// Try to find the parent.
var $parent;
if ( opts.parent && $this.parents( opts.parent ).length ) {
$parent = $this.parents( opts.parent );
}
else if ( $this.attr( DATA_PARENT ) && $this.parents( $this.attr( DATA_PARENT ) ).length ){
$parent = $this.parents( $this.attr( DATA_PARENT ) );
}
else if ( useCSSBackground() ){
$parent = $this;
}
else if (opts.parent) {
$parent = $this.parents( opts.parent );
}
else {
$parent = $this.parent();
}

$parent.css({ backgroundColor: data.color });

// Helper function to calculate yiq - http://en.wikipedia.org/wiki/YIQ
var getYIQ = function(color){
var rgb = data.color.match(/\d+/g);
return ((rgb[0]*299)+(rgb[1]*587)+(rgb[2]*114))/1000;
};

var getNormalizedTextColor = function (color){
return getYIQ(color) >= opts.yiqThreshold ? opts.normalizedTextColors.dark : opts.normalizedTextColors.light;
};

var getLumaClass = function (color){
return getYIQ(color) <= opts.yiqThreshold ? opts.lumaClasses.dark : opts.lumaClasses.light;
};

// Normalize the text color based on luminance.
if ( opts.normalizeTextColor )
$parent.css({ color: getNormalizedTextColor(data.color) });

// Add a class based on luminance.
$parent.addClass( getLumaClass(data.color) )
.attr('data-ab-yaq', getYIQ(data.color));

opts.success && opts.success($this, data);
});

/* Handle the colors. */
handleColors();

});
},
};

})(jQuery);
10 changes: 10 additions & 0 deletions ckanext/opendatani/assets/js/privacy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
function privacyFunction(){
var privacy = document.getElementById("field-privacy").checked;
if (privacy === true) {
return true
}
else {
alert('Consent to process has not been provided, user account cannot be created');
return false
}
}
Loading

0 comments on commit bffbf40

Please sign in to comment.