Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Помогите сократить код! (https://javascript.ru/forum/misc/53145-pomogite-sokratit-kod.html)

tarkasha 22.01.2015 16:42

Помогите сократить код!
 
<input type="button" value="На весь экран" class="button1-check-act" onclick="full('swf-zoom');fullbackgraund('litebox-full');fulloverflow('bd');fullbuttoff('toolbar-litebox')" ></input>

<script type="text/javascript">
			// На весь экран
			function full(nodeId) {
			 var node = document.getElementById(nodeId);
			if (node){window.scrollTo(0,0);node.style.margin = 'auto';node.style.zIndex	= '50';node.style.height = '85%';node.style.width = '85%';node.style.left = '32.5%';node.style.marginLeft	= '-25%';node.style.top	= '8%';	node.style.transition = 'all .218s ease 0s';} 
			}
			function fullpositionFIXED(nodeId) {
			 var node = document.getElementById(nodeId);
			if (node){node.style.display = 'block';	} 
			}
			function fullbackgraund(nodeId) {
			 var node = document.getElementById(nodeId);
			if (node){node.style.display = 'block';	} 
			}
			function fulloverflow(nodeId) {
			 var node = document.getElementById(nodeId);
			if (node){node.style.overflow = 'hidden';	} 
			}
			function fullbuttoff(nodeId) {
			 var node = document.getElementById(nodeId);
			if (node){node.style.display = 'block';	} 
			}

danik.js 22.01.2015 16:51

Воспользуйся онлайн-обфускатором кода.
А если серьезно - проще переписать чем копаться в этом дерьме. Че кнопка должна делать-то?

skrudjmakdak 22.01.2015 16:56

node.style.margin = 'auto';node.style.zIndex = '50';node.style.height = '85%';node.style.width = '85%';node.style.left = '32.5%';node.style.marginLeft   = '-25%';node.style.top = '8%'; node.style.transition = 'all .218s ease 0s';}

напиши класс в цсс, например так:
.myclass {
margin: auto;
z-index: 50;
...
}

и присваивай своему элементу этот класс, можно для начала так:
node.setAttribute('class', 'myclass');

tarkasha 22.01.2015 17:12

Цитата:

Сообщение от danik.js (Сообщение 352814)
Воспользуйся онлайн-обфускатором кода.
А если серьезно - проще переписать чем копаться в этом дерьме. Че кнопка должна делать-то?

При нажатии на кнопку скрипт должен менять значения в классах CSS

skrudjmakdak 23.01.2015 09:39

вот те рабочий пример, изучай:
<html>
    <head>
        <title>example</title>
		<style>
.cl {
	width: 100px;
	height: 30px;
	border: 1px solid silver;
}
		
.cl-one {
	background-color: red;
	font-weight: bold;
}

.cl-two {
	background-color: black;
	color: green;
	border-radius: 5px;
	font-style: italic;
}
		</style>
    </head>
    <body>
		<div class="cl" onclick="updateClass(this, 'cl-one');">123</div>
		<div class="cl" onclick="updateClass(this, 'cl-two');">345</div>
		<script>
function updateClass (ths, nameCl) {
	var listCl = ths.getAttribute('class').split(' '),
		index = listCl.indexOf(nameCl);
		
	if (index == -1) {
		listCl.push(nameCl);
	} else {
		listCl.splice(index, 1);
	}
	
	ths.setAttribute('class', listCl.join(' '));
}
	</script>
	</body>
  
</html>

danik.js 23.01.2015 10:21

skrudjmakdak, про .className не слышал? А вообще:
<html>
    <head>
        <title>example</title>
        <style>
.cl {
    width: 100px;
    height: 30px;
    border: 1px solid silver;
}
         
.cl-one {
    background-color: red;
    font-weight: bold;
}
 
.cl-two {
    background-color: black;
    color: green;
    border-radius: 5px;
    font-style: italic;
}
        </style>
    </head>
    <body>
        <div class="cl" onclick="classList.toggle('cl-one');">123</div>
        <div class="cl" onclick="classList.toggle('cl-two');">345</div>
    </body>
   
</html>

Кроссбраузерность? classList.js в помощь.


Часовой пояс GMT +3, время: 16:17.