Это форк Vinaora Nivo Slider, пришлось переименовать, в силу требования JED. Даже старую версию качать можно было только с варезных сайтов, нашпигованную троянами. Зачем оно такое, согласитесь.
Add ModContactformMasterproMailSettings::getAllVacanciesByCity() method
diff --git a/ModContactformMasterproMailSettings.class.php b/ModContactformMasterproMailSettings.class.php
index 0b29bb6..1f6fa81 100644
--- a/ModContactformMasterproMailSettings.class.php
+++ b/ModContactformMasterproMailSettings.class.php
@@ -43,8 +43,33 @@ private $arr;
return array_keys($this->arr);
}
+ /**
+ * Returns array of all possible vacancies in all cities.
+ *
+ * @return One dimentional array.
+ */
public function getAllVacancies(){
- return array_unique(call_user_func_array('array_merge', array_map(create_function('$x', 'return array_keys($x);'), array_values($this->arr)))
+ return array_unique(
+ call_user_func_array(
+ 'array_merge'
+ ,array_map(
+ create_function('$x', 'return array_keys($x);')
+ ,array_values($this->arr)
+ )
+ )
+ );
+ }
+
+ /**
+ * Array of cities which are the arrays ov vacancies in it.
+ **/
+ public function getAllVacanciesByCity(){
+ return array_map(
+ function($a){
+ return array_keys($a);
+ }
+ , $this->arr
+ );
}
public function getMailByCityAndVacancy($city, $vacancy){
diff --git a/tmpl/default.php b/tmpl/default.php
index d8d37ce..5bcac5f 100644
--- a/tmpl/default.php
+++ b/tmpl/default.php
@@ -85,4 +85,8 @@ $oldData = $session->get('postTwergewrtgert', '', SESSION_NAMESPACE);
<div class="error" id="errorMessage"><?=$errorMessage?></div>
</form>
<?=$successMessage?>
-</div>
\ No newline at end of file
+</div>
<!DOCTYPE html>
<html>
<head>
<title>Test</title>
<script>
var users = Array('Petya','Vasya');
var admins = Array('Kolya','Seva');
function showNames(v){
var mas = eval(v);
var el = document.getElementById('names');
while(el.childNodes.length>0){
el.removeChild(el.childNodes[el.childNodes.length-1]);
}
for(var i=0;i<mas.length;i++){
var opt = document.createElement("option");
opt.innerHTML=mas[i];
el.appendChild(opt);
}
}
</script>
</head>
<body onload="showNames('admins')">
<select id="level" onchange="showNames(this.value)">
<option value="admins">ADMIN</option>
<option value="users">USER</option>
</select>
<select id="names">
</select>
</body>
</html>
<script>
<?
$lists = $mailSettings->getAllVacanciesByCity();
foreach($lists as $key => $value)
{
echo(
" var $key = Array(\n");
$string = '';
foreach($value as $lists)
$string .= ",'$lists'";
{
$string = substr($string, 1);
echo ("$string \n");
}
echo ');';
}
?>
function showNames(v){
var mas = eval(v);
var el = document.getElementById('names');
while(el.childNodes.length>0){
el.removeChild(el.childNodes[el.childNodes.length-1]);
}
for(var i=0;i<mas.length;i++){
var opt = document.createElement("option");
opt.innerHTML=mas[i];
el.appendChild(opt);
}
}
</script>
<body onload="showNames('Chicago')">
<select id="level" onchange="showNames(this.value)">
<?
foreach($mailSettings->getAllCyties() as $city){
echo "<option value='" . htmlentities(trim($city), ENT_QUOTES, "UTF-8") . "'>$city</option>";
}
?>
</select>
<select id="names">
/*! Chained 1.0.0 - MIT license - Copyright 2010-2014 Mika Tuupola */
!function(a,b){"use strict";a.fn.chained=function(c){return this.each(function(){function d(){var d=!0,g=a("option:selected",e).val();a(e).html(f.html());var h="";a(c).each(function(){var c=a("option:selected",this).val();c&&(h.length>0&&(h+=b.Zepto?"\\\\":"\\"),h+=c)});var i;i=a.isArray(c)?a(c[0]).first():a(c).first();var j=a("option:selected",i).val();a("option",e).each(function(){a(this).hasClass(h)&&a(this).val()===g?(a(this).prop("selected",!0),d=!1):a(this).hasClass(h)||a(this).hasClass(j)||""===a(this).val()||a(this).remove()}),1===a("option",e).size()&&""===a(e).val()?a(e).prop("disabled",!0):a(e).prop("disabled",!1),d&&a(e).trigger("change")}var e=this,f=a(e).clone();a(c).each(function(){a(this).bind("change",function(){d()}),a("option:selected",this).length||a("option",this).first().attr("selected","selected"),d()})})},a.fn.chainedTo=a.fn.chained,a.fn.chained.defaults={}}(window.jQuery||window.Zepto,window,document);
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//jquery.chained.min.js"></script>
<select id="town" name="town">
<option value="">--</option>
<? $lists = $mailSettings->getAllVacanciesByCity();
foreach($lists as $key => $value)
{
foreach($value as $lists)
{
echo ("<option value=" . "\"$key\"" . ">" . "$key" ."</option>");
}} ?>
</select>
<select id="vac" name="vac">
<option value="">--</option>
<? $lists = $mailSettings->getAllVacanciesByCity();
foreach($lists as $key => $value)
{
$string = '';
foreach($value as $lists)
$string .= "$lists";
{
echo ("<option value=" . "\"$string\"" . " class=" . " \"$key\"" . ">" . "$string" . "</option>");
}} ?>
</select>
<script>
$("#vac").chained("#town");
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//jquery.chained.min.js"></script>
<select id="town" name="town">
<option value="">--</option>
<?foreach($mailSettings->getAllCyties() as $city){?>
<option value="<?=htmlentities($city)?>"><?=$city?></option>
<?}
?>
</select>
<select id="vac" name="vac">
<option value="">--</option>
<?foreach($mailSettings->getAllVacanciesByCity() as $city => $vacancies){
foreach ($vacancies as $vacancy){?>
<option value="<?=htmlentities($vacancy)?>" class="<?=htmlentities($city)?>"><?=$vacancy?></option>
<?}
}?>
</select>
<script>
$("#vac").chained("#town");
</script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//f09954de.bget.ru/test/test2/jquery.chained.min.js"></script>
<select id="town" name="town">
<option value="">--</option>
<?foreach($mailSettings->getAllCyties() as $city){?>
<option value="<?=preg_replace('/[^\w\d]/iu', '_', $city)?>"><?=$city?></option>
<?}
?>
</select>
<select id="vac" name="vac">
<option value="">--</option>
<?foreach($mailSettings->getAllVacanciesByCity() as $city => $vacancies){
foreach ($vacancies as $vacancy){?>
<option value="<?=htmlentities($vacancy)?>" class="<?=preg_replace('/[^\w\d]/iu', '_', $city)?>"><?=$vacancy?></option>
<?}
}?>
</select>
<script>
$("#vac").chained("#town");
</script>
Aleksej пишет: Нам с вами поможет очень небольшой и крайне полезный скрипт, актуальную версию которого всегда можно достать на гитхабе: jquery.chained.min.js .
First you must include jQuery and Chained in your code:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script src="jquery.chained.min.js"></script>
Then lets assume you have the following HTML code:
You can now chain the #series to #mark. There are two different ways to do it. Choose yourself if you prefer more english like or shorter version. I prefer the shorter version.<select id="mark" name="mark"> <option value="">--</option> <option value="bmw">BMW</option> <option value="audi">Audi</option> </select> <select id="series" name="series"> <option value="">--</option> <option value="series-3" class="bmw">3 series</option> <option value="series-5" class="bmw">5 series</option> <option value="series-6" class="bmw">6 series</option> <option value="a3" class="audi">A3</option> <option value="a4" class="audi">A4</option> <option value="a5" class="audi">A5</option> </select>
$("#series").chained("#mark"); /* or $("#series").chainedTo("#mark"); */[/quote]
yotson пишет: если нужно чтобы по определенным выборам селектов открывалось текстовое поле?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Тест</title>
</head>
<body>
<select onchange="this.value=='мир'?document.getElementById('blablabla').style.display='':document.getElementById('blablabla').style.display='none'">
<option value=""></option>
<option value="мир">мир</option>
<option value="труд">труд</option>
<option value="май">май</option>
</select>
<div><textarea id="blablabla" rows="5" style="display:none; width:50%;"></textarea></div>
</body>
</html>
yotson пишет: а если нужно чтобы не по одному селекту из трех textarea открывалось, а по нескольким?
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Тест</title>
</head>
<body>
<select onchange="this.value.includes('р')?document.getElementById('blablabla').style.display='':document.getElementById('blablabla').style.display='none'">
<option value=""></option>
<option value="мир">мир</option>
<option value="труд">труд</option>
<option value="май">май</option>
</select>
<div><textarea id="blablabla" rows="5" style="display:none; width:50%;"></textarea></div>
</body>
</html>
<input type="checkbox" checked="checked" onclick="if(this.checked){this.nextSibling.style.display=''}else {this.nextSibling.style.display='none'; this.nextSibling.value='';}"><input type="text">
<div class="chained-selects">
<select id="select-1">
<option selected>Choose level 1 option</option>
<option>1</option>
<option>2</option>
<option>3</option>
</select>
<select id="select-2" disabled>
<option selected>Choose level 2 option</option>
</select>
<select id="select-3" disabled>
<option selected>Choose level 3 option</option>
</select>
</div>
<script>
var options = generateOptions();
document.querySelector('.chained-selects').addEventListener('change', onChange, false);
function onChange(e) {
e.stopPropagation();
var s = e.target;
if (!s.nextElementSibling)
return;
var next = s.nextElementSibling;
if (s.selectedIndex === 0)
deactivateBoxes(next);
else {
var path = [];
for (var p = s; p; p = p.previousElementSibling) {
var selOptNode = p.options[p.selectedIndex];
path.push(selOptNode.value);
}
path.reverse();
var children = path.reduce(
function(o, optName) {
return o[optName];
},
options
);
/*
if (children === null) {
children = fetch(path);
o[...] = children;
}
*/
children = Object.keys(children);
// Insert children in s.nextChild
for (var q = next.firstElementChild.nextElementSibling; q; q = nextq) {
nextq = q.nextElementSibling;
next.removeChild(q);
}
for (var i = 0; i < children.length; ++i) {
var optEl = document.createElement('option');
optEl.innerHTML = children[i];
next.appendChild(optEl);
}
next.selectedIndex = 0;
next.disabled = false;
deactivateBoxes(next.nextElementSibling);
}
}
function deactivateBoxes(s) {
while (s) {
s.selectedIndex = 0;
s.disabled = true;
s = s.nextElementSibling;
}
}
function generateOptions() {
return {
'1': {
'1-1': {
'1-1-1': null,
'1-1-2': null
},
'1-2': {
'1-2-1': null,
'1-2-2': null,
'1-2-3': null,
'1-2-4': null,
},
'1-3': {
'1-3-1': null,
'1-3-2': null,
'1-3-3': null,
'1-3-4': null,
'1-3-5': null,
}
},
'2': {
'2-1': {
'2-1-1': null,
'2-1-2': null
},
'2-2': {
'2-2-1': null,
'2-2-2': null,
'2-2-3': null,
'2-2-4': null,
},
'2-3': {
'2-3-1': null,
'2-3-2': null,
'2-3-3': null,
'2-3-4': null,
'2-3-5': null,
}
},
'3': {
'3-1': {
'3-1-1': null,
'3-1-2': null
},
'3-2': {
'3-2-1': null,
'3-2-2': null,
'3-2-3': null,
'3-2-4': null,
},
'3-3': {
'3-3-1': null,
'3-3-2': null,
'3-3-3': null,
'3-3-4': null,
'3-3-5': null,
}
}
};
}
</script>
serge пишет: www.appelsiini.net/projects/chained
<select id="mark" name="mark" class="selectpicker" multiple data-max-options="2">
<option value="">--</option>
<option value="bmw">BMW</option>
<option value="audi">Audi</option>
</select>
<select id="series" name="series" class="selectpicker" multiple data-max-options="2">
<option value="">--</option>
<option value="series-3" class="bmw">3 series</option>
<option value="series-5" class="bmw">5 series</option>
<option value="series-6" class="bmw">6 series</option>
<option value="a3" class="audi">A3</option>
<option value="a4" class="audi">A4</option>
<option value="a5" class="audi">A5</option>
</select>
*! Chained 1.0.0 - MIT license - Copyright 2010-2014 Mika Tuupola */
!function (a, b) {
"use strict";
a.fn.chained = function (c) {
return this.each(function () {
function d() {
var d = !0;
a(e).html(f.html());
var h = a("option:selected", this).parent().val();
var arr = h.toString().split(",");
a("option", e).each(function () {
var current_class = a(this).attr("class");
if(h != current_class && $.inArray(current_class, arr) < 0){
a(this).remove()
}
});
if (1 === a("option", e).size() && "" === a(e).val()) {
a(e).prop("disabled", !0)
} else {
a(e).prop("disabled", !1)
}
d && a(e).trigger("change")
}
var e = this, f = a(e).clone();
a(c).each(function () {
a(this).bind("change", function () {
d()
}), a("option:selected", this).length || a("option", this).first().attr("selected", "selected"), d()
})
})
}, a.fn.chainedTo = a.fn.chained, a.fn.chained.defaults = {}
}(window.jQuery || window.Zepto, window, document);
$('selectpicker').selectpicker();
$('select').on('change', function() {
$(this).selectpicker('refresh');
});
$("#series").chained("#mark");