")
37 | .attr("id", containerTabId)
38 | .addClass("nav nav-tabs navbar-fixed-bottom");
39 |
40 |
41 | outputTabHeader.appendTo(tabs);
42 | messagesTabHeader.appendTo(tabs);
43 | var container = $("#"+settings.resultsContainerId);
44 | tabs.appendTo(container);
45 |
46 | var tabContent = $('' +
47 | '
' +
48 | '
' +
49 | '
').appendTo(container);
50 |
51 | // Activate Tab Navigation
52 | $('#' + containerTabId +' a').click(function (e) {
53 | e.preventDefault();
54 | $(this).tab('show');
55 | });
56 |
57 | var outputContainer = $("#" + outputContainerId);
58 | var messagesContainer = $("#" + messagesContainerId);
59 |
60 | function activateOutputTab() {
61 | $('#' + containerTabId + ' a[href="#' + outputContainerId + '"]').tab('show');
62 | }
63 |
64 | function activateMessagesTab() {
65 | $('#' + containerTabId + ' a[href="#' + messagesContainerId + '"]').tab('show');
66 | }
67 |
68 | var instance = {
69 | clear: function () {
70 | outputContainer.text("");
71 | messagesContainer.text("");
72 | },
73 | activateOutputTab: activateOutputTab,
74 | activateMessagesTab: activateMessagesTab,
75 | addMessage: addMessage,
76 | onSuccess: function (results) {
77 | results.forEach( function (item) {
78 | if (item.type === "info") {
79 | if (settings.packageInfoEnabled) {
80 | createDisplayItem(item).appendTo(messagesContainer);
81 | }
82 | } else {
83 | createDisplayItem(item).appendTo(outputContainer);
84 | }
85 | });
86 | activateOutputTab();
87 | },
88 | onFail: function (errors) {
89 | errors.forEach( function (item) {
90 | item.text = item.exception;
91 | createDisplayItem(item).appendTo(messagesContainer);
92 | })
93 | activateMessagesTab();
94 | }
95 | };
96 |
97 | function addMessage(message) {
98 | $("")
99 | .addClass(errorSeverityStyles[message.severity])
100 | .html('
' + message.severity + ": " + message.titleName + " - " + message.x)
101 | .appendTo(messagesContainer);
102 | }
103 |
104 | function createDisplayItem(item) {
105 | return $("
")
106 | .addClass(resultTypeStyles[item.type])
107 | .html(unEscapeString(item.text));
108 | }
109 |
110 | return instance;
111 | }
112 |
113 | return ResultsContainer;
114 |
115 | })();
116 |
--------------------------------------------------------------------------------
/editor/static/icons/class.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/kotlin-web-site-cn/71e04d308d1b9163b8337ab914dc7568dcfeb31d/editor/static/icons/class.png
--------------------------------------------------------------------------------
/editor/static/icons/error.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/kotlin-web-site-cn/71e04d308d1b9163b8337ab914dc7568dcfeb31d/editor/static/icons/error.png
--------------------------------------------------------------------------------
/editor/static/icons/method.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/kotlin-web-site-cn/71e04d308d1b9163b8337ab914dc7568dcfeb31d/editor/static/icons/method.png
--------------------------------------------------------------------------------
/editor/static/icons/package.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/kotlin-web-site-cn/71e04d308d1b9163b8337ab914dc7568dcfeb31d/editor/static/icons/package.png
--------------------------------------------------------------------------------
/editor/static/icons/property.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/kotlin-web-site-cn/71e04d308d1b9163b8337ab914dc7568dcfeb31d/editor/static/icons/property.png
--------------------------------------------------------------------------------
/editor/static/icons/warning.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/kotlin-web-site-cn/71e04d308d1b9163b8337ab914dc7568dcfeb31d/editor/static/icons/warning.png
--------------------------------------------------------------------------------
/editor/static/icons/wavyline-green.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/kotlin-web-site-cn/71e04d308d1b9163b8337ab914dc7568dcfeb31d/editor/static/icons/wavyline-green.gif
--------------------------------------------------------------------------------
/editor/static/icons/wavyline-red.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/kotlin-web-site-cn/71e04d308d1b9163b8337ab914dc7568dcfeb31d/editor/static/icons/wavyline-red.gif
--------------------------------------------------------------------------------
/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/daimajia/kotlin-web-site-cn/71e04d308d1b9163b8337ab914dc7568dcfeb31d/favicon.ico
--------------------------------------------------------------------------------
/js/com/carousel.js:
--------------------------------------------------------------------------------
1 | define([
2 | 'jquery',
3 | 'jcarousel'
4 | ], function($)
5 | {
6 | function Carousel(config) {
7 | var that = this,
8 | $wrapElem,
9 | $carousel;
10 |
11 | that._elem = config.elem;
12 |
13 | $wrapElem = $(that._elem);
14 | $carousel = $wrapElem.find('.js-carousel');
15 |
16 | $carousel.jcarousel({
17 | list: '.js-carousel-list'
18 | });
19 |
20 | $wrapElem.find('.js-carousel-nav-prev')
21 | .jcarouselControl({
22 | target: '-=1'
23 | })
24 | .on('jcarouselcontrol:active', function () {
25 | $(this).removeClass('is_disabled');
26 | })
27 | .on('jcarouselcontrol:inactive', function () {
28 | $(this).addClass('is_disabled');
29 | });
30 |
31 | $wrapElem.find('.js-carousel-nav-next')
32 | .jcarouselControl({
33 | target: '+=1'
34 | })
35 | .on('jcarouselcontrol:active', function () {
36 | $(this).removeClass('is_disabled');
37 | })
38 | .on('jcarouselcontrol:inactive', function () {
39 | $(this).addClass('is_disabled');
40 | });
41 | }
42 |
43 | Carousel.prototype._elem = null;
44 |
45 | return Carousel;
46 | });
--------------------------------------------------------------------------------
/js/com/toc.js:
--------------------------------------------------------------------------------
1 | define(['jquery'], function($) {
2 | function Toc(options) {
3 | var that = this,
4 | option;
5 |
6 | if (typeof options == 'object') {
7 | for (option in options) {
8 | if (option in that) {
9 | that[option] = options[option];
10 | }
11 | }
12 | }
13 |
14 | that.scope = document.body;
15 | that.init(options);
16 | }
17 |
18 | Toc.prototype = {
19 | selector: 'h1,h2,h3,h4,h5,h6',
20 |
21 | scope: null,
22 |
23 | from: 1,
24 |
25 | to: 6,
26 |
27 | map: null,
28 |
29 | createLinks: true,
30 |
31 | cssClasses: {
32 | tocList: 'toc',
33 | tocListItem: 'toc-item_level_#'
34 | },
35 |
36 | init: function(options) {
37 | var that = this;
38 |
39 | that.map = that.get();
40 | },
41 |
42 | __getMap: function(selector, scope) {
43 | var that = this;
44 | var sections = [], sectionNode, section;
45 | var i, len;
46 | var selector = (typeof selector != 'undefined') ? selector : that.selector;
47 | var scope = (typeof scope != 'undefined') ? scope : that.scope;
48 | var sectionsNodes = ('querySelectorAll' in scope)
49 | ? scope.querySelectorAll(selector)
50 | : $(selector, scope);
51 |
52 | for (i = 0, len = sectionsNodes.length; i < len; i++) {
53 | sectionNode = sectionsNodes[i];
54 | section = {
55 | id: sectionNode.id,
56 | level: parseInt(sectionNode.tagName.substr(1,1)),
57 | title: $(sectionNode).text(),
58 | node: sectionNode,
59 | content: []
60 | };
61 | sections.push(section);
62 | }
63 | return sections;
64 | },
65 |
66 | get: function(options) {
67 | var that = this;
68 | var selector = (options && typeof options.selector != 'undefined') ? options.selector : that.selector;
69 | var scope = (options && typeof options.scope != 'undefined') ? options.scope : that.scope;
70 | var sectMap, tocList;
71 |
72 | sectMap = that.__getMap(selector, scope);
73 | if (sectMap.length == 0) {
74 | return [];
75 | }
76 |
77 | tocList = that.__getBranch(sectMap, sectMap[0].level, 0);
78 | return tocList;
79 | },
80 |
81 | render: function(opts) {
82 | var that = this;
83 | var from = (opts && typeof opts.from != 'undefined') ? opts.from : that.from;
84 | var to = (opts && typeof opts.to != 'undefined') ? opts.to : that.to;
85 | var target = (opts && typeof opts.target != 'undefined') ? opts.target : null;
86 | var toc;
87 |
88 | toc = that.__create(that.map, from, to);
89 |
90 | if (target != null) {
91 | target.appendChild(toc);
92 | }
93 |
94 | return toc;
95 | },
96 |
97 | __create: function(list, from, to) {
98 | var that = this;
99 | var createLinks = that.createLinks;
100 | var ul, li, a, title;
101 | var section, sectionContent;
102 | var css = that.cssClasses;
103 | var i, len;
104 |
105 | if (list.length == 0) {
106 | return null;
107 | }
108 |
109 | ul = document.createElement('ul');
110 | ul.className = css.tocList;
111 | for (i = 0, len = list.length; i < len; i++) {
112 | section = list[i];
113 |
114 | li = document.createElement('li');
115 | li.className = css.tocListItem.replace('#', section.level);
116 |
117 | if (createLinks) {
118 | title = document.createElement('a');
119 | title.href = "#"+ section.id;
120 | title.appendChild(document.createTextNode(section.title));
121 | }
122 | else {
123 | title = document.createTextNode(section.title);
124 | }
125 |
126 | li.appendChild(title);
127 |
128 | if (section.content.length > 0 &&
129 | section.content[0].level >= from &&
130 | section.content[0].level <= to) {
131 | sectionContent = that.__create(section.content, from, to);
132 | li.appendChild(sectionContent);
133 | }
134 |
135 | ul.appendChild(li);
136 | }
137 | return ul;
138 | },
139 |
140 | __getBranch: function(sections, level, start, firstRun) {
141 | var that = this;
142 | var firstRun = (typeof firstRun !== 'undefined') ? firstRun : true;
143 | var end = sections.length;
144 | var tree = [];
145 | var section, prevSect;
146 |
147 | for (var i = start; i < end; i++) {
148 | section = sections[i];
149 | prevSect = (typeof sections[i-1] !== 'undefined')
150 | ? sections[i-1]
151 | : null;
152 |
153 | if (section.level == level) {
154 | // siblings
155 | tree.push(section);
156 | }
157 | else if (section.level > level) {
158 | // inner branch
159 | if (prevSect && prevSect.level < section.level) {
160 | prevSect.content = this.__getBranch(sections, section.level, i, false);
161 | }
162 | }
163 | else if (section.level < level) {
164 | // out of branch
165 | if (!firstRun) {
166 | break;
167 | }
168 | }
169 | }
170 | return tree;
171 | }
172 | };
173 |
174 | return Toc;
175 | });
--------------------------------------------------------------------------------
/js/com/video-gallery.js:
--------------------------------------------------------------------------------
1 | define([
2 | 'jquery',
3 | 'com/nav-tree',
4 | 'com/video-player'
5 | ], function ($, NavTree, Player) {
6 |
7 | NavTree.prototype.templates.leafItem = function (item) {
8 | var hasUrl = 'url' in item,
9 | hasDuration = 'duration' in item,
10 | hasDescription = 'description' in item,
11 | isExternal = hasUrl && Player.getVideoIdFromUrl(item.url) === null,
12 | itemClassNames,
13 | itemLinkClassNames,
14 | attrs = {};
15 |
16 | itemClassNames = ['tree-item', 'tree-leaf', 'js-item', 'js-leaf', 'video-item'];
17 | itemLinkClassNames = ['tree-item-title', 'tree-leaf-title', 'js-item-title', 'js-leaf-title', 'video-item-title'];
18 |
19 | if (isExternal)
20 | itemLinkClassNames.push('is_external');
21 |
22 | if (hasUrl) {
23 | attrs['href'] = item.url;
24 | }
25 |
26 | if (hasDescription) {
27 | attrs['data-description'] = item.description;
28 | }
29 |
30 | var t =
31 | ['.' + itemClassNames.join('.'),
32 | [
33 | (hasUrl ? 'a.' : 'div.') + itemLinkClassNames.join('.'), attrs,
34 | ['span.marker'],
35 | ['span.text', item.title],
36 | hasDuration
37 | ? ['span.duration', item.duration]
38 | : null
39 | ]
40 | ];
41 |
42 | return t;
43 | };
44 |
45 | function VideoGallery(elem, config) {
46 |
47 | var tree = new NavTree(elem, {data: config.data});
48 |
49 | var player = new Player(config.playerElem, {
50 | width: '100%',
51 | height: 480,
52 | videoId: 'viiDaLpPfN4'
53 | });
54 |
55 | tree.on('selectLeaf', function(e, branch, elem) {
56 | var videoUrl = elem.href,
57 | videoId,
58 | description = elem.getAttribute('data-description') || '',
59 | $elem = $(elem);
60 |
61 | videoId = Player.getVideoIdFromUrl(videoUrl);
62 |
63 | if (videoId) {
64 | player.playVideo(videoId);
65 |
66 | config.descriptionElem.innerHTML = description;
67 | }
68 | });
69 |
70 | $(elem).find('a').on('click', function(e) {
71 | var $el = $(this);
72 | var isExternal = $el.hasClass('is_external');
73 |
74 | if (isExternal)
75 | $el.attr('target', '_blank');
76 | else
77 | e.preventDefault();
78 |
79 | });
80 | }
81 |
82 | return VideoGallery;
83 | });
--------------------------------------------------------------------------------
/js/config/bootstrap.js:
--------------------------------------------------------------------------------
1 | require._config({
2 | baseUrl: '/kotlin-web-site-cn/js',
3 |
4 | paths: {
5 | 'jquery': 'vendor/jquery/jquery-1.11.0.min',
6 | 'jcarousel': 'vendor/jcarousel/jquery.jcarousel.min'
7 | },
8 |
9 | shim: {
10 | 'jcarousel': {
11 | deps: ['jquery'],
12 | exports: 'jQuery.fn.jcarousel'
13 | }
14 | },
15 |
16 | deps: ['require'],
17 |
18 | callback: function (require) {
19 | var html = document.getElementsByTagName('html')[0];
20 |
21 | html.className = html.className.replace('no-js', '');
22 |
23 | // OS detection
24 | if (navigator.userAgent.indexOf('Linux') > -1)
25 | html.className += ' os_linux';
26 |
27 | // Browser detection
28 | if ('chrome' in window)
29 | html.className += ' ua_chrome';
30 | else if (navigator.userAgent.toLowerCase().indexOf('firefox') > -1)
31 | html.className += ' ua_firefox';
32 |
33 | // hack to force :active support in mobile Safari
34 | document.addEventListener("touchstart", function () {}, false);
35 |
36 | // OS and browser detection
37 | require(['jquery']);
38 | }
39 | });
--------------------------------------------------------------------------------
/js/page/events.js:
--------------------------------------------------------------------------------
1 | define(['com/events-table'], function (EventsTable) {
2 |
3 | return function (elem, data) {
4 | $(document).ready(function () {
5 | new EventsTable(elem, data);
6 | });
7 | };
8 |
9 | });
--------------------------------------------------------------------------------
/js/page/index.js:
--------------------------------------------------------------------------------
1 | define([
2 | 'jquery',
3 | 'com/carousel',
4 | 'com/video-player'
5 | ], function ($, Carousel, Player) {
6 |
7 | var initTabs = function () {
8 | var $tabs = $('.js-tab');
9 |
10 | $tabs.on('click', function () {
11 | var $tab = $(this),
12 | tabId = $tab.attr('data-tab-id');
13 |
14 | if ($tab.hasClass('is_active')) {
15 | return;
16 | }
17 |
18 | $tabs.each(function () {
19 | var $currentTab = $(this),
20 | currentTabId = $currentTab.attr('data-tab-id'),
21 | $tabContentNode = $('#' + currentTabId);
22 |
23 | if (tabId === currentTabId) {
24 | $currentTab.addClass('is_active');
25 | $tabContentNode.removeClass('is_hidden');
26 | } else {
27 | $currentTab.removeClass('is_active');
28 | $tabContentNode.addClass('is_hidden');
29 | }
30 | });
31 | });
32 | };
33 |
34 | var initPopups = function () {
35 | var popups =
36 | {
37 | init: function () {
38 | var that = this,
39 | $popups = $('.js-popup'),
40 | $popupShowButtons = $('.js-popup-open-button'),
41 | $popupHideButtons = $('.js-popup-close-button');
42 |
43 | $popupShowButtons.on('click', function (e) {
44 | var popupId = this.getAttribute('data-popup-id');
45 |
46 | e.stopPropagation();
47 | that.showPopup(popupId);
48 | });
49 |
50 | $popupHideButtons.on('click', function (e) {
51 | var popupId = this.getAttribute('data-popup-id');
52 |
53 | e.stopPropagation();
54 | that.hidePopup(popupId);
55 | });
56 |
57 | $(document.body).on('click', function () {
58 | $popups.each(function () {
59 | var $popup = $(this),
60 | popupId = this.id;
61 |
62 | if (!$popup.hasClass('_hidden')) {
63 | that.hidePopup(popupId);
64 | }
65 | });
66 | });
67 |
68 | $popups.on('click', function (e) {
69 | e.stopPropagation();
70 | })
71 | },
72 |
73 | togglePopup: function (id) {
74 | var that = this,
75 | $popupNode = $('#' + id);
76 |
77 | if ($popupNode.hasClass('_hidden')) {
78 | that.showPopup(id);
79 | } else {
80 | that.hidePopup(id);
81 | }
82 | },
83 |
84 | showPopup: function (id) {
85 | var $popupNode = $('#' + id);
86 |
87 | $popupNode.removeClass('_hidden');
88 | },
89 |
90 | hidePopup: function (id) {
91 | var $popupNode = $('#' + id);
92 |
93 | $popupNode.addClass('_hidden');
94 | }
95 | };
96 |
97 | popups.init();
98 | };
99 |
100 | var initPlayer = function () {
101 | var $playerBlock = $('.js-video-player-wrap'),
102 | $playerPlaceholder = $playerBlock.find('.js-video-player'),
103 | $thumbLink = $playerBlock.find('.js-video-thumb-link'),
104 | playerHeight = $playerBlock.get(0).offsetHeight;
105 |
106 | $playerBlock.css('height', playerHeight);
107 |
108 | $thumbLink.on('click', function (e) {
109 | var $thumbLink = $(this),
110 | videoId = Player.getVideoIdFromUrl(this.href);
111 |
112 | if (!videoId) {
113 | return;
114 | }
115 |
116 | $playerBlock.addClass('is_showing-video');
117 |
118 | setTimeout(function () {
119 | $thumbLink.remove();
120 | new Player($playerPlaceholder.get(0), {
121 | width: '100%',
122 | height: playerHeight,
123 | videoId: videoId,
124 | autoPlay: true
125 | });
126 |
127 | }, 400);
128 |
129 | e.preventDefault();
130 | });
131 | };
132 |
133 | return (function () {
134 | $(document).ready(function () {
135 | // Features carousel
136 | new Carousel({
137 | elem: document.getElementById('features-carousel-wrap')
138 | });
139 |
140 | // Testimonials carousel
141 | new Carousel({
142 | elem: document.getElementById('testimonials-carousel-wrap')
143 | });
144 |
145 | initPlayer();
146 | initPopups();
147 | initTabs();
148 | });
149 | })();
150 |
151 | });
--------------------------------------------------------------------------------
/js/page/reference.js:
--------------------------------------------------------------------------------
1 | define(['com/nav-tree'], function (NavTree) {
2 |
3 | return (function () {
4 | $(document).ready(function () {
5 | new NavTree(document.getElementById('reference-nav'));
6 | });
7 | });
8 |
9 | });
--------------------------------------------------------------------------------
/js/page/tutorials.js:
--------------------------------------------------------------------------------
1 | define(['com/nav-tree'], function (NavTree) {
2 |
3 | return (function () {
4 | $(document).ready(function () {
5 | new NavTree(document.getElementById('tutorials-nav'));
6 | });
7 | })();
8 |
9 | });
--------------------------------------------------------------------------------
/js/page/videos.js:
--------------------------------------------------------------------------------
1 | define(['com/video-gallery'], function(VideoGallery) {
2 |
3 | return function(data) {
4 | new VideoGallery(data.elem, {
5 | playerElem: data.playerElem,
6 | descriptionElem: data.descriptionElem,
7 | data: data.videos
8 | });
9 | };
10 |
11 | });
--------------------------------------------------------------------------------
/js/util/common.js:
--------------------------------------------------------------------------------
1 | define({
2 | isArray: function(variable) {
3 | return variable instanceof Array;
4 | },
5 |
6 | isObject: function(variable) {
7 | return variable instanceof Object;
8 | },
9 |
10 | isDate: function(variable) {
11 | return variable instanceof Date;
12 | }
13 | });
--------------------------------------------------------------------------------
/js/util/cookie.js:
--------------------------------------------------------------------------------
1 | define(function () {
2 | var cookieUtils = {
3 |
4 | isCookiesEnabled: function () {
5 | return navigator.cookieEnabled;
6 | },
7 |
8 | /**
9 | * @param name
10 | * @returns {string|null}
11 | */
12 | getCookie: function (name) {
13 | var regexp = new RegExp('(?:^|; )' + name.replace(/([\.$?*|{}\(\)\[\]\\\/\+^])/g, '\\$1') + '=([^;]*)');
14 | var matches = document.cookie.match(regexp);
15 | return matches ? decodeURIComponent(matches[1]) : null;
16 | },
17 |
18 | /**
19 | * @param {string} name
20 | * @returns {boolean}
21 | */
22 | hasCookie: function (name) {
23 | var cookie = this.getCookie(name);
24 | return cookie !== null;
25 | },
26 |
27 | /**
28 | * @param {string} name
29 | * @param {string} value
30 | * @param {object} options
31 | * options.expires (number (in seconds), Date, null)
32 | * options.path (string)
33 | * options.domain (string)
34 | * options.secure (boolean)
35 | * @returns void
36 | */
37 | setCookie: function (name, value, options) {
38 | options = options || {};
39 |
40 | var expires = options.expires;
41 |
42 | if (typeof expires === 'number' && expires) {
43 | var d = new Date();
44 | d.setTime(d.getTime() + expires * 1000);
45 | expires = options.expires = d;
46 | }
47 | if (expires && expires.toUTCString) {
48 | options.expires = expires.toUTCString();
49 | }
50 |
51 | value = encodeURIComponent(value);
52 |
53 | var updatedCookie = name + '=' + value;
54 |
55 | for (var propName in options) {
56 | updatedCookie += '; ' + propName;
57 | var propValue = options[propName];
58 | if (propValue !== true) {
59 | updatedCookie += "=" + propValue;
60 | }
61 | }
62 |
63 | document.cookie = updatedCookie;
64 | },
65 |
66 | /**
67 | * @param {string} name
68 | * @returns void
69 | */
70 | removeCookie: function (name) {
71 | this.setCookie(name, '', {expires: -1});
72 | }
73 | };
74 |
75 | return cookieUtils;
76 | });
--------------------------------------------------------------------------------
/js/util/localStorage.js:
--------------------------------------------------------------------------------
1 | define({
2 | /**
3 | * @param {string} key
4 | * @param {*} value
5 | * @returns {*}
6 | */
7 | setItem: function (key, value) {
8 | var type = typeof value;
9 |
10 | if (type !== 'string' || type !== 'number' || type !== 'boolean' || type === null) {
11 | value = JSON.stringify(value);
12 | }
13 |
14 | localStorage.setItem(key, value);
15 |
16 | return arguments[1];
17 | },
18 |
19 | /**
20 | * @param {string} key
21 | * @returns {*}
22 | */
23 | getItem: function (key) {
24 | var value = localStorage.getItem(key),
25 | valueLength,
26 | isNeedToParse;
27 |
28 | if (value !== null) {
29 | valueLength = value.length;
30 | isNeedToParse =
31 | (value.substring(0, 1) === '[' && value.substring(valueLength - 1, valueLength) === ']') ||
32 | (value.substring(0, 1) === '{' && value.substring(valueLength - 1, valueLength) === '}');
33 |
34 | if (isNeedToParse) {
35 | value = JSON.parse(value);
36 | }
37 | }
38 |
39 | return value;
40 | },
41 |
42 | /**
43 | * @param {string} key
44 | */
45 | removeItem: function (key) {
46 | localStorage.removeItem(key);
47 | },
48 |
49 | /**
50 | * @returns {object|null}
51 | */
52 | getAllItems: function () {
53 | var key,
54 | items = {},
55 | i = 0;
56 |
57 | for (key in localStorage) {
58 | items[key] = localStorage[key];
59 | i++;
60 | }
61 |
62 | return i > 0 ? items : null;
63 | },
64 |
65 | /**
66 | * @returns void
67 | */
68 | clear: function () {
69 | localStorage.clear();
70 | }
71 | });
--------------------------------------------------------------------------------
/js/util/render.js:
--------------------------------------------------------------------------------
1 | define(function() {
2 | var util = {
3 | isObject: function (object) {
4 | return Object.prototype.toString.call(object) === '[object Object]';
5 | },
6 |
7 | isArray: function (object) {
8 | return Object.prototype.toString.call(object) === '[object Array]';
9 | },
10 |
11 | selectorPatterns: [
12 | {
13 | name: 'class',
14 | regex: new RegExp('\\.([a-zA-Z0-9-_])*')
15 | },
16 | {
17 | name: 'id',
18 | regex: new RegExp('#([a-zA-Z0-9-_])*')
19 | }
20 | ],
21 |
22 | parseSelector: function (selector) {
23 | var patterns = util.selectorPatterns,
24 | props = {},
25 | value = '';
26 |
27 | for (var i = 0, len = patterns.length; i < len; i++) {
28 | var pattern = patterns[i];
29 | var regex = pattern.regex;
30 |
31 | while (regex.test(selector)) {
32 | var matches = regex.exec(selector);
33 | selector = selector.replace(matches[0], '');
34 | value = matches[0].substring(1);
35 |
36 | if (pattern.name in props) {
37 | props[pattern.name] += ' ' + value;
38 | } else {
39 | props[pattern.name] = value;
40 | }
41 | }
42 | }
43 |
44 | if (selector !== '') {
45 | props['tag'] = selector;
46 | } else {
47 | props['tag'] = 'div';
48 | }
49 |
50 | return props;
51 | }
52 | };
53 |
54 | /**
55 | * @param {Array} data
56 | * @param {HTMLElement} target [optional]
57 | * @returns {DocumentFragment}
58 | */
59 | function render(data, target) {
60 | var context = target || document.createDocumentFragment(),
61 | dataLength = data.length,
62 | i,
63 | item, elem, props, attrName,
64 | isNull;
65 |
66 | for (i = 0; i < dataLength; i++) {
67 | item = data[i];
68 | isNull = item === null || item === undefined || item === false;
69 |
70 | if (isNull) {
71 | continue;
72 | }
73 |
74 | // text node
75 | if (typeof item === 'string' || typeof item === 'number') {
76 | context.appendChild(document.createTextNode(item));
77 | continue;
78 | }
79 |
80 | // _elem
81 | if (typeof item[0] === 'string') {
82 | props = util.parseSelector(item[0]);
83 | elem = document.createElement(props.tag);
84 |
85 | item.shift();
86 | delete props.tag;
87 |
88 | if (util.isObject(item[0])) {
89 | for (attrName in item[0]) {
90 | props[attrName] = item[0][attrName];
91 | }
92 | }
93 |
94 | for (attrName in props) {
95 | elem.setAttribute(attrName, props[attrName]);
96 | delete props[attrName];
97 | }
98 |
99 | context.appendChild(render(item, elem));
100 |
101 | continue;
102 | }
103 |
104 | // node
105 | if (item.nodeType !== undefined) {
106 | context.appendChild(item);
107 | continue;
108 | }
109 |
110 | render(item, context);
111 | }
112 |
113 | return context;
114 | }
115 |
116 | return render;
117 | });
118 |
--------------------------------------------------------------------------------
/robots.txt:
--------------------------------------------------------------------------------
1 | User-agent: *
2 | Disallow:
3 | Host: kotlinlang.org
--------------------------------------------------------------------------------