Plugin Directory

Changeset 960469


Ignore:
Timestamp:
08/05/2014 01:37:54 PM (12 years ago)
Author:
shunk
Message:

Bug fix: undo

Location:
wp-table-tag-gen/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • wp-table-tag-gen/trunk/css/style.dev.css

    r957466 r960469  
    7070    display: block;
    7171}
    72 
    7372
    7473#generator .help {
  • wp-table-tag-gen/trunk/js/wp-table-tag-gen.dev.js

    r960042 r960469  
    149149});
    150150
    151 if ( window.localStorage ) {
    152     localStorage.clear();
    153     localStorage.setItem( 'index', 0 );
    154     localStorage.setItem( 'undo', 0 );
    155 } else {
     151if ( ! window.localStorage ) {
    156152    $( '#undo, #redo, #initialize' ).hide();
    157153}
  • wp-table-tag-gen/trunk/js/wp-table-tag-gen.js

    r960042 r960469  
    2727 */
    2828jQuery(function(a){function b(){var b=.9*a(window).width(),c=.9*a(window).height();a("#TB_window").css({width:b+"px","margin-left":.5*-b+"px"}),a("#TB_ajaxContent").css({padding:"0",width:b+"px",height:c+"px"})}var c="WP Table Tag Gen";window.QTags&&(QTags.addButton("ttg","table",function(){tb_show(c,"#TB_inline?height=&width=&inlineId=wp-table-tag-gen",!1),b(),a(window).resize(function(){a("#TB_ajaxWindowTitle").text()===c&&b()})},!1,!1,"Insert a table tag from WP Table Tag Gen.",116),window.localStorage&&(localStorage.clear(),localStorage.setItem("index",0),localStorage.setItem("undo",0),localStorage.setItem("o0",JSON.stringify({row:a("[name=row]").val(),col:a("[name=col]").val()})),localStorage.setItem("data0",a("#tag-wrapper").html()),a("#undo").attr("disabled","disabled"),a("#redo").attr("disabled","disabled")))});
    29 jQuery(function(a){function b(a){return new RegExp(a,"i").test(navigator.userAgent)}function c(b,c){m.find("table").empty();var d,e,f;for(d=0;b>d;d++){for(f=a("<tr />"),e=0;c>e;e++)a("<td />").appendTo(f);f.appendTo(m.find("table"))}}function d(b,d){var f;return 0>d?(f=a(this).val(),a(this).val(++f),c(p.val(),q.val()),g(e())):d>0&&(f=a(this).val(),--f,f>0&&(a(this).val(f),c(p.val(),q.val()),g(e()))),i(),!1}function e(){if(window.localStorage){var a=localStorage.getItem("index"),b=localStorage.getItem("undo"),c=m.html(),d={row:p.val(),col:q.val()};return a==b?(a++,localStorage.setItem("data"+a,c),localStorage.setItem("o"+a,JSON.stringify(d)),localStorage.setItem("index",a),localStorage.setItem("undo",a)):a>b&&(b++,localStorage.setItem("data"+b,c),localStorage.setItem("o"+b,JSON.stringify(d)),localStorage.setItem("index",b),localStorage.setItem("undo",b)),f(),c}}function f(){if(window.localStorage){var b=Number(localStorage.getItem("index")),c=Number(localStorage.getItem("undo"));b==c?0==c?(a("#undo").attr("disabled","disabled"),a("#redo").attr("disabled","disabled")):(a("#undo").removeAttr("disabled"),a("#redo").attr("disabled","disabled")):0==c?(a("#undo").attr("disabled","disabled"),a("#redo").removeAttr("disabled")):(a("#undo").removeAttr("disabled"),a("#redo").removeAttr("disabled"))}}function g(c){var d;d=c?c:m.html(),d=d.toLowerCase().replace(/<\/table>/g,"\n</table>").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/ui-selecte(d\s|d)/g,"").replace(/ui-selecte(e\s|e)/g,"").replace(/ttg-merged/g,"").replace(/ class=\"\"/g,"").replace(/ class=\" \"/g,"").replace(/ style=\".*?\"/g,"").replace(/<tb.*?>/g,"\n<tbody>").replace(/<\/tbo.*?>/g,"\n</tbody>").replace(/<tr/g,"\n<tr").replace(/<\/tr/g,"\n</tr").replace(/<td/g,"\n<td").replace(/<th/g,"\n<th"),b("msie|trident")&&(d=d.replace(/ class=>/g,">").replace(/^\n/g,"")),a("[name=source]").val("").val(d)}function h(){a(".ui-selected."+t).each(function(){var b=Number(a(this).attr("rowspan")),c=Number(a(this).attr("colspan"));for(isNaN(c)&&(c=1),a(this).removeAttr("rowspan"),a(this).removeAttr("colspan"),e=1;c>e;e++){if(a(this).get(0).tagName.match(/td/i))var d=a("<td>");else a(this).get(0).tagName.match(/th/i)&&(d=a("<th>"));d.addClass("ui-selected"),d.insertAfter(a(this))}var e,f,g,h=a(this).parent("tr"),i=a("tr").index(h),j=i+1,k=(Number(q.val()),a(this).parent().children().index(a(this))-1);for(e=j;j+b-1>e;e++)for(g=a("tr:eq("+e+")").children(),f=0;c>f;f++)a(this).get(0).tagName.match(/td/i)?d=a("<td>"):a(this).get(0).tagName.match(/th/i)&&(d=a("<th>")),d.addClass("ui-selected"),-1==k?d.insertBefore(g[0]):d.insertAfter(g[k]?g[k]:g[g.length-1]);a(this).removeClass(t)})}function i(){m.find("input").remove(),a("#stripe-label").remove()}function j(b){var b=b||".default";clearTimeout(k),a("#generator .message p").hide(),a(b).show(),a(b).hasClass("alert")&&(k=setTimeout(function(){a(b).fadeOut("normal",function(){a(".default").fadeIn()})},5e3))}var k,l="#tag-wrapper",m=a(l),n=m.find("table"),o=a("#ttg-header"),p=o.find("[name=row]"),q=o.find("[name=col]"),r=o.find("[name=row], [name=col]"),s=o.find(".button"),t="TTG-merged";c(p.val(),q.val()),g(),a("#class, #chars").show(),a("#output-chars, #output-class").hide(),a.cookie("checked",""),s.not("#undo, #redo").removeAttr("disabled"),m.mousedown(function(a){a.metaKey=!1}).selectable(),r.mouseup(function(){c(p.val(),q.val()),g(e())}).mousewheel(d),r.keyup(function(){var b=1*a(this).val();return/[0-9]/.test(b)===!1?void j("#ent-num"):1>b?void j("#ent-natural-num"):(c(p.val(),q.val()),void g(e()))}),window.localStorage?(localStorage.clear(),localStorage.setItem("index",0),localStorage.setItem("undo",0)):a("#undo, #redo, #initialize").hide(),a("#output-chars").click(function(){j(),s.not("#undo, #redo").removeAttr("disabled"),a("#chars").show(),a(this).hide(),r.mousewheel(d),m.find("td, th").each(function(){content=a(this).children("textarea").val(),a(this).children("textarea").remove(),a(this).text(content)}),g(e())}),a("#output-class").click(function(){j(),s.not("#undo, #redo").removeAttr("disabled"),a("#class").show(),a(this).hide(),r.mousewheel(d),m.find("td, th").each(function(){var b=a(this).children("input").val();a(this).children("input").remove(),a(this).addClass(b).removeClass("class")});var b=a(".table-class").val();n.removeAttr("class"),b&&n.addClass(b);var c=[];a(".tr-class").each(function(b){c[b]=a(this).val()}),m.find("tr").each(function(b){a(this).removeAttr("class"),void 0!=c[b]&&a(this).addClass(c[b])}),i(),g(e())}),a("#chars").click(function(){j("#ent-chars"),a(".ui-selected").removeClass("ui-selected"),s.not("#output-chars").attr("disabled","disabled"),a(this).hide(),a("#output-chars").show(),r.unbind("mousewheel"),m.find("td, th").each(function(){var b=a(this).text();a(this).html('<textarea rows="2" name="textarea">'+b+"</textarea> ")}),b("webkit")&&m.find("td:has( input ), th:has( input )").css("padding","1px 3px 2px")}),a(document).on({focus:function(){var b=a(this).parents("tr");b.find("textarea").attr("rows","4"),b.prevAll().find("textarea").attr("rows","2"),b.nextAll().find("textarea").attr("rows","2")},blur:function(){n.find("textarea").attr("rows","2")}},"[name=textarea]"),a("#class").click(function(){j("#ent-class-names"),s.not("#output-class").attr("disabled","disabled"),a(this).hide(),a("#output-class").show(),r.unbind("mousewheel"),m.find("td, th").each(function(){a(this).removeClass("ui-selectee ui-selected "+t);var b=a(this).attr("class");void 0==b&&(b=""),a('<input type="text" value="'+b+'" size="5">').appendTo(this),a(this).children().addClass("class")});var c=-30;b("webkit")&&(c=-33,m.find("td:has( input ), th:has( input )").css("padding","3px"));var d=n.find("tr:first").position().left,e=n.attr("class");void 0!=e&&(e=e.replace(/ui-selecte(d\s|d)/g,"").replace(/ui-selecte(e\s|e)/g,"")),e||(e=""),a("<input />").val(e).attr({type:"text",size:"5",placeholder:"table","class":"table-class"}).css({position:"absolute",top:c+"px",left:d+4+"px"}).appendTo(l),a("<label />").attr("id","stripe-label").css({position:"absolute",top:c+5+"px",left:d-69+"px"}).appendTo(l),a("<input />").attr({type:"checkbox",id:"stripe"}).appendTo("#stripe-label").after("<span>stripe</span>"),m.find("tr").each(function(){c=b("firefox")?a(this).position().top+3:b("webkit")?a(this).position().top+4:b("meie|trident")?a(this).position().top+6:a(this).position().top+3;var d=a(this).position().left,e=a(this).attr("class");void 0!=e&&(e=e.replace(/ui-selecte(d\s|d)/g,"").replace(/ui-selecte(e\s|e)/g,"")),e||(e=""),a("<input />").val(e).attr({type:"text",size:"5",placeholder:"tr","class":"tr-class"}).css({position:"absolute",top:c+"px",left:d-75+"px"}).appendTo(l)}),a("#stripe").removeAttr("checked");var f=a.cookie("checked");1==f&&a("#stripe").attr("checked","checked");var g=[];a("#stripe-label").click(function(){a("#stripe").is(":checked")?(a.cookie("checked",1),a(".tr-class").each(function(b){g[b]=a(this).val();var c=a(this).val();a(this).val(b%2==0?"even"+(""!=c?" "+c:""):"odd"+(""!=c?" "+c:""))})):(a.cookie("checked",""),a(".tr-class").each(function(b){g[b]=a(this).val(),void 0!=g[b]?(g[b]=g[b].replace(/eve(n\s|n)/g,"").replace(/od(d\s|d)/g,""),a(this).val(g[b])):a(this).val("")}))})}),a(window).resize(function(){var c=-30;b("webkit")&&(c=-33);var d=n.find("tr:first").position().left;a(".table-class").css({position:"absolute",top:c+"px",left:d+4+"px"}),a("#stripe-label").css({position:"absolute",top:c+5+"px",left:d-69+"px"}),c=[],d=0,m.find("tr").each(function(e){b("firefox")?c[e]=a(this).position().top+3:b("webkit")&&(c[e]=a(this).position().top+4),d=a(this).position().left}),a(".tr-class").each(function(b){a(this).css({position:"absolute",top:c[b]+"px",left:d-75+"px"})})}),a("#merge").click(function(){var b=null,c=null,d=m.find("td.ui-selected, th.ui-selected");if(0===d.length)return void j("#select-cells");if(d.each(function(){a(this).get(0).tagName.match(/td/i)?b=!0:a(this).get(0).tagName.match(/th/i)&&(c=!0)}),1==b&&1==c)return j("#cant-merge"),!1;if(1==b&&null==c)var f="td";else null==b&&1==c&&(f="th");a(f+".ui-selected").each(function(){return a(this).hasClass(t)?(a(".ui-selected").removeClass("ui-selected"),j("#cant-remerge"),!1):void 0});var h=p.val(),i=q.val(),k=a(f+".ui-selected").parent("tr").addClass("ui-selected").length,l=a(f+".ui-selected").length/k;if(h==k&&i==l)n.html("<tr><"+f+"></"+f+"></tr>");else{h!=k&&i==l?k>1&&(a("tr.ui-selected:not( tr.ui-selected:first )").remove(),k=1):h==k&&i!=l&&l>1&&(m.find("tr.ui-selected").each(function(){a(this).children(f+".ui-selected:not( .ui-selected:first )").remove()}),l=1);var o=(a("tr").index(a("tr.ui-selected:first")),a(f).index(a(f+".ui-selected:first")));if(i>o);else;a("tr.ui-selected").each(function(b){0==b?l>1&&a(this).children(f+".ui-selected:not(.ui-selected:first)").remove():a(this).children(f+".ui-selected").remove()}),l>1&&a(f+".ui-selected:first").attr("colspan",l).addClass(t),k>1&&a(f+".ui-selected:first").attr("rowspan",k).addClass(t);var r=a("tr:empty").length;r>0&&(m.find("[rowspan]").each(function(){var b=a(this).attr("rowspan")-r;a(this).attr("rowspan",b),1==a(this).attr("rowspan")&&a(this).removeAttr("rowspan")}),m.find("tr:empty").remove(),h-=r),a("."+t).each(function(){void 0===a(this).attr("rowspan")&&void 0===a(this).attr("colspan")&&a(this).removeClass(t)})}g(e())}),a("#replace").click(function(){var b=m.find("td.ui-selected, th.ui-selected");return 0===b.length?void j("#select-cells"):(b.each(function(){var b=a(this).text(),c=a(this).attr("colspan"),d=a(this).attr("rowspan"),e=a(this).attr("class"),f=a("td"==a(this).get(0).tagName.toLowerCase()?"<th>":"<td>");a(this).replaceWith(function(){return f.text(b),c&&f.attr("colspan",c),d&&f.attr("rowspan",d),e&&f.addClass(e).removeClass("ui-selected"),f})}),void g(e()))}),a("#split").click(function(){var a=m.find("td.ui-selected, th.ui-selected");return 0===a.length?void j("#select-cells"):(h(),void g(e()))}),a("#undo").click(function(){if(window.localStorage){var a=localStorage.getItem("undo");a--;var b=JSON.parse(localStorage.getItem("o"+a));p.val(b.row),q.val(b.col);var c=localStorage.getItem("data"+a);m.empty().html(c),localStorage.setItem("undo",a),g(c),f(),i()}}),a("#redo").click(function(){if(window.localStorage){var a=(localStorage.getItem("index"),localStorage.getItem("undo"));a++;var b=JSON.parse(localStorage.getItem("o"+a));p.val(b.row),q.val(b.col);var c=localStorage.getItem("data"+a);m.empty().html(c),localStorage.setItem("undo",a),g(c),f(),i()}}),a("#initialize").click(function(){c(p.val(),q.val()),g(),window.localStorage&&(localStorage.clear(),localStorage.setItem("index",0),localStorage.setItem("undo",0),localStorage.setItem("o0",JSON.stringify({row:p.val(),col:q.val()})),localStorage.setItem("data0",m.html())),i(),f()}),a("#insert").click(function(){var b=a("[name=source]","#generator").val();a("#content").insertAtCaret(b),tb_remove()}),a.fn.extend({insertAtCaret:function(a){var b=this.get(0);b.focus();var c=b.value,d=b.selectionStart,e=d+a.length;b.value=c.substr(0,d)+a+c.substr(d),b.setSelectionRange(e,e)}})});
     29jQuery(function(a){function b(a){return new RegExp(a,"i").test(navigator.userAgent)}function c(b,c){m.find("table").empty();var d,e,f;for(d=0;b>d;d++){for(f=a("<tr />"),e=0;c>e;e++)a("<td />").appendTo(f);f.appendTo(m.find("table"))}}function d(b,d){var f;return 0>d?(f=a(this).val(),a(this).val(++f),c(p.val(),q.val()),g(e())):d>0&&(f=a(this).val(),--f,f>0&&(a(this).val(f),c(p.val(),q.val()),g(e()))),i(),!1}function e(){if(window.localStorage){var a=localStorage.getItem("index"),b=localStorage.getItem("undo"),c=m.html(),d={row:p.val(),col:q.val()};return a==b?(a++,localStorage.setItem("data"+a,c),localStorage.setItem("o"+a,JSON.stringify(d)),localStorage.setItem("index",a),localStorage.setItem("undo",a)):a>b&&(b++,localStorage.setItem("data"+b,c),localStorage.setItem("o"+b,JSON.stringify(d)),localStorage.setItem("index",b),localStorage.setItem("undo",b)),f(),c}}function f(){if(window.localStorage){var b=Number(localStorage.getItem("index")),c=Number(localStorage.getItem("undo"));b==c?0==c?(a("#undo").attr("disabled","disabled"),a("#redo").attr("disabled","disabled")):(a("#undo").removeAttr("disabled"),a("#redo").attr("disabled","disabled")):0==c?(a("#undo").attr("disabled","disabled"),a("#redo").removeAttr("disabled")):(a("#undo").removeAttr("disabled"),a("#redo").removeAttr("disabled"))}}function g(c){var d;d=c?c:m.html(),d=d.toLowerCase().replace(/<\/table>/g,"\n</table>").replace(/&lt;/g,"<").replace(/&gt;/g,">").replace(/ui-selecte(d\s|d)/g,"").replace(/ui-selecte(e\s|e)/g,"").replace(/ttg-merged/g,"").replace(/ class=\"\"/g,"").replace(/ class=\" \"/g,"").replace(/ style=\".*?\"/g,"").replace(/<tb.*?>/g,"\n<tbody>").replace(/<\/tbo.*?>/g,"\n</tbody>").replace(/<tr/g,"\n<tr").replace(/<\/tr/g,"\n</tr").replace(/<td/g,"\n<td").replace(/<th/g,"\n<th"),b("msie|trident")&&(d=d.replace(/ class=>/g,">").replace(/^\n/g,"")),a("[name=source]").val("").val(d)}function h(){a(".ui-selected."+t).each(function(){var b=Number(a(this).attr("rowspan")),c=Number(a(this).attr("colspan"));for(isNaN(c)&&(c=1),a(this).removeAttr("rowspan"),a(this).removeAttr("colspan"),e=1;c>e;e++){if(a(this).get(0).tagName.match(/td/i))var d=a("<td>");else a(this).get(0).tagName.match(/th/i)&&(d=a("<th>"));d.addClass("ui-selected"),d.insertAfter(a(this))}var e,f,g,h=a(this).parent("tr"),i=a("tr").index(h),j=i+1,k=(Number(q.val()),a(this).parent().children().index(a(this))-1);for(e=j;j+b-1>e;e++)for(g=a("tr:eq("+e+")").children(),f=0;c>f;f++)a(this).get(0).tagName.match(/td/i)?d=a("<td>"):a(this).get(0).tagName.match(/th/i)&&(d=a("<th>")),d.addClass("ui-selected"),-1==k?d.insertBefore(g[0]):d.insertAfter(g[k]?g[k]:g[g.length-1]);a(this).removeClass(t)})}function i(){m.find("input").remove(),a("#stripe-label").remove()}function j(b){var b=b||".default";clearTimeout(k),a("#generator .message p").hide(),a(b).show(),a(b).hasClass("alert")&&(k=setTimeout(function(){a(b).fadeOut("normal",function(){a(".default").fadeIn()})},5e3))}var k,l="#tag-wrapper",m=a(l),n=m.find("table"),o=a("#ttg-header"),p=o.find("[name=row]"),q=o.find("[name=col]"),r=o.find("[name=row], [name=col]"),s=o.find(".button"),t="TTG-merged";c(p.val(),q.val()),g(),a("#class, #chars").show(),a("#output-chars, #output-class").hide(),a.cookie("checked",""),s.not("#undo, #redo").removeAttr("disabled"),m.mousedown(function(a){a.metaKey=!1}).selectable(),r.mouseup(function(){c(p.val(),q.val()),g(e())}).mousewheel(d),r.keyup(function(){var b=1*a(this).val();return/[0-9]/.test(b)===!1?void j("#ent-num"):1>b?void j("#ent-natural-num"):(c(p.val(),q.val()),void g(e()))}),window.localStorage||a("#undo, #redo, #initialize").hide(),a("#output-chars").click(function(){j(),s.not("#undo, #redo").removeAttr("disabled"),a("#chars").show(),a(this).hide(),r.mousewheel(d),m.find("td, th").each(function(){content=a(this).children("textarea").val(),a(this).children("textarea").remove(),a(this).text(content)}),g(e())}),a("#output-class").click(function(){j(),s.not("#undo, #redo").removeAttr("disabled"),a("#class").show(),a(this).hide(),r.mousewheel(d),m.find("td, th").each(function(){var b=a(this).children("input").val();a(this).children("input").remove(),a(this).addClass(b).removeClass("class")});var b=a(".table-class").val();n.removeAttr("class"),b&&n.addClass(b);var c=[];a(".tr-class").each(function(b){c[b]=a(this).val()}),m.find("tr").each(function(b){a(this).removeAttr("class"),void 0!=c[b]&&a(this).addClass(c[b])}),i(),g(e())}),a("#chars").click(function(){j("#ent-chars"),a(".ui-selected").removeClass("ui-selected"),s.not("#output-chars").attr("disabled","disabled"),a(this).hide(),a("#output-chars").show(),r.unbind("mousewheel"),m.find("td, th").each(function(){var b=a(this).text();a(this).html('<textarea rows="2" name="textarea">'+b+"</textarea> ")}),b("webkit")&&m.find("td:has( input ), th:has( input )").css("padding","1px 3px 2px")}),a(document).on({focus:function(){var b=a(this).parents("tr");b.find("textarea").attr("rows","4"),b.prevAll().find("textarea").attr("rows","2"),b.nextAll().find("textarea").attr("rows","2")},blur:function(){n.find("textarea").attr("rows","2")}},"[name=textarea]"),a("#class").click(function(){j("#ent-class-names"),s.not("#output-class").attr("disabled","disabled"),a(this).hide(),a("#output-class").show(),r.unbind("mousewheel"),m.find("td, th").each(function(){a(this).removeClass("ui-selectee ui-selected "+t);var b=a(this).attr("class");void 0==b&&(b=""),a('<input type="text" value="'+b+'" size="5">').appendTo(this),a(this).children().addClass("class")});var c=-30;b("webkit")&&(c=-33,m.find("td:has( input ), th:has( input )").css("padding","3px"));var d=n.find("tr:first").position().left,e=n.attr("class");void 0!=e&&(e=e.replace(/ui-selecte(d\s|d)/g,"").replace(/ui-selecte(e\s|e)/g,"")),e||(e=""),a("<input />").val(e).attr({type:"text",size:"5",placeholder:"table","class":"table-class"}).css({position:"absolute",top:c+"px",left:d+4+"px"}).appendTo(l),a("<label />").attr("id","stripe-label").css({position:"absolute",top:c+5+"px",left:d-69+"px"}).appendTo(l),a("<input />").attr({type:"checkbox",id:"stripe"}).appendTo("#stripe-label").after("<span>stripe</span>"),m.find("tr").each(function(){c=b("firefox")?a(this).position().top+3:b("webkit")?a(this).position().top+4:b("meie|trident")?a(this).position().top+6:a(this).position().top+3;var d=a(this).position().left,e=a(this).attr("class");void 0!=e&&(e=e.replace(/ui-selecte(d\s|d)/g,"").replace(/ui-selecte(e\s|e)/g,"")),e||(e=""),a("<input />").val(e).attr({type:"text",size:"5",placeholder:"tr","class":"tr-class"}).css({position:"absolute",top:c+"px",left:d-75+"px"}).appendTo(l)}),a("#stripe").removeAttr("checked");var f=a.cookie("checked");1==f&&a("#stripe").attr("checked","checked");var g=[];a("#stripe-label").click(function(){a("#stripe").is(":checked")?(a.cookie("checked",1),a(".tr-class").each(function(b){g[b]=a(this).val();var c=a(this).val();a(this).val(b%2==0?"even"+(""!=c?" "+c:""):"odd"+(""!=c?" "+c:""))})):(a.cookie("checked",""),a(".tr-class").each(function(b){g[b]=a(this).val(),void 0!=g[b]?(g[b]=g[b].replace(/eve(n\s|n)/g,"").replace(/od(d\s|d)/g,""),a(this).val(g[b])):a(this).val("")}))})}),a(window).resize(function(){var c=-30;b("webkit")&&(c=-33);var d=n.find("tr:first").position().left;a(".table-class").css({position:"absolute",top:c+"px",left:d+4+"px"}),a("#stripe-label").css({position:"absolute",top:c+5+"px",left:d-69+"px"}),c=[],d=0,m.find("tr").each(function(e){b("firefox")?c[e]=a(this).position().top+3:b("webkit")&&(c[e]=a(this).position().top+4),d=a(this).position().left}),a(".tr-class").each(function(b){a(this).css({position:"absolute",top:c[b]+"px",left:d-75+"px"})})}),a("#merge").click(function(){var b=null,c=null,d=m.find("td.ui-selected, th.ui-selected");if(0===d.length)return void j("#select-cells");if(d.each(function(){a(this).get(0).tagName.match(/td/i)?b=!0:a(this).get(0).tagName.match(/th/i)&&(c=!0)}),1==b&&1==c)return j("#cant-merge"),!1;if(1==b&&null==c)var f="td";else null==b&&1==c&&(f="th");a(f+".ui-selected").each(function(){return a(this).hasClass(t)?(a(".ui-selected").removeClass("ui-selected"),j("#cant-remerge"),!1):void 0});var h=p.val(),i=q.val(),k=a(f+".ui-selected").parent("tr").addClass("ui-selected").length,l=a(f+".ui-selected").length/k;if(h==k&&i==l)n.html("<tr><"+f+"></"+f+"></tr>");else{h!=k&&i==l?k>1&&(a("tr.ui-selected:not( tr.ui-selected:first )").remove(),k=1):h==k&&i!=l&&l>1&&(m.find("tr.ui-selected").each(function(){a(this).children(f+".ui-selected:not( .ui-selected:first )").remove()}),l=1);var o=(a("tr").index(a("tr.ui-selected:first")),a(f).index(a(f+".ui-selected:first")));if(i>o);else;a("tr.ui-selected").each(function(b){0==b?l>1&&a(this).children(f+".ui-selected:not(.ui-selected:first)").remove():a(this).children(f+".ui-selected").remove()}),l>1&&a(f+".ui-selected:first").attr("colspan",l).addClass(t),k>1&&a(f+".ui-selected:first").attr("rowspan",k).addClass(t);var r=a("tr:empty").length;r>0&&(m.find("[rowspan]").each(function(){var b=a(this).attr("rowspan")-r;a(this).attr("rowspan",b),1==a(this).attr("rowspan")&&a(this).removeAttr("rowspan")}),m.find("tr:empty").remove(),h-=r),a("."+t).each(function(){void 0===a(this).attr("rowspan")&&void 0===a(this).attr("colspan")&&a(this).removeClass(t)})}g(e())}),a("#replace").click(function(){var b=m.find("td.ui-selected, th.ui-selected");return 0===b.length?void j("#select-cells"):(b.each(function(){var b=a(this).text(),c=a(this).attr("colspan"),d=a(this).attr("rowspan"),e=a(this).attr("class"),f=a("td"==a(this).get(0).tagName.toLowerCase()?"<th>":"<td>");a(this).replaceWith(function(){return f.text(b),c&&f.attr("colspan",c),d&&f.attr("rowspan",d),e&&f.addClass(e).removeClass("ui-selected"),f})}),void g(e()))}),a("#split").click(function(){var a=m.find("td.ui-selected, th.ui-selected");return 0===a.length?void j("#select-cells"):(h(),void g(e()))}),a("#undo").click(function(){if(window.localStorage){var a=localStorage.getItem("undo");a--;var b=JSON.parse(localStorage.getItem("o"+a));p.val(b.row),q.val(b.col);var c=localStorage.getItem("data"+a);m.empty().html(c),localStorage.setItem("undo",a),g(c),f(),i()}}),a("#redo").click(function(){if(window.localStorage){var a=(localStorage.getItem("index"),localStorage.getItem("undo"));a++;var b=JSON.parse(localStorage.getItem("o"+a));p.val(b.row),q.val(b.col);var c=localStorage.getItem("data"+a);m.empty().html(c),localStorage.setItem("undo",a),g(c),f(),i()}}),a("#initialize").click(function(){c(p.val(),q.val()),g(),window.localStorage&&(localStorage.clear(),localStorage.setItem("index",0),localStorage.setItem("undo",0),localStorage.setItem("o0",JSON.stringify({row:p.val(),col:q.val()})),localStorage.setItem("data0",m.html())),i(),f()}),a("#insert").click(function(){var b=a("[name=source]","#generator").val();a("#content").insertAtCaret(b),tb_remove()}),a.fn.extend({insertAtCaret:function(a){var b=this.get(0);b.focus();var c=b.value,d=b.selectionStart,e=d+a.length;b.value=c.substr(0,d)+a+c.substr(d),b.setSelectionRange(e,e)}})});
Note: See TracChangeset for help on using the changeset viewer.