@@ 12780-13277 (lines=498) @@ | ||
12777 | * |
|
12778 | */ |
|
12779 | ||
12780 | ;(function ($, window, document, undefined) { |
|
12781 | ||
12782 | "use strict"; |
|
12783 | ||
12784 | window = (typeof window != 'undefined' && window.Math == Math) |
|
12785 | ? window |
|
12786 | : (typeof self != 'undefined' && self.Math == Math) |
|
12787 | ? self |
|
12788 | : Function('return this')() |
|
12789 | ; |
|
12790 | ||
12791 | $.fn.rating = function(parameters) { |
|
12792 | var |
|
12793 | $allModules = $(this), |
|
12794 | moduleSelector = $allModules.selector || '', |
|
12795 | ||
12796 | time = new Date().getTime(), |
|
12797 | performance = [], |
|
12798 | ||
12799 | query = arguments[0], |
|
12800 | methodInvoked = (typeof query == 'string'), |
|
12801 | queryArguments = [].slice.call(arguments, 1), |
|
12802 | returnedValue |
|
12803 | ; |
|
12804 | $allModules |
|
12805 | .each(function() { |
|
12806 | var |
|
12807 | settings = ( $.isPlainObject(parameters) ) |
|
12808 | ? $.extend(true, {}, $.fn.rating.settings, parameters) |
|
12809 | : $.extend({}, $.fn.rating.settings), |
|
12810 | ||
12811 | namespace = settings.namespace, |
|
12812 | className = settings.className, |
|
12813 | metadata = settings.metadata, |
|
12814 | selector = settings.selector, |
|
12815 | error = settings.error, |
|
12816 | ||
12817 | eventNamespace = '.' + namespace, |
|
12818 | moduleNamespace = 'module-' + namespace, |
|
12819 | ||
12820 | element = this, |
|
12821 | instance = $(this).data(moduleNamespace), |
|
12822 | ||
12823 | $module = $(this), |
|
12824 | $icon = $module.find(selector.icon), |
|
12825 | ||
12826 | initialLoad, |
|
12827 | module |
|
12828 | ; |
|
12829 | ||
12830 | module = { |
|
12831 | ||
12832 | initialize: function() { |
|
12833 | module.verbose('Initializing rating module', settings); |
|
12834 | ||
12835 | if($icon.length === 0) { |
|
12836 | module.setup.layout(); |
|
12837 | } |
|
12838 | ||
12839 | if(settings.interactive) { |
|
12840 | module.enable(); |
|
12841 | } |
|
12842 | else { |
|
12843 | module.disable(); |
|
12844 | } |
|
12845 | module.set.initialLoad(); |
|
12846 | module.set.rating( module.get.initialRating() ); |
|
12847 | module.remove.initialLoad(); |
|
12848 | module.instantiate(); |
|
12849 | }, |
|
12850 | ||
12851 | instantiate: function() { |
|
12852 | module.verbose('Instantiating module', settings); |
|
12853 | instance = module; |
|
12854 | $module |
|
12855 | .data(moduleNamespace, module) |
|
12856 | ; |
|
12857 | }, |
|
12858 | ||
12859 | destroy: function() { |
|
12860 | module.verbose('Destroying previous instance', instance); |
|
12861 | module.remove.events(); |
|
12862 | $module |
|
12863 | .removeData(moduleNamespace) |
|
12864 | ; |
|
12865 | }, |
|
12866 | ||
12867 | refresh: function() { |
|
12868 | $icon = $module.find(selector.icon); |
|
12869 | }, |
|
12870 | ||
12871 | setup: { |
|
12872 | layout: function() { |
|
12873 | var |
|
12874 | maxRating = module.get.maxRating(), |
|
12875 | html = $.fn.rating.settings.templates.icon(maxRating) |
|
12876 | ; |
|
12877 | module.debug('Generating icon html dynamically'); |
|
12878 | $module |
|
12879 | .html(html) |
|
12880 | ; |
|
12881 | module.refresh(); |
|
12882 | } |
|
12883 | }, |
|
12884 | ||
12885 | event: { |
|
12886 | mouseenter: function() { |
|
12887 | var |
|
12888 | $activeIcon = $(this) |
|
12889 | ; |
|
12890 | $activeIcon |
|
12891 | .nextAll() |
|
12892 | .removeClass(className.selected) |
|
12893 | ; |
|
12894 | $module |
|
12895 | .addClass(className.selected) |
|
12896 | ; |
|
12897 | $activeIcon |
|
12898 | .addClass(className.selected) |
|
12899 | .prevAll() |
|
12900 | .addClass(className.selected) |
|
12901 | ; |
|
12902 | }, |
|
12903 | mouseleave: function() { |
|
12904 | $module |
|
12905 | .removeClass(className.selected) |
|
12906 | ; |
|
12907 | $icon |
|
12908 | .removeClass(className.selected) |
|
12909 | ; |
|
12910 | }, |
|
12911 | click: function() { |
|
12912 | var |
|
12913 | $activeIcon = $(this), |
|
12914 | currentRating = module.get.rating(), |
|
12915 | rating = $icon.index($activeIcon) + 1, |
|
12916 | canClear = (settings.clearable == 'auto') |
|
12917 | ? ($icon.length === 1) |
|
12918 | : settings.clearable |
|
12919 | ; |
|
12920 | if(canClear && currentRating == rating) { |
|
12921 | module.clearRating(); |
|
12922 | } |
|
12923 | else { |
|
12924 | module.set.rating( rating ); |
|
12925 | } |
|
12926 | } |
|
12927 | }, |
|
12928 | ||
12929 | clearRating: function() { |
|
12930 | module.debug('Clearing current rating'); |
|
12931 | module.set.rating(0); |
|
12932 | }, |
|
12933 | ||
12934 | bind: { |
|
12935 | events: function() { |
|
12936 | module.verbose('Binding events'); |
|
12937 | $module |
|
12938 | .on('mouseenter' + eventNamespace, selector.icon, module.event.mouseenter) |
|
12939 | .on('mouseleave' + eventNamespace, selector.icon, module.event.mouseleave) |
|
12940 | .on('click' + eventNamespace, selector.icon, module.event.click) |
|
12941 | ; |
|
12942 | } |
|
12943 | }, |
|
12944 | ||
12945 | remove: { |
|
12946 | events: function() { |
|
12947 | module.verbose('Removing events'); |
|
12948 | $module |
|
12949 | .off(eventNamespace) |
|
12950 | ; |
|
12951 | }, |
|
12952 | initialLoad: function() { |
|
12953 | initialLoad = false; |
|
12954 | } |
|
12955 | }, |
|
12956 | ||
12957 | enable: function() { |
|
12958 | module.debug('Setting rating to interactive mode'); |
|
12959 | module.bind.events(); |
|
12960 | $module |
|
12961 | .removeClass(className.disabled) |
|
12962 | ; |
|
12963 | }, |
|
12964 | ||
12965 | disable: function() { |
|
12966 | module.debug('Setting rating to read-only mode'); |
|
12967 | module.remove.events(); |
|
12968 | $module |
|
12969 | .addClass(className.disabled) |
|
12970 | ; |
|
12971 | }, |
|
12972 | ||
12973 | is: { |
|
12974 | initialLoad: function() { |
|
12975 | return initialLoad; |
|
12976 | } |
|
12977 | }, |
|
12978 | ||
12979 | get: { |
|
12980 | initialRating: function() { |
|
12981 | if($module.data(metadata.rating) !== undefined) { |
|
12982 | $module.removeData(metadata.rating); |
|
12983 | return $module.data(metadata.rating); |
|
12984 | } |
|
12985 | return settings.initialRating; |
|
12986 | }, |
|
12987 | maxRating: function() { |
|
12988 | if($module.data(metadata.maxRating) !== undefined) { |
|
12989 | $module.removeData(metadata.maxRating); |
|
12990 | return $module.data(metadata.maxRating); |
|
12991 | } |
|
12992 | return settings.maxRating; |
|
12993 | }, |
|
12994 | rating: function() { |
|
12995 | var |
|
12996 | currentRating = $icon.filter('.' + className.active).length |
|
12997 | ; |
|
12998 | module.verbose('Current rating retrieved', currentRating); |
|
12999 | return currentRating; |
|
13000 | } |
|
13001 | }, |
|
13002 | ||
13003 | set: { |
|
13004 | rating: function(rating) { |
|
13005 | var |
|
13006 | ratingIndex = (rating - 1 >= 0) |
|
13007 | ? (rating - 1) |
|
13008 | : 0, |
|
13009 | $activeIcon = $icon.eq(ratingIndex) |
|
13010 | ; |
|
13011 | $module |
|
13012 | .removeClass(className.selected) |
|
13013 | ; |
|
13014 | $icon |
|
13015 | .removeClass(className.selected) |
|
13016 | .removeClass(className.active) |
|
13017 | ; |
|
13018 | if(rating > 0) { |
|
13019 | module.verbose('Setting current rating to', rating); |
|
13020 | $activeIcon |
|
13021 | .prevAll() |
|
13022 | .addBack() |
|
13023 | .addClass(className.active) |
|
13024 | ; |
|
13025 | } |
|
13026 | if(!module.is.initialLoad()) { |
|
13027 | settings.onRate.call(element, rating); |
|
13028 | } |
|
13029 | }, |
|
13030 | initialLoad: function() { |
|
13031 | initialLoad = true; |
|
13032 | } |
|
13033 | }, |
|
13034 | ||
13035 | setting: function(name, value) { |
|
13036 | module.debug('Changing setting', name, value); |
|
13037 | if( $.isPlainObject(name) ) { |
|
13038 | $.extend(true, settings, name); |
|
13039 | } |
|
13040 | else if(value !== undefined) { |
|
13041 | if($.isPlainObject(settings[name])) { |
|
13042 | $.extend(true, settings[name], value); |
|
13043 | } |
|
13044 | else { |
|
13045 | settings[name] = value; |
|
13046 | } |
|
13047 | } |
|
13048 | else { |
|
13049 | return settings[name]; |
|
13050 | } |
|
13051 | }, |
|
13052 | internal: function(name, value) { |
|
13053 | if( $.isPlainObject(name) ) { |
|
13054 | $.extend(true, module, name); |
|
13055 | } |
|
13056 | else if(value !== undefined) { |
|
13057 | module[name] = value; |
|
13058 | } |
|
13059 | else { |
|
13060 | return module[name]; |
|
13061 | } |
|
13062 | }, |
|
13063 | debug: function() { |
|
13064 | if(!settings.silent && settings.debug) { |
|
13065 | if(settings.performance) { |
|
13066 | module.performance.log(arguments); |
|
13067 | } |
|
13068 | else { |
|
13069 | module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':'); |
|
13070 | module.debug.apply(console, arguments); |
|
13071 | } |
|
13072 | } |
|
13073 | }, |
|
13074 | verbose: function() { |
|
13075 | if(!settings.silent && settings.verbose && settings.debug) { |
|
13076 | if(settings.performance) { |
|
13077 | module.performance.log(arguments); |
|
13078 | } |
|
13079 | else { |
|
13080 | module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':'); |
|
13081 | module.verbose.apply(console, arguments); |
|
13082 | } |
|
13083 | } |
|
13084 | }, |
|
13085 | error: function() { |
|
13086 | if(!settings.silent) { |
|
13087 | module.error = Function.prototype.bind.call(console.error, console, settings.name + ':'); |
|
13088 | module.error.apply(console, arguments); |
|
13089 | } |
|
13090 | }, |
|
13091 | performance: { |
|
13092 | log: function(message) { |
|
13093 | var |
|
13094 | currentTime, |
|
13095 | executionTime, |
|
13096 | previousTime |
|
13097 | ; |
|
13098 | if(settings.performance) { |
|
13099 | currentTime = new Date().getTime(); |
|
13100 | previousTime = time || currentTime; |
|
13101 | executionTime = currentTime - previousTime; |
|
13102 | time = currentTime; |
|
13103 | performance.push({ |
|
13104 | 'Name' : message[0], |
|
13105 | 'Arguments' : [].slice.call(message, 1) || '', |
|
13106 | 'Element' : element, |
|
13107 | 'Execution Time' : executionTime |
|
13108 | }); |
|
13109 | } |
|
13110 | clearTimeout(module.performance.timer); |
|
13111 | module.performance.timer = setTimeout(module.performance.display, 500); |
|
13112 | }, |
|
13113 | display: function() { |
|
13114 | var |
|
13115 | title = settings.name + ':', |
|
13116 | totalTime = 0 |
|
13117 | ; |
|
13118 | time = false; |
|
13119 | clearTimeout(module.performance.timer); |
|
13120 | $.each(performance, function(index, data) { |
|
13121 | totalTime += data['Execution Time']; |
|
13122 | }); |
|
13123 | title += ' ' + totalTime + 'ms'; |
|
13124 | if(moduleSelector) { |
|
13125 | title += ' \'' + moduleSelector + '\''; |
|
13126 | } |
|
13127 | if($allModules.length > 1) { |
|
13128 | title += ' ' + '(' + $allModules.length + ')'; |
|
13129 | } |
|
13130 | if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) { |
|
13131 | console.groupCollapsed(title); |
|
13132 | if(console.table) { |
|
13133 | console.table(performance); |
|
13134 | } |
|
13135 | else { |
|
13136 | $.each(performance, function(index, data) { |
|
13137 | console.log(data['Name'] + ': ' + data['Execution Time']+'ms'); |
|
13138 | }); |
|
13139 | } |
|
13140 | console.groupEnd(); |
|
13141 | } |
|
13142 | performance = []; |
|
13143 | } |
|
13144 | }, |
|
13145 | invoke: function(query, passedArguments, context) { |
|
13146 | var |
|
13147 | object = instance, |
|
13148 | maxDepth, |
|
13149 | found, |
|
13150 | response |
|
13151 | ; |
|
13152 | passedArguments = passedArguments || queryArguments; |
|
13153 | context = element || context; |
|
13154 | if(typeof query == 'string' && object !== undefined) { |
|
13155 | query = query.split(/[\. ]/); |
|
13156 | maxDepth = query.length - 1; |
|
13157 | $.each(query, function(depth, value) { |
|
13158 | var camelCaseValue = (depth != maxDepth) |
|
13159 | ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1) |
|
13160 | : query |
|
13161 | ; |
|
13162 | if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) { |
|
13163 | object = object[camelCaseValue]; |
|
13164 | } |
|
13165 | else if( object[camelCaseValue] !== undefined ) { |
|
13166 | found = object[camelCaseValue]; |
|
13167 | return false; |
|
13168 | } |
|
13169 | else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) { |
|
13170 | object = object[value]; |
|
13171 | } |
|
13172 | else if( object[value] !== undefined ) { |
|
13173 | found = object[value]; |
|
13174 | return false; |
|
13175 | } |
|
13176 | else { |
|
13177 | return false; |
|
13178 | } |
|
13179 | }); |
|
13180 | } |
|
13181 | if ( $.isFunction( found ) ) { |
|
13182 | response = found.apply(context, passedArguments); |
|
13183 | } |
|
13184 | else if(found !== undefined) { |
|
13185 | response = found; |
|
13186 | } |
|
13187 | if($.isArray(returnedValue)) { |
|
13188 | returnedValue.push(response); |
|
13189 | } |
|
13190 | else if(returnedValue !== undefined) { |
|
13191 | returnedValue = [returnedValue, response]; |
|
13192 | } |
|
13193 | else if(response !== undefined) { |
|
13194 | returnedValue = response; |
|
13195 | } |
|
13196 | return found; |
|
13197 | } |
|
13198 | }; |
|
13199 | if(methodInvoked) { |
|
13200 | if(instance === undefined) { |
|
13201 | module.initialize(); |
|
13202 | } |
|
13203 | module.invoke(query); |
|
13204 | } |
|
13205 | else { |
|
13206 | if(instance !== undefined) { |
|
13207 | instance.invoke('destroy'); |
|
13208 | } |
|
13209 | module.initialize(); |
|
13210 | } |
|
13211 | }) |
|
13212 | ; |
|
13213 | ||
13214 | return (returnedValue !== undefined) |
|
13215 | ? returnedValue |
|
13216 | : this |
|
13217 | ; |
|
13218 | }; |
|
13219 | ||
13220 | $.fn.rating.settings = { |
|
13221 | ||
13222 | name : 'Rating', |
|
13223 | namespace : 'rating', |
|
13224 | ||
13225 | slent : false, |
|
13226 | debug : false, |
|
13227 | verbose : false, |
|
13228 | performance : true, |
|
13229 | ||
13230 | initialRating : 0, |
|
13231 | interactive : true, |
|
13232 | maxRating : 4, |
|
13233 | clearable : 'auto', |
|
13234 | ||
13235 | fireOnInit : false, |
|
13236 | ||
13237 | onRate : function(rating){}, |
|
13238 | ||
13239 | error : { |
|
13240 | method : 'The method you called is not defined', |
|
13241 | noMaximum : 'No maximum rating specified. Cannot generate HTML automatically' |
|
13242 | }, |
|
13243 | ||
13244 | ||
13245 | metadata: { |
|
13246 | rating : 'rating', |
|
13247 | maxRating : 'maxRating' |
|
13248 | }, |
|
13249 | ||
13250 | className : { |
|
13251 | active : 'active', |
|
13252 | disabled : 'disabled', |
|
13253 | selected : 'selected', |
|
13254 | loading : 'loading' |
|
13255 | }, |
|
13256 | ||
13257 | selector : { |
|
13258 | icon : '.icon' |
|
13259 | }, |
|
13260 | ||
13261 | templates: { |
|
13262 | icon: function(maxRating) { |
|
13263 | var |
|
13264 | icon = 1, |
|
13265 | html = '' |
|
13266 | ; |
|
13267 | while(icon <= maxRating) { |
|
13268 | html += '<i class="icon"></i>'; |
|
13269 | icon++; |
|
13270 | } |
|
13271 | return html; |
|
13272 | } |
|
13273 | } |
|
13274 | ||
13275 | }; |
|
13276 | ||
13277 | })( jQuery, window, document ); |
|
13278 | ||
13279 | /*! |
|
13280 | * # Semantic UI 2.2.11 - Search |
@@ 11-508 (lines=498) @@ | ||
8 | * |
|
9 | */ |
|
10 | ||
11 | ;(function ($, window, document, undefined) { |
|
12 | ||
13 | "use strict"; |
|
14 | ||
15 | window = (typeof window != 'undefined' && window.Math == Math) |
|
16 | ? window |
|
17 | : (typeof self != 'undefined' && self.Math == Math) |
|
18 | ? self |
|
19 | : Function('return this')() |
|
20 | ; |
|
21 | ||
22 | $.fn.rating = function(parameters) { |
|
23 | var |
|
24 | $allModules = $(this), |
|
25 | moduleSelector = $allModules.selector || '', |
|
26 | ||
27 | time = new Date().getTime(), |
|
28 | performance = [], |
|
29 | ||
30 | query = arguments[0], |
|
31 | methodInvoked = (typeof query == 'string'), |
|
32 | queryArguments = [].slice.call(arguments, 1), |
|
33 | returnedValue |
|
34 | ; |
|
35 | $allModules |
|
36 | .each(function() { |
|
37 | var |
|
38 | settings = ( $.isPlainObject(parameters) ) |
|
39 | ? $.extend(true, {}, $.fn.rating.settings, parameters) |
|
40 | : $.extend({}, $.fn.rating.settings), |
|
41 | ||
42 | namespace = settings.namespace, |
|
43 | className = settings.className, |
|
44 | metadata = settings.metadata, |
|
45 | selector = settings.selector, |
|
46 | error = settings.error, |
|
47 | ||
48 | eventNamespace = '.' + namespace, |
|
49 | moduleNamespace = 'module-' + namespace, |
|
50 | ||
51 | element = this, |
|
52 | instance = $(this).data(moduleNamespace), |
|
53 | ||
54 | $module = $(this), |
|
55 | $icon = $module.find(selector.icon), |
|
56 | ||
57 | initialLoad, |
|
58 | module |
|
59 | ; |
|
60 | ||
61 | module = { |
|
62 | ||
63 | initialize: function() { |
|
64 | module.verbose('Initializing rating module', settings); |
|
65 | ||
66 | if($icon.length === 0) { |
|
67 | module.setup.layout(); |
|
68 | } |
|
69 | ||
70 | if(settings.interactive) { |
|
71 | module.enable(); |
|
72 | } |
|
73 | else { |
|
74 | module.disable(); |
|
75 | } |
|
76 | module.set.initialLoad(); |
|
77 | module.set.rating( module.get.initialRating() ); |
|
78 | module.remove.initialLoad(); |
|
79 | module.instantiate(); |
|
80 | }, |
|
81 | ||
82 | instantiate: function() { |
|
83 | module.verbose('Instantiating module', settings); |
|
84 | instance = module; |
|
85 | $module |
|
86 | .data(moduleNamespace, module) |
|
87 | ; |
|
88 | }, |
|
89 | ||
90 | destroy: function() { |
|
91 | module.verbose('Destroying previous instance', instance); |
|
92 | module.remove.events(); |
|
93 | $module |
|
94 | .removeData(moduleNamespace) |
|
95 | ; |
|
96 | }, |
|
97 | ||
98 | refresh: function() { |
|
99 | $icon = $module.find(selector.icon); |
|
100 | }, |
|
101 | ||
102 | setup: { |
|
103 | layout: function() { |
|
104 | var |
|
105 | maxRating = module.get.maxRating(), |
|
106 | html = $.fn.rating.settings.templates.icon(maxRating) |
|
107 | ; |
|
108 | module.debug('Generating icon html dynamically'); |
|
109 | $module |
|
110 | .html(html) |
|
111 | ; |
|
112 | module.refresh(); |
|
113 | } |
|
114 | }, |
|
115 | ||
116 | event: { |
|
117 | mouseenter: function() { |
|
118 | var |
|
119 | $activeIcon = $(this) |
|
120 | ; |
|
121 | $activeIcon |
|
122 | .nextAll() |
|
123 | .removeClass(className.selected) |
|
124 | ; |
|
125 | $module |
|
126 | .addClass(className.selected) |
|
127 | ; |
|
128 | $activeIcon |
|
129 | .addClass(className.selected) |
|
130 | .prevAll() |
|
131 | .addClass(className.selected) |
|
132 | ; |
|
133 | }, |
|
134 | mouseleave: function() { |
|
135 | $module |
|
136 | .removeClass(className.selected) |
|
137 | ; |
|
138 | $icon |
|
139 | .removeClass(className.selected) |
|
140 | ; |
|
141 | }, |
|
142 | click: function() { |
|
143 | var |
|
144 | $activeIcon = $(this), |
|
145 | currentRating = module.get.rating(), |
|
146 | rating = $icon.index($activeIcon) + 1, |
|
147 | canClear = (settings.clearable == 'auto') |
|
148 | ? ($icon.length === 1) |
|
149 | : settings.clearable |
|
150 | ; |
|
151 | if(canClear && currentRating == rating) { |
|
152 | module.clearRating(); |
|
153 | } |
|
154 | else { |
|
155 | module.set.rating( rating ); |
|
156 | } |
|
157 | } |
|
158 | }, |
|
159 | ||
160 | clearRating: function() { |
|
161 | module.debug('Clearing current rating'); |
|
162 | module.set.rating(0); |
|
163 | }, |
|
164 | ||
165 | bind: { |
|
166 | events: function() { |
|
167 | module.verbose('Binding events'); |
|
168 | $module |
|
169 | .on('mouseenter' + eventNamespace, selector.icon, module.event.mouseenter) |
|
170 | .on('mouseleave' + eventNamespace, selector.icon, module.event.mouseleave) |
|
171 | .on('click' + eventNamespace, selector.icon, module.event.click) |
|
172 | ; |
|
173 | } |
|
174 | }, |
|
175 | ||
176 | remove: { |
|
177 | events: function() { |
|
178 | module.verbose('Removing events'); |
|
179 | $module |
|
180 | .off(eventNamespace) |
|
181 | ; |
|
182 | }, |
|
183 | initialLoad: function() { |
|
184 | initialLoad = false; |
|
185 | } |
|
186 | }, |
|
187 | ||
188 | enable: function() { |
|
189 | module.debug('Setting rating to interactive mode'); |
|
190 | module.bind.events(); |
|
191 | $module |
|
192 | .removeClass(className.disabled) |
|
193 | ; |
|
194 | }, |
|
195 | ||
196 | disable: function() { |
|
197 | module.debug('Setting rating to read-only mode'); |
|
198 | module.remove.events(); |
|
199 | $module |
|
200 | .addClass(className.disabled) |
|
201 | ; |
|
202 | }, |
|
203 | ||
204 | is: { |
|
205 | initialLoad: function() { |
|
206 | return initialLoad; |
|
207 | } |
|
208 | }, |
|
209 | ||
210 | get: { |
|
211 | initialRating: function() { |
|
212 | if($module.data(metadata.rating) !== undefined) { |
|
213 | $module.removeData(metadata.rating); |
|
214 | return $module.data(metadata.rating); |
|
215 | } |
|
216 | return settings.initialRating; |
|
217 | }, |
|
218 | maxRating: function() { |
|
219 | if($module.data(metadata.maxRating) !== undefined) { |
|
220 | $module.removeData(metadata.maxRating); |
|
221 | return $module.data(metadata.maxRating); |
|
222 | } |
|
223 | return settings.maxRating; |
|
224 | }, |
|
225 | rating: function() { |
|
226 | var |
|
227 | currentRating = $icon.filter('.' + className.active).length |
|
228 | ; |
|
229 | module.verbose('Current rating retrieved', currentRating); |
|
230 | return currentRating; |
|
231 | } |
|
232 | }, |
|
233 | ||
234 | set: { |
|
235 | rating: function(rating) { |
|
236 | var |
|
237 | ratingIndex = (rating - 1 >= 0) |
|
238 | ? (rating - 1) |
|
239 | : 0, |
|
240 | $activeIcon = $icon.eq(ratingIndex) |
|
241 | ; |
|
242 | $module |
|
243 | .removeClass(className.selected) |
|
244 | ; |
|
245 | $icon |
|
246 | .removeClass(className.selected) |
|
247 | .removeClass(className.active) |
|
248 | ; |
|
249 | if(rating > 0) { |
|
250 | module.verbose('Setting current rating to', rating); |
|
251 | $activeIcon |
|
252 | .prevAll() |
|
253 | .addBack() |
|
254 | .addClass(className.active) |
|
255 | ; |
|
256 | } |
|
257 | if(!module.is.initialLoad()) { |
|
258 | settings.onRate.call(element, rating); |
|
259 | } |
|
260 | }, |
|
261 | initialLoad: function() { |
|
262 | initialLoad = true; |
|
263 | } |
|
264 | }, |
|
265 | ||
266 | setting: function(name, value) { |
|
267 | module.debug('Changing setting', name, value); |
|
268 | if( $.isPlainObject(name) ) { |
|
269 | $.extend(true, settings, name); |
|
270 | } |
|
271 | else if(value !== undefined) { |
|
272 | if($.isPlainObject(settings[name])) { |
|
273 | $.extend(true, settings[name], value); |
|
274 | } |
|
275 | else { |
|
276 | settings[name] = value; |
|
277 | } |
|
278 | } |
|
279 | else { |
|
280 | return settings[name]; |
|
281 | } |
|
282 | }, |
|
283 | internal: function(name, value) { |
|
284 | if( $.isPlainObject(name) ) { |
|
285 | $.extend(true, module, name); |
|
286 | } |
|
287 | else if(value !== undefined) { |
|
288 | module[name] = value; |
|
289 | } |
|
290 | else { |
|
291 | return module[name]; |
|
292 | } |
|
293 | }, |
|
294 | debug: function() { |
|
295 | if(!settings.silent && settings.debug) { |
|
296 | if(settings.performance) { |
|
297 | module.performance.log(arguments); |
|
298 | } |
|
299 | else { |
|
300 | module.debug = Function.prototype.bind.call(console.info, console, settings.name + ':'); |
|
301 | module.debug.apply(console, arguments); |
|
302 | } |
|
303 | } |
|
304 | }, |
|
305 | verbose: function() { |
|
306 | if(!settings.silent && settings.verbose && settings.debug) { |
|
307 | if(settings.performance) { |
|
308 | module.performance.log(arguments); |
|
309 | } |
|
310 | else { |
|
311 | module.verbose = Function.prototype.bind.call(console.info, console, settings.name + ':'); |
|
312 | module.verbose.apply(console, arguments); |
|
313 | } |
|
314 | } |
|
315 | }, |
|
316 | error: function() { |
|
317 | if(!settings.silent) { |
|
318 | module.error = Function.prototype.bind.call(console.error, console, settings.name + ':'); |
|
319 | module.error.apply(console, arguments); |
|
320 | } |
|
321 | }, |
|
322 | performance: { |
|
323 | log: function(message) { |
|
324 | var |
|
325 | currentTime, |
|
326 | executionTime, |
|
327 | previousTime |
|
328 | ; |
|
329 | if(settings.performance) { |
|
330 | currentTime = new Date().getTime(); |
|
331 | previousTime = time || currentTime; |
|
332 | executionTime = currentTime - previousTime; |
|
333 | time = currentTime; |
|
334 | performance.push({ |
|
335 | 'Name' : message[0], |
|
336 | 'Arguments' : [].slice.call(message, 1) || '', |
|
337 | 'Element' : element, |
|
338 | 'Execution Time' : executionTime |
|
339 | }); |
|
340 | } |
|
341 | clearTimeout(module.performance.timer); |
|
342 | module.performance.timer = setTimeout(module.performance.display, 500); |
|
343 | }, |
|
344 | display: function() { |
|
345 | var |
|
346 | title = settings.name + ':', |
|
347 | totalTime = 0 |
|
348 | ; |
|
349 | time = false; |
|
350 | clearTimeout(module.performance.timer); |
|
351 | $.each(performance, function(index, data) { |
|
352 | totalTime += data['Execution Time']; |
|
353 | }); |
|
354 | title += ' ' + totalTime + 'ms'; |
|
355 | if(moduleSelector) { |
|
356 | title += ' \'' + moduleSelector + '\''; |
|
357 | } |
|
358 | if($allModules.length > 1) { |
|
359 | title += ' ' + '(' + $allModules.length + ')'; |
|
360 | } |
|
361 | if( (console.group !== undefined || console.table !== undefined) && performance.length > 0) { |
|
362 | console.groupCollapsed(title); |
|
363 | if(console.table) { |
|
364 | console.table(performance); |
|
365 | } |
|
366 | else { |
|
367 | $.each(performance, function(index, data) { |
|
368 | console.log(data['Name'] + ': ' + data['Execution Time']+'ms'); |
|
369 | }); |
|
370 | } |
|
371 | console.groupEnd(); |
|
372 | } |
|
373 | performance = []; |
|
374 | } |
|
375 | }, |
|
376 | invoke: function(query, passedArguments, context) { |
|
377 | var |
|
378 | object = instance, |
|
379 | maxDepth, |
|
380 | found, |
|
381 | response |
|
382 | ; |
|
383 | passedArguments = passedArguments || queryArguments; |
|
384 | context = element || context; |
|
385 | if(typeof query == 'string' && object !== undefined) { |
|
386 | query = query.split(/[\. ]/); |
|
387 | maxDepth = query.length - 1; |
|
388 | $.each(query, function(depth, value) { |
|
389 | var camelCaseValue = (depth != maxDepth) |
|
390 | ? value + query[depth + 1].charAt(0).toUpperCase() + query[depth + 1].slice(1) |
|
391 | : query |
|
392 | ; |
|
393 | if( $.isPlainObject( object[camelCaseValue] ) && (depth != maxDepth) ) { |
|
394 | object = object[camelCaseValue]; |
|
395 | } |
|
396 | else if( object[camelCaseValue] !== undefined ) { |
|
397 | found = object[camelCaseValue]; |
|
398 | return false; |
|
399 | } |
|
400 | else if( $.isPlainObject( object[value] ) && (depth != maxDepth) ) { |
|
401 | object = object[value]; |
|
402 | } |
|
403 | else if( object[value] !== undefined ) { |
|
404 | found = object[value]; |
|
405 | return false; |
|
406 | } |
|
407 | else { |
|
408 | return false; |
|
409 | } |
|
410 | }); |
|
411 | } |
|
412 | if ( $.isFunction( found ) ) { |
|
413 | response = found.apply(context, passedArguments); |
|
414 | } |
|
415 | else if(found !== undefined) { |
|
416 | response = found; |
|
417 | } |
|
418 | if($.isArray(returnedValue)) { |
|
419 | returnedValue.push(response); |
|
420 | } |
|
421 | else if(returnedValue !== undefined) { |
|
422 | returnedValue = [returnedValue, response]; |
|
423 | } |
|
424 | else if(response !== undefined) { |
|
425 | returnedValue = response; |
|
426 | } |
|
427 | return found; |
|
428 | } |
|
429 | }; |
|
430 | if(methodInvoked) { |
|
431 | if(instance === undefined) { |
|
432 | module.initialize(); |
|
433 | } |
|
434 | module.invoke(query); |
|
435 | } |
|
436 | else { |
|
437 | if(instance !== undefined) { |
|
438 | instance.invoke('destroy'); |
|
439 | } |
|
440 | module.initialize(); |
|
441 | } |
|
442 | }) |
|
443 | ; |
|
444 | ||
445 | return (returnedValue !== undefined) |
|
446 | ? returnedValue |
|
447 | : this |
|
448 | ; |
|
449 | }; |
|
450 | ||
451 | $.fn.rating.settings = { |
|
452 | ||
453 | name : 'Rating', |
|
454 | namespace : 'rating', |
|
455 | ||
456 | slent : false, |
|
457 | debug : false, |
|
458 | verbose : false, |
|
459 | performance : true, |
|
460 | ||
461 | initialRating : 0, |
|
462 | interactive : true, |
|
463 | maxRating : 4, |
|
464 | clearable : 'auto', |
|
465 | ||
466 | fireOnInit : false, |
|
467 | ||
468 | onRate : function(rating){}, |
|
469 | ||
470 | error : { |
|
471 | method : 'The method you called is not defined', |
|
472 | noMaximum : 'No maximum rating specified. Cannot generate HTML automatically' |
|
473 | }, |
|
474 | ||
475 | ||
476 | metadata: { |
|
477 | rating : 'rating', |
|
478 | maxRating : 'maxRating' |
|
479 | }, |
|
480 | ||
481 | className : { |
|
482 | active : 'active', |
|
483 | disabled : 'disabled', |
|
484 | selected : 'selected', |
|
485 | loading : 'loading' |
|
486 | }, |
|
487 | ||
488 | selector : { |
|
489 | icon : '.icon' |
|
490 | }, |
|
491 | ||
492 | templates: { |
|
493 | icon: function(maxRating) { |
|
494 | var |
|
495 | icon = 1, |
|
496 | html = '' |
|
497 | ; |
|
498 | while(icon <= maxRating) { |
|
499 | html += '<i class="icon"></i>'; |
|
500 | icon++; |
|
501 | } |
|
502 | return html; |
|
503 | } |
|
504 | } |
|
505 | ||
506 | }; |
|
507 | ||
508 | })( jQuery, window, document ); |
|
509 |