1 2/** 3 * å ¥åé ç®ã®ã°ã«ã¼ããèªåçã«å¢ããã¦ãã 4 * 5 *ãµã¼ãå´ã§ã® auto_list 颿°ãä½µç¨ããå¿ è¦ããã 6 */ 7$.widget("phf.auto_list",{ 8 options: { 9 //option 10 selector : ".js_auto_list", 11 12 //event 13 clone : function(){} 14 15 //method 16 }, 17 18 /** 19 * æ°ããè¡ã追å 20 */ 21 clone_list: function($list_item) { 22 //console.debug($list_item); 23 var $elm=this.element; 24 var ins=this; 25 var opt=ins.options; 26 var selector=opt.selector; 27 28 if(!ins.is_last($list_item)){ 29 return false; 30 } 31 32 var list_id=$list_item.attr("list_id"); 33 var max_index=ins.max_index($list_item); 34 35 var $tmpl=$list_item; 36 //console.debug($tmpl); 37 if(!ins.is_tmpl($list_item)){ 38 ins.list_live($(":input",$list_item),$list_item); 39 $tmpl=ins.get_tmpl($list_item); 40 } 41 42 $new_elm=$($tmpl.outerHTML().replace(new RegExp("\-\-\\(auto_list"+list_id+":index\\)\-\-","g"),max_index+1)); 43 44 $new_elm.removeAttr('style').css({'opacity':'0'}); 45 //$new_elm.insertBefore($tmpl).removeClass("js_list_tmpl").show(); 46 $new_elm.insertBefore($tmpl).removeClass("js_list_tmpl").animate({'opacity':1},{'duration':333,'complete':function(){}}); 47 48 opt.clone($new_elm); //event 49 /*ç¹å¥è¨è¿°*/ 50 if($('#editor_'+(max_index+1)).is('*')){if(CKEDITOR.instances['editor_'+(max_index+1)]){}else{CKEDITOR.replace('editor_'+(max_index+1));}} 51 for(var i=0;i<=(max_index+1);i++){ 52 if($('#editor1_'+i).is('*')){if(CKEDITOR.instances['editor1_'+i]){}else{CKEDITOR.replace('editor1_'+i);}} 53 if($('#editor2_'+i).is('*')){if(CKEDITOR.instances['editor2_'+i]){}else{CKEDITOR.replace('editor2_'+i);}} 54 if($('#editor3_'+i).is('*')){if(CKEDITOR.instances['editor3_'+i]){}else{CKEDITOR.replace('editor3_'+i);}} 55 if($('#editor4_'+i).is('*')){if(CKEDITOR.instances['editor4_'+i]){}else{CKEDITOR.replace('editor4_'+i);}} 56 if($('#editor5_'+i).is('*')){if(CKEDITOR.instances['editor5_'+i]){}else{CKEDITOR.replace('editor5_'+i);}} 57 } 58 }, 59 60 /** 61 * è¡åé¤ 62 */ 63 delete_line: function($list_item) { 64 var $elm=this.element; 65 var ins=this; 66 var opt=ins.options; 67 var selector=opt.selector; 68 69 if(!ins.is_last($list_item)){ 70 $list_item.animate({'opacity':0},{'duration':333,'complete':function(){ 71 $list_item.remove(); 72 }}); 73 } 74 }, 75 76 /** 77 * ä½åãã¼ã¿ç»é²é²æ¢ã®çºã«nameã«å ãã夿´ãå ã«æ»ã 78 */ 79 list_live: function($input,$list_item) { 80 //console.debug($input); 81 var $elm=this.element; 82 var ins=this; 83 var opt=ins.options; 84 var selector=opt.selector; 85 var list_id=$list_item.attr("list_id"); 86 87 $input.attr("name",function(i,val){if(isset(val))return val.replace("__dummy__"+list_id,'')}); 88 }, 89 90 //------------------------------------------ 91 // common function 92 //------------------------------------------ 93 94 /** 95 * æå¤§ã®list_indexãåå¾ 96 */ 97 max_index: function($list_item) { 98 var $elm=this.element; 99 var ins=this; 100 var opt=ins.options; 101 var selector=opt.selector; 102 103 var indexes=ins.siblings($list_item).andSelf().not(".js_list_tmpl").map(function(){ 104 return parseInt($(this).attr("list_index")); 105 }).toArray(); 106 //console.debug(indexes); 107 108 var max_index=-1; 109 if(indexes.length){ 110 max_index=max(indexes); 111 }; 112 113 return parseInt(max_index); 114 }, 115 116 /** 117 * ãã³ãã¬ã¼ããã©ãã 118 */ 119 is_tmpl: function($list_item) { 120 var $elm=this.element; 121 var ins=this; 122 var opt=ins.options; 123 var selector=opt.selector; 124 125 var flag=$list_item.is(".js_list_tmpl"); 126 return flag; 127 }, 128 129 /** 130 * æå®ããããªã¹ãã®ãã³ãã¬ã¼ããåå¾ 131 */ 132 get_tmpl: function($list_item) { 133 var $elm=this.element; 134 var ins=this; 135 var opt=ins.options; 136 var selector=opt.selector; 137 138 var $result=$list_item.nextUntil(":not("+selector+")").andSelf().filter(".js_list_tmpl").eq(0); 139 return $result; 140 }, 141 142 /** 143 * (ãã³ãã¬ã¼ããé¤ãã¦)ãªã¹ãã®æå¾ã®è¦ç´ ãã©ãã 144 */ 145 is_last: function($list_item) { 146 var $elm=this.element; 147 var ins=this; 148 var opt=ins.options; 149 var selector=opt.selector; 150 151 var flag=($list_item.is(selector) && !$list_item.nextUntil(":not("+selector+")",":not(.js_list_tmpl)").length); 152 return flag; 153 }, 154 155 /** 156 * æå®ããããªã¹ãã®ãã³ãã¬ã¼ããé¤ãæå¾ã®ãªã¹ã 157 */ 158 get_last: function($list_item) { 159 var $elm=this.element; 160 var ins=this; 161 var opt=ins.options; 162 var selector=opt.selector; 163 164 var $result=$list_item.nextUntil(":not("+selector+")").andSelf().not(".js_list_tmpl").last(); 165 return $result; 166 }, 167 168 /** 169 * æå®ããããªã¹ãè¦ç´ ã¨åããªã¹ãã®è¦ç´ ãå ¨ã¦é¸æ 170 */
171 siblings: function($list_item) { 172 var $elm=this.element; 173 var ins=this; 174 var opt=ins.options; 175 var selector=opt.selector; 176 177 //console.debug($list_item.prevUntil(":not("+selector+")").add($list_item.nextUntil(":not("+selector+")")).add($list_item).not(".js_list_tmpl")); 178 var $result=$list_item.prevUntil(":not("+selector+")").add($list_item.nextUntil(":not("+selector+")")).add($list_item).not(".js_list_tmpl"); 179 return $result; 180 }, 181 182 /** 183 * ãã®è¦ç´ ãå±ãã¦ãããªã¹ããåå¾ 184 */ 185 current_list: function($target) { 186 var $elm=this.element; 187 var ins=this; 188 var opt=ins.options; 189 var selector=opt.selector; 190 191 return $target.parents(selector).eq(0); 192 }, 193 194 /** 195 * ãã®è¦ç´ ãå±ãã¦ãããªã¹ãã親ã®ãªã¹ããå«ãã¦å ¨ã¦åå¾ 196 */ 197 current_lists: function($target) { 198 var $elm=this.element; 199 var ins=this; 200 var opt=ins.options; 201 var selector=opt.selector; 202 203 return $target.parents(selector); 204 }, 205 206 //------------------------------------------ 207 // init å¦ç 208 //------------------------------------------ 209 210 _init: function() { 211 var $elm=this.element; 212 var ins=this; 213 var opt=ins.options; 214 var selector=opt.selector; 215 216 //è¡ã®åé¤ 217 $(document).on("click",".js_list_delete",function(){ 218 //$(".js_list_delete").live("click",function(){ 219 if(confirm('ãã®ãã¼ã¿ãåé¤ãã¾ã\nããããã§ããï¼')){ 220 var $this=$(this); 221 //var $list_item=$this.parents(selector); 222 var $list_item=$this.parents(selector).eq(0); 223 ins.delete_line($list_item); 224 } 225 return false; 226 }); 227 228 //æå¾ã®è¦ç´ ã¯ãã³ãã¬ã¼ãç¨(ãµã¼ããµã¤ãããã³ãã¬ã¼ãç¨ã«ä¸ã¤ä½åã«åºåããããã«ãã) 229 $(selector).filter(function(){ 230 return !$(this).next(selector).length; //:last-childã§ã¯ãªã¹ã系以å¤ã®ã¿ã°ã«å¯¾å¿ã§ããªãçºä¸å¯ããã ãã®å¦çã¯éããããããªã 231 }).addClass('js_list_tmpl'); 232 233 //ãªã¹ãã®æå¾ã®ç©ºãã¼ã¿ããã³ãã¬ã¼ããå å·¥(ãããã®ãã¼ã¿ãç»é²ãããªãçºã«nameã夿´ããç) 234 $(".js_list_tmpl").hide(); 235 $($(".js_list_tmpl").get().reverse()).each(function (){ 236 var $val=$(this); 237 var $list_item=$(this); 238 $input=$val.find(":input"); 239 var list_id=$list_item.attr("list_id"); 240 $input.attr("name", function(i,val){if(isset(val) && val.indexOf("__dummy__"+list_id)==-1)return "__dummy__"+list_id+val;} ); 241 242 //ãã¼ã¸ã®ãã¼ãæç¹ã§æå¤§ããä¸ã¤å¤ãçæãã¦ãã 243 var $last=ins.get_last($val); 244 if(!$last.length){ 245 //ãªã¹ããã¾ã ä¸ã¤ããªãå ´å 246 ins.clone_list($val); 247 }else{ 248 $last.find(":input").last().change(); 249 } 250 }); 251 252 //ãªã¹ãã®æå¾ã®è¦ç´ ã«ä½ãå ¥åããããæ¬¡ã®è¦ç´ ãç¨æ 253 var clone_event={}; 254 255 $(document).on("change keyup paste",selector+" :input",clone_event=function(){ 256 //$(selector).find(":input").live("change keyup paste",clone_event=function(){ 257 var $this=$(this); 258 ins.current_lists($this).each(function(key){ 259 var $val=$(this); 260 ins.clone_list($val); 261 }); 262 }); 263 //è£ é£¾ããã¹ãã¨ãªã¢ããã¤ã³ã(ckeditorã«å¯¾å¿) 264 $(document.body).delegate(selector+" iframe","mouseover",function(){ 265 $("iframe").each(function(i){ 266 var $iframe=$(this); 267 if(!$iframe.data("auto_list_bind")){ 268 $iframe.data("auto_list_bind",true); 269 $(this).contents().delegate("body","change keyup paste",function(){ clone_event.apply($iframe.get(0)); }); 270 } 271 }); 272 }) 273 274 } 275}); 276
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.