Skip to content

Commit

Permalink
Update with the new dy homepage
Browse files Browse the repository at this point in the history
  • Loading branch information
ComMouse committed Oct 23, 2016
1 parent be82f1e commit 64d000d
Show file tree
Hide file tree
Showing 99 changed files with 3,541 additions and 204 deletions.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 Arrow Rowe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

217 changes: 217 additions & 0 deletions dist/index/script/index-102720ad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
$(document).ready(function () {

/* =======================
* .selection
* ======================= */

var slc = [];
(function () {

$('.selection').each(init);
$('a[href^="#"]').each(initSmoothScroll);
$('.circle-fade').removeClass('circle-fade');

function init() {
var $e = $(this);
var opt = register($e);
if (!opt) {
return;
}
$e.html(template(opt));
if (opt.defaultIndex >= 0 && opt.defaultIndex < opt.count) {
$($e.find('.item')[opt.defaultIndex]).addClass('active');
}
}

function initSmoothScroll() {
var href = $(this).attr('href').substr(1);

$(this).click(function (event) {
scrollTo($('#' + href)[0]);
event.preventDefault();
});
}

function register($e) {
var opt = $.extend({
count: 3,
marginWidth: 36,
defaultIndex: 0,
on: []
}, {
count: $e.data('count'),
disabled: $e.hasClass('disabled'),
arrow: $e.hasClass('arrow'),
simple: $e.hasClass('simple'),
selector: $e.data('selector'),
defaultIndex: $e.data('default-index')
});
if (opt.selector) {
opt.$selector = $(opt.selector);
if (opt.$selector.data('panel-index') !== undefined) {
/* eslint-disable no-console */
console.warn('Element "%s" has got a selection binding %d already.', opt.selector, opt.$selector.data('panel-index'));
/* eslint-enable no-console */
return false;
}
var panelIndex = slc.push(opt) - 1;
opt.$selector.attr('data-panel-index', panelIndex);
initGallSize(opt);
}
return opt;
}

function initGallSize(opt) {
var w = opt.width = opt.$selector.width();
var h = opt.height = opt.$selector.height();
opt.$selector.find('.galls').css({
'width': (w * opt.count) + 'px',
'height': h + 'px'
});
opt.$selector.find('.gall').css({
'width': w + 'px',
'height': h + 'px'
});
}

function template(opt) {

var marginLeftBegin = (1 - opt.count) * opt.marginWidth * 0.5;

var items = [];
var itemTemplateHead = '<div class="item"' + (opt.disabled ? '' : ' fn="select"') + ' data-index="';
var marginLeft = marginLeftBegin;
for (var i = 0; i < opt.count; i++) {
items[i] = itemTemplateHead + i + '" style="margin-left:' + marginLeft + 'px"></div>';
marginLeft += opt.marginWidth;
}
var itemsHTML = items.join('');

var arrowHTML = '';
if (opt.arrow) {
arrowHTML = '<div class="arrow-contain"><div class="arrow-self" style="margin-left:' + marginLeftBegin + 'px"></div></div>';
}

return itemsHTML + arrowHTML;
}

})();

function getSelectIndexBySelector(selector) {
for (var i = 0; i < slc.length; i++) {
if (slc[i].selector === selector) {
return i;
}
}
return -1;
}

function onSelect(selector, fn) {
var selectIndex = getSelectIndexBySelector(selector);
if (selectIndex === -1) {
return -1;
}
return slc[selectIndex].on.push(fn) - 1;
}

// Smooth Scroll
function scrollTo(y) {
if (y instanceof HTMLElement) {
y = $(y).offset().top;
}
$('html, body').animate({scrollTop: y}, 'slow');
}

/* =======================
* [fn]
* ======================= */

var frc = window.frc = {};

$(document).on('click', '[fn]', function () {
var $e = $(this);
var fn = $e.attr('fn');
if (typeof frc[fn] === 'function') {
frc[fn].apply(this, [$e]);
}
});

frc.select = function ($e) {

var selector = $e.parent().data('selector');
if (!selector) { return; }
var panelIndex = $(selector).data('panel-index');
if (typeof panelIndex !== 'number') { return; }

var opt = slc[panelIndex];
var index = $e.data('index');
/* eslint-disable no-console */
console.log('Click on selection (' + panelIndex + ') "' + selector + '"[' + index + ']', opt);
/* eslint-enable no-console */

$(selector + ' > .galls').css({
'left': '-' + (opt.width * index) + 'px'
});

$e.parent().find('.item').removeClass('active');
$e.addClass('active');

if (opt.arrow) {
var marginLeftBegin = (1 - opt.count) * opt.marginWidth * 0.5;
$e.parent().find('.arrow-self').css({
'margin-left': (marginLeftBegin + index * opt.marginWidth).toString() + 'px'
});
}

if (opt.on.length) {
opt.on.forEach(function (fn) {
fn(index);
});
}

};

/* =======================
* Business Logic
* ======================= */

onSelect('#J_Intro', function () {});

onSelect('#J_Teams', function (index) {
$('#J_TeamName').html([
'Web 组',
'Android 组',
'iOS 组',
'设计组',
'Open-Class Community 组',
'呃... and more...'
][index]);
});

onSelect('#J_Cases', function (index) {
$('#J_CaseName').html([
'Web 端',
'Android App',
'iOS App'
][index]);
});

onSelect('#J_CaseWebAlbum', function (index) {
var images = $('#J_CaseWebSample > img');
images.removeClass('active');
images.eq(index).addClass('active');
});

onSelect('#J_CaseAndroidAlbum', function (index) {
var images = $('#J_CaseAndroidSample > img');
images.removeClass('active');
images.eq(index).addClass('active');
});

onSelect('#J_CaseIOSAlbum', function (index) {
var images = $('#J_CaseIOSSample > img');
images.removeClass('active');
images.eq(index).addClass('active');
});

});
Loading

0 comments on commit 64d000d

Please sign in to comment.