Skip to content

Instantly share code, notes, and snippets.

@artygrand
artygrand / equal-height.js
Created June 21, 2016 12:30
Equal heights for catalog grid
Object.defineProperty(Array.prototype, 'chunk', {value: function(n) {
return Array.from(Array(Math.ceil(this.length/n)), (_,i)=>this.slice(i*n,i*n+n));
}});
$(window).load(function(){
$.each($('.hit-info a').toArray().chunk(4), function(index, els) {
var maxheight = 0;
$(els).each(function(){
var height = $(this).outerHeight()
if(height > maxheight) {
maxheight = height;
@artygrand
artygrand / context-sites.php
Created July 17, 2016 08:45
SyDES plugin: Add dropdown with all sites in context menu
<?php
$app->on('before.module', '*', function() use($app){
$app->response->context['sites'] = array(
'title' => 'Сайты',
'link' => '',
'children' => array(),
);
$allsites = $app->cache->get('allsites');
if (!$allsites){
@artygrand
artygrand / select-theme.php
Created July 17, 2016 08:53
SyDES plugin: select theme for subsite
<?php
$app->on('after.module', 'pages/view/*', function() use($app){
$parts = explode('/', $app->response->data['fullpath']);
$themes = str_replace(DIR_TEMPLATE, '', glob(DIR_TEMPLATE . '*', GLOB_ONLYDIR));
if (in_array($parts[0], $themes)) {
$conf = $app->config_site;
$conf['template'] = $parts[0];
$app->config_site = $conf;
}
@artygrand
artygrand / script.js
Created September 20, 2016 13:40
Simple stars vote script for input
$(document).ready(function(){
$('.stars').each(function(){
var input = $(this), stars = $('<div class="stars-visible"><span></span><span></span><span></span><span></span><span></span></div>')
stars.find('span').click(function(){
$(this).addClass('active').siblings().removeClass('active')
input.val(5-$(this).index())
})
input.hide().before(stars)
})
})
@artygrand
artygrand / isotope.php
Created October 22, 2016 10:43
Isotope theme for module Sydes.Album
<?php
$this->response->script[] = 'https://cdnjs.cloudflare.com/ajax/libs/jquery.isotope/3.0.1/isotope.pkgd.min.js';
?>
<div id="filters" class="button-group">
<button class="button is-checked" data-filter="*">Все</button>
<?php foreach ($result['tags'] as $tag){ ?>
<button class="button" data-filter=".<?=convertToAscii($tag);?>"><?=$tag;?></button>
<?php } ?>
</div>
@artygrand
artygrand / script.js
Created December 9, 2016 11:09
Fixed nav on scroll
var nav_offset = $('nav').offset().top,
nav_height = $('nav').outerHeight(true);
$('nav').after($('<div>').addClass('padding').css('height', nav_height));
$(window).scroll(function(){
if ($(this).scrollTop() > nav_offset){
$('nav').addClass('fixed')
} else {
$('nav').removeClass('fixed')
}
});
@artygrand
artygrand / decoder.php
Last active February 24, 2017 10:37
Sample XOR encoder
<?php
$encoded = "..."; // <-- encoded string from the request
$decoded = "";
for( $i = 0; $i < strlen($encoded); $i++ ) {
$b = ord($encoded[$i]);
$a = $b ^ 123; // <-- must be same number used to encode the character
$decoded .= chr($a)
}
@artygrand
artygrand / index.html
Created February 28, 2017 08:15
old JS landscape generatror
<HEAD><SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var WIDTH = 1;
var XA = 0;
var XB = 64;
var YA = 0;
var YB = 64;
var Z1 = 0;
var Z2 = 0;
@artygrand
artygrand / index.html
Created February 28, 2017 08:17
old JS maze generator
<HEAD><script>
<!-- Original: Darren Latham -->
<!-- Begin
function buildMaze(width, height) {
document.write("<html><style type=\"text/css\">.b { background:black;color:black} ");
document.write(".w { color:white;background:white }</style><body>");
var error = 0;
if ( (parseInt(width) < 5) || (parseInt(height) > 20) ) {
document.write("<p>The width entered ("+width+") must be between 5 and 20. Hit back to try again.</p>");
@artygrand
artygrand / load.php
Created March 22, 2017 07:50
Curl file loader
<?php
set_time_limit(0);
$file = dirname(__FILE__) . '/file.tgz';
$url = 'http://site/file.tgz';
$file_offset=filesize($file);
$file_offset=$file_offset-1024*4;