Skip to content
This repository has been archived by the owner on Nov 14, 2018. It is now read-only.

Commit

Permalink
Рефакторинг
Browse files Browse the repository at this point in the history
  • Loading branch information
lossir authored and lossir committed Aug 20, 2015
1 parent 22bf39e commit 6d56a9b
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 38 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
jL/old/*
.idea
.idea
jquery-1.11.2.js
es5-shim.map
html5forIE.min.js
11 changes: 11 additions & 0 deletions jL.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
//Time: 10:51
//TODO: Написать "перехватчик" ajax запросов, для отслеживания появления новых элементов

//Date: 20.08.2015
//Time: 13:38
//TODO: Необходимо подробно просмотреть реализацию мелких, но важных функций для ie8\9

(function ($) {
"use strict";
Expand Down Expand Up @@ -56,6 +59,14 @@
expansionDefineProperty(Array.prototype, 'diff', function(a) {
return this.filter(function(i) {return a.indexOf(i) < 0;});
});
expansionDefineProperty(window.Element.prototype, 'getElementsByClassName', function (className) {
return Array.prototype.filter.call(this.getElementsByTagName("*"), function (item) {
return !~item.className.split(" ").indexOf(className);
});
});
expansionDefineProperty(window.Element.prototype, 'addEventListener', function () {
//console.log(this,arguments);
});
expansionDefineProperty(Array.prototype, 'forEach', function (func) {
func = func || false;
var key,
Expand Down
17 changes: 14 additions & 3 deletions utilities/class-action/example.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
<!doctype html>
<html lang="ru">
<!--[if lt IE 7]><html class="ie ie6" lang="ru"><![endif]-->
<!--[if IE 7]><html class="ie ie7" lang="ru"><![endif]-->
<!--[if IE 8]><html class="ie ie8" lang="ru"><![endif]-->
<!--[if IE 9]><html class="ie ie9" lang="ru"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html lang="ru"><!--<![endif]-->
<head>


<meta http-equiv="X-UA-Compatible" content="IE=Edge;chrome=1">
<meta http-equiv="content-language" content="ru"/>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">

<link rel="stylesheet" href="/cutback.css"/>
<link rel="stylesheet" href="style.css"/>

<script src="//code.jquery.com/jquery-2.1.1.min.js"></script>
<!--[if lt IE 9]><script src="/html5forIE.min.js"></script><![endif]-->

<script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
<!--<script src="//code.jquery.com/jquery-1.9.1.min.js"></script>-->
<!--<script src="/js/jquery-1.11.2.min.js"></script>-->
<script src="/jL.js"></script>
Expand All @@ -27,6 +35,9 @@
.selected {
box-shadow: inset 0 0 0 1px red;
}
.ie8 .selected {
border: solid 1px red;
}

.disabled {
opacity: 0.4;
Expand Down Expand Up @@ -80,7 +91,7 @@
<li class="cu-p">2</li>
<li class="cu-p">3</li>
<li class="cu-p">4</li>
<li class="cu-p">5</li>
<li class="cu-p selected">5</li>
<li class="cu-p">6</li>
<li class="cu-p">7</li>
<li class="cu-p">8</li>
Expand Down
69 changes: 35 additions & 34 deletions utilities/class-action/jL.utility.class-action.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,39 +163,39 @@
}
},
{
'className' : 'placeholder',
'className' : '.ie9[placeholder]',
/**
*/
'action': function () {
var elems = $(this);
jL.IEBind.add('8,9', function(){
elems.each(function () {
var $this = $(this),
placeholder = $this.attr('placeholder'),
tag = $this.prop('tagName'),
color = $this.prop('color'),
method = (tag === 'INPUT') ? 'val'
: 'text',
placeholderShow = function () {
if($this[method]() === placeholder){
$this.css('color', color);
$this[method]('');
}
},
placeholderHide = function () {
var value = $this[method]();
$this[method](value === placeholder || value === '' ? function () {
$this.css('color', '#aaaaaa');
return placeholder;
}()
: value);
};
$this.on( "focus", placeholderShow);
$this.on( "blur", placeholderHide);
placeholderHide();
//jL.IEBind.add('8,9', function(){
elems.each(function () {
var $this = $(this),
placeholder = $this.attr('placeholder'),
tag = $this.prop('tagName'),
color = $this.prop('color'),
method = (tag === 'INPUT') ? 'val'
: 'text',
placeholderShow = function () {
if($this[method]() === placeholder){
$this.css('color', color);
$this[method]('');
}
},
placeholderHide = function () {
var value = $this[method]();
$this[method](value === placeholder || value === '' ? function () {
$this.css('color', '#aaaaaa');
return placeholder;
}()
: value);
};
$this.on( "focus", placeholderShow);
$this.on( "blur", placeholderHide);
placeholderHide();
// $this[method](placeholder);
});
});
//});
}
},
{
Expand Down Expand Up @@ -229,7 +229,7 @@
}
},
{
'className' : 'select-css',
'className' : '.ca-select-css',
/**
* <pre>
* Создание стилизованного тега select
Expand Down Expand Up @@ -322,20 +322,21 @@
}
},
{
'className' : 'switch,switch-block',
'className' : '.ca-switch, .ca-switch-block',
/**
* Переключение класса "selected" между набором элементов
*/
'action': function () {
var $this = $(this),
var self = this,
$this = $(this),
switchClass = 'selected',
items = this.children,
$items = $(items);
// элементы могут переключать класс "selected" внутри своего набора
if($this.hasClass('ca-switch')) {
$this.on('click', '>*', function (index) {
$(document).on("click", ">*", function (e) {
$items.removeClass(switchClass);
this.className += " "+switchClass;
event.srcElement.className += " "+switchClass;
});
}
// или в другом наборе элементов
Expand All @@ -357,7 +358,7 @@
}
},
{
'className' : 'popup-image',
'className' : '.ca-popup-image',
'action': function () {

}
Expand All @@ -366,7 +367,7 @@

$(function(){
actions.forEach(function(item){
$(getSelector(item.className,',')).each(item.action);
$(item.className).each(item.action);
});
});

Expand Down

0 comments on commit 6d56a9b

Please sign in to comment.