From 91353af9af82f173de9bc9b3d005d1d01cb56be6 Mon Sep 17 00:00:00 2001 From: oizulain Date: Sat, 9 Jul 2016 00:14:08 +0200 Subject: [PATCH] Enhancement #8 - Refactoring String HTML --- dist/jquery.ddslick.min.js | 2 +- src/jquery.ddslick.js | 26 ++++++++++++-------------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/dist/jquery.ddslick.min.js b/dist/jquery.ddslick.min.js index ee3b266..a5ac61e 100644 --- a/dist/jquery.ddslick.min.js +++ b/dist/jquery.ddslick.min.js @@ -1 +1 @@ -!function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&module.exports?module.exports=e(require("jquery")):e(window.jQuery)}(function(e){function d(e,d){var i=e.find(".dd-option-value[value= '"+d+"']").parents("li").prevAll().length;t(e,i)}function t(e,d,t){var i=e.data("ddslick"),s=e.find(".dd-selected"),l=s.siblings(".dd-selected-value"),a=e.find(".dd-option").eq(d),c=a.closest("li"),r=i.settings,p=i.settings.data[d];e.find(".dd-option").removeClass("dd-option-selected"),a.addClass("dd-option-selected"),i.selectedIndex=d,i.selectedItem=c,i.selectedData=p,r.showSelectedHTML?s.html((p.imageSrc?"":"")+(p.text?"":"")+(p.description?""+p.description+"":"")):s.html(p.text),l.val(p.value),i.original.val(p.value),e.data("ddslick",i),n(e),o(e),t&&"function"==typeof r.onSelected&&r.onSelected.call(this,i)}function i(d){var t=d.find(".dd-select"),i=t.siblings(".dd-options"),n=t.find(".dd-pointer"),o=i.is(":visible"),l=a[d.attr("data-settings-id")];e(".dd-click-off-close").not(i).slideUp(l.animationTime),e(".dd-pointer").removeClass("dd-pointer-up"),t.removeClass("dd-open"),o?(i.slideUp(l.animationTime),n.removeClass("dd-pointer-up"),t.removeClass("dd-open")):(t.addClass("dd-open"),i.slideDown(l.animationTime),n.addClass("dd-pointer-up")),s(d)}function n(e){var d=a[e.attr("data-settings-id")];e.find(".dd-select").removeClass("dd-open"),e.find(".dd-options").slideUp(d.animationTime),e.find(".dd-pointer").removeClass("dd-pointer-up").removeClass("dd-pointer-up")}function o(e){var d=e.find(".dd-select").css("height"),t=e.find(".dd-selected-description"),i=e.find(".dd-selected-image");t.length<=0&&i.length>0&&e.find(".dd-selected-text").css("lineHeight",d)}function s(d){d.find(".dd-option").each(function(){var t=e(this),i=t.css("height"),n=t.find(".dd-option-description"),o=d.find(".dd-option-image");n.length<=0&&o.length>0&&t.find(".dd-option-text").css("lineHeight",i)})}e.fn.ddslick=function(d){return l[d]?l[d].apply(this,Array.prototype.slice.call(arguments,1)):"object"!=typeof d&&d?void e.error("Method "+d+" does not exists."):l.init.apply(this,arguments)};var l={},a={},c={data:[],keepJSONItemsOnTop:!1,animationTime:50,width:260,height:null,background:"#eee",selectText:"",defaultSelectedIndex:null,truncateDescription:!0,imagePosition:"left",showSelectedHTML:!0,clickOffToClose:!0,embedCSS:!0,onSelected:function(){}},r=!1,p="
",f="",u="";l.init=function(d){var n=e.extend({},c,d);return e("#css-ddslick").length<=0&&n.embedCSS&&e(u).appendTo("head"),this.each(function(){var n=e.extend({},c,d),o=e(this),s=o.data("ddslick");if(!s){var l=[];o.find("option").each(function(){var d=e(this),t=d.data();l.push({text:e.trim(d.text()),value:d.val(),selected:d.is(":selected"),description:t.description,imageSrc:t.imagesrc})}),n.keepJSONItemsOnTop?e.merge(n.data,l):n.data=e.merge(l,n.data);var u=o,h=e("
").attr("id",o.attr("id"));o.replaceWith(h),o=h;var m="ID_"+(new Date).getTime();e(o).attr("data-settings-id",m),a[m]={},e.extend(a[m],n),o.addClass("dd-container").append(p).append(f),o.find("input.dd-selected-value").attr("id",e(u).attr("id")).attr("name",e(u).attr("name"));var g=o.find(".dd-options");l=o.find(".dd-select"),g.css({width:n.width}),l.css({width:n.width,background:n.background}),o.css({width:n.width}),null!==n.height&&g.css({height:n.height,overflow:"auto"}),e.each(n.data,function(e,d){d.selected&&(n.defaultSelectedIndex=e),g.append("
  • "+(d.value?" ":"")+(d.imageSrc?" ":"")+(d.text?" ":"")+(d.description?" "+d.description+"":"")+"
  • ")});var v={settings:n,original:u,selectedIndex:-1,selectedItem:null,selectedData:null};if(o.data("ddslick",v),n.selectText.length>0&&null===n.defaultSelectedIndex)o.find(".dd-selected").html(n.selectText);else{var x=null!=n.defaultSelectedIndex&&n.defaultSelectedIndex>=0&&n.defaultSelectedIndex");f.imageSrc&&u.append(e("").addClass("dd-selected-image"+("right"===p.imagePosition?" dd-image-right":"")).attr("src",f.imageSrc)),f.text&&u.append(e("