Permalink
Browse files

remove js errors

optimize js code in news and polls
  • Loading branch information...
1 parent e6171f6 commit d5566c10b6718ce2245a7215bbffa1d4441047fe @esclkm esclkm committed Jun 23, 2012
Showing with 54 additions and 97 deletions.
  1. +13 −14 modules/polls/js/polls.js
  2. +37 −46 plugins/news/js/news.admin.js
  3. +0 −9 plugins/news/news.admin.php
  4. +4 −28 plugins/news/tpl/news.admin.tpl
View
@@ -9,25 +9,24 @@ $(".deloption").live("click",function () {
}
if (ansCount<=ansMax)
{
- $("#addoption").attr('disabled', '');
+ $("#addoption").removeAttr('disabled');
+ }
+ return false;
+});
+$("#addoption").live("click",function () {
+ if (ansCount<ansMax)
+ {
+ $('.polloptiondiv').last().clone().attr("id", '').insertAfter($('.polloptiondiv').last()).show().children('.tbox').attr('value', '');
+ ansCount++;
+ }
+ if (ansCount>=ansMax)
+ {
+ $("#addoption").attr('disabled', 'disabled');
}
return false;
});
-
$(document).ready(function(){
ansCount = $('.polloptiondiv').length;
- $("#addoption").click(function () {
- if (ansCount<ansMax)
- {
- $('.polloptiondiv').last().clone().attr("id", '').insertAfter($('.polloptiondiv').last()).show().children('.tbox').attr('value', '');
- ansCount++;
- }
- if (ansCount>=ansMax)
- {
- $("#addoption").attr('disabled', 'disabled');
- }
- return false;
- });
$('#addoption').show();
$('.deloption').show();
});
@@ -4,90 +4,81 @@ function changecats()
{
var newstext = '';
var unsetcats = '';
- $('[name=maxpages]').val($('#cat_1 .cac').val());
+ num = $('#catgenerator .newscat').length;
+ $('[name=maxpages]').val($('#catgenerator .newscat').first().find('.cac').val());
- for (var i = 1; i <= num; i++)
- {
- var mycat = $('#cat_'+i+' .cay').val();
- if(i > 1)
+ $('#catgenerator .newscat').each(function(i) {
+ var mycat = $(this).find('.cay').val();
+ if(i > 0)
{
- var mycat2 = mycat.replace(/[,. -]/i, "_");
- $('#cat_'+i+' .cag').html(('{' + 'INDEX_NEWS_' + mycat2 + '}').toUpperCase());
- $('#cat_'+i+ ' .caf').html('news.' + mycat2 + '.tpl');
+ var mycat2 = mycat.replace(/[,\.\s-]/g, "_");
+ $(this).find('.cag').html(('{' + 'INDEX_NEWS_' + mycat2 + '}').toUpperCase());
+ $(this).find('.caf').html('news.' + mycat2 + '.tpl');
}
else
{
- $('#cat_'+i+' .cag').html(('{' + 'INDEX_NEWS}').toUpperCase());
- $('#cat_'+i+' .caf').html('news.tpl');
+ $(this).find('.cag').html(('{' + 'INDEX_NEWS}').toUpperCase());
+ $(this).find('.caf').html('news.tpl');
}
- if ($('#cat_'+i).length && mycat != '')
+ if ($(this).length && mycat != '')
{
if (!(newstext.indexOf(mycat) + 1))
{
newstext += mycat;
- unsetcats = '|' + $('#cat_'+i+' .cac').val();
- if ($('#cat_'+i+' .cam').val() != '' && $('#cat_'+i+' .cam').val() != '0')
+ unsetcats = '|' + $(this).find('.cac').val();
+ if ($(this).find('.cam').val() != '' && $(this).find('.cam').val() != '0')
{
- unsetcats += '|' + $('#cat_'+i+' .cam').val();
+ unsetcats += '|' + $(this).find('.cam').val();
}
newstext += unsetcats;
if (i < num) newstext += ', ';
- $('#cat_'+i+' > .cat_desc').show();
- $('#cat_'+i+' > .cat_exists').hide();
+ $(this).find('.cat_desc').show();
+ $(this).find('.cat_exists').hide();
}
else
{
- $('#cat_'+i+' > .cat_desc').hide();
- $('#cat_'+i+' > .cat_exists').show();
+ $(this).find('.cat_desc').hide();
+ $(this).find('.cat_exists').show();
}
}
- }
+ });
$('[name=category]').val(newstext);
}
$(".deloption").live("click", function () {
- $(this).parents('tr').remove();
+ $(this).closest('tr').remove();
changecats();
return false;
});
+$('#addoption').live("click", function(){
+ var object = $('.newscat').last().clone();
+ $(object).find('.deloption').show();
+ $(object).insertBefore('#addtr').show();
+ changecats();
+ return false;
+});
+
$('.cam, .cac, select').live("change", function(){
changecats();
});
$(document).ready(function(){
- num = $('.newscat').length - 1;
- $('#helptext').insertAfter('[name=maxpages]');
- $('[name=maxpages]').insertBefore('#addoption').hide();
- $('[name=category]').insertBefore('#addoption').width('100%').hide();
- $('[name=x]').insertBefore('#addoption');
- $("#cat_new").hide();
- $("#syncpag").html($('[name=syncpagination]').parent().parent().html());
- $("#cachettl").html($('[name=cache_ttl]').parent().html());
- $('#catgenerator').show().parents('form#saveconfig').html($('#catgenerator').html());
+ $('#catgenerator').show().prependTo($('form#saveconfig'));
+ $('[name=category]').closest('tr').hide();
+ $('[name=maxpages]').closest('tr').hide();
- for (var i = 1; i <= num + 1; i++)
- {
- if(i == (num + 1)) i = 'new';
+ $('#catgenerator .newscat').each(function(i) {
var input = $('[name=newsmaincat]').clone();
- newstext = $('#cat_'+i+' .cay').val();
- $(input).val(newstext).insertBefore('#cat_'+i+' .cay');
- $('#cat_'+i+' .cay').remove();
+ newstext = $(this).find('.cay').val();
+ $(input).val(newstext).insertBefore($(this).find('.cay'));
+ $(this).find('.cay').remove();
$(input).attr('name', 'cay').attr('class', 'cay');
- if(i > 1) $('#cat_'+i).find('.deloption').show();
- }
+ if(i > 1) $(this).find('.deloption').show();
+ });
$('.cay').width('200px');
changecats();
-
- $('#addoption').click(function(){
- num++;
- var object = $('#cat_new').clone().attr("id", 'cat_' + num);
- $(object).find('.deloption').show();
- $(object).insertBefore('#addtr').show();
- changecats();
- });
-
});
@@ -43,15 +43,6 @@
}
}
- $jj++;
- $tt->assign(array(
- 'ADDNUM' => 'new',
- 'ADDCATEGORY' => '',
- 'ADDCOUNT' => $cfg['plugin']['news']['maxpages'],
- 'ADDCUT' => ''
- ));
- $tt->parse('MAIN.ADDITIONAL');
-
$tt->assign(array(
'MAINCATEGORY' => cot_selectbox_categories($index, 'newsmaincat'),
'CATNUM' => $jj
@@ -1,5 +1,5 @@
<!-- BEGIN: MAIN -->
-<script src="{PHP.cfg.plugins_dir}/news/js/news.admin.js" type="text/javascript"></script>
+<script src="{PHP.cfg.plugins_dir}/news/js/news.admin.js" type="text/javascript"></script>
<div id="catgenerator" style="display:none"> <div style="display:none">{MAINCATEGORY}</div>
<table class="cells">
<tr>
@@ -11,48 +11,24 @@
<td class="coltop width10">&nbsp;</td>
</tr>
<!-- BEGIN: ADDITIONAL -->
- <tr id="cat_{ADDNUM}" class="newscat">
+ <tr class="newscat">
<td>
<input type="text" class="text cay" name="cay" value="{ADDCATEGORY}" size="32" maxlength="255" />
- <div class="cat_exists" style="color:red; display:none;"> &nbsp; {PHP.L.Newscat_exists}</div>
</td>
<td><input type="text" class="text cac" name="cac" value="{ADDCOUNT}" size="3" maxlength="255" /></td>
<td><input type="text" class="text cam" name="cam" value="{ADDCUT}" size="4" maxlength="4" /></td>
<td class="cat_desc"><span class="cag">&nbsp;</span></td>
<td class="cat_desc"><span class="caf">&nbsp;</span></td>
<td colspan="2" class="cat_exists" style="color:red; display:none;">{PHP.L.Newscat_exists}</td>
- <td><a href="#" class="deloption" style="display:none">{PHP.R.admin_icon_delete}</a></td>
+ <td><button name="deloption" class="deloption" type="button" style="display:none">{PHP.L.Delete}</button></td>
</tr>
<!-- END: ADDITIONAL -->
<tr id="addtr">
<td class="valid" colspan="6"><button name="addoption" id="addoption" type="button">{PHP.L.Add}</button></td>
</tr>
</table>
-
- <h2>{PHP.L.Settings}</h2>
- <table class="cells">
- <tr>
- <td class="coltop" style="width:75%;">{PHP.L.Parameter}</td>
- <td class="coltop" style="width:15%;">{PHP.L.Value}</td>
- <td class="coltop" style="width:10%;">{PHP.L.Reset}</td>
- </tr>
- <tr>
- <td>{PHP.L.cfg_syncpagination.0}:</td>
- <td class="centerall"><span id="syncpag"> &nbsp; </span></td>
- <td class="centerall">{PHP.R.icon_reset}</td>
- </tr>
- <tr>
- <td>{PHP.L.cfg_cache_ttl.0}:</td>
- <td class="centerall"><span id="cachettl"> &nbsp; </span></td>
- <td class="centerall">{PHP.R.icon_reset}</td>
- </tr>
- <tr>
- <td class="valid" colspan="3"><button type="submit">{PHP.L.Update}</button></td>
- </tr>
- </table>
-
<p class="small">* {PHP.L.Newsautocutdesc}</p>
- <p class="small">** {PHP.L.Template_help}</p>
+ <p class="small">** {PHP.L.Template_help}</p><br />
</div>
<!-- END: MAIN -->

0 comments on commit d5566c1

Please sign in to comment.