2
2
'use strict' ;
3
3
// For more information about browser field, check out the browser field at https://github.com/substack/browserify-handbook#browser-field.
4
4
5
+ var styleElementsInsertedAtTop = [ ] ;
6
+
7
+ var insertStyleElement = function ( styleElement , options ) {
8
+ var head = document . head || document . getElementsByTagName ( 'head' ) [ 0 ] ;
9
+ var lastStyleElementInsertedAtTop = styleElementsInsertedAtTop [ styleElementsInsertedAtTop . length - 1 ] ;
10
+
11
+ options = options || { } ;
12
+ options . insertAt = options . insertAt || 'bottom' ;
13
+
14
+ if ( options . insertAt === 'top' ) {
15
+ if ( ! lastStyleElementInsertedAtTop ) {
16
+ head . insertBefore ( styleElement , head . firstChild ) ;
17
+ } else if ( lastStyleElementInsertedAtTop . nextSibling ) {
18
+ head . insertBefore ( styleElement , lastStyleElementInsertedAtTop . nextSibling ) ;
19
+ } else {
20
+ head . appendChild ( styleElement ) ;
21
+ }
22
+ styleElementsInsertedAtTop . push ( styleElement ) ;
23
+ } else if ( options . insertAt === 'bottom' ) {
24
+ head . appendChild ( styleElement ) ;
25
+ } else {
26
+ throw new Error ( 'Invalid value for parameter \'insertAt\'. Must be \'top\' or \'bottom\'.' ) ;
27
+ }
28
+ } ;
29
+
5
30
module . exports = {
6
31
// Create a <link> tag with optional data attributes
7
32
createLink : function ( href , attributes ) {
@@ -22,10 +47,10 @@ module.exports = {
22
47
head . appendChild ( link ) ;
23
48
} ,
24
49
// Create a <style> tag with optional data attributes
25
- createStyle : function ( cssText , attributes ) {
26
- var head = document . head || document . getElementsByTagName ( 'head' ) [ 0 ] ,
27
- style = document . createElement ( 'style' ) ;
50
+ createStyle : function ( cssText , attributes , extraOptions ) {
51
+ extraOptions = extraOptions || { } ;
28
52
53
+ var style = document . createElement ( 'style' ) ;
29
54
style . type = 'text/css' ;
30
55
31
56
for ( var key in attributes ) {
@@ -35,17 +60,17 @@ module.exports = {
35
60
var value = attributes [ key ] ;
36
61
style . setAttribute ( 'data-' + key , value ) ;
37
62
}
38
-
63
+
39
64
if ( style . sheet ) { // for jsdom and IE9+
40
65
style . innerHTML = cssText ;
41
66
style . sheet . cssText = cssText ;
42
- head . appendChild ( style ) ;
67
+ insertStyleElement ( style , { insertAt : extraOptions . insertAt } ) ;
43
68
} else if ( style . styleSheet ) { // for IE8 and below
44
- head . appendChild ( style ) ;
69
+ insertStyleElement ( style , { insertAt : extraOptions . insertAt } ) ;
45
70
style . styleSheet . cssText = cssText ;
46
71
} else { // for Chrome, Firefox, and Safari
47
72
style . appendChild ( document . createTextNode ( cssText ) ) ;
48
- head . appendChild ( style ) ;
73
+ insertStyleElement ( style , { insertAt : extraOptions . insertAt } ) ;
49
74
}
50
75
}
51
76
} ;
@@ -57,7 +82,8 @@ angular
57
82
bindings : {
58
83
menuOptions : '<' ,
59
84
data : '<' ,
60
- closeMenu : '&'
85
+ closeMenu : '&' ,
86
+ options : '<'
61
87
} ,
62
88
templateUrl : 'src/component/menu.html' ,
63
89
controller : function ( ) {
@@ -80,7 +106,7 @@ angular
80
106
}
81
107
} )
82
108
} , { } ] , 3 :[ function ( require , module , exports ) {
83
- var css = ".sh_menu_container {\n position: fixed;\n height: auto;\n background: #ececec;\n z-index: 90001;\n min-width: 150px;\n border: 0.5px solid rgba(0,0,0,0.2);\n border-radius: 2.5px;\n box-shadow: 0px 0px 10px 2px rgba(0,0,0,0.1);\n}\n.sh_menu_container ul {\n list-style: none;\n padding: 5px 0;\n margin: 0;\n}\n.sh_menu_container ul li {\n padding-right: 10px;\n padding-left: 15px;\n padding-bottom: 5px;\n padding-top: 5px;\n transition: all 0.15s;\n}\n.sh_menu_container ul li.sh_menu_item:hover {\n cursor: pointer;\n background: #4b8bec;\n color: white;\n}\n.sh_context_mask {\n position: fixed;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n z-index: 90000;\n}\n.sh_menu_divider {\n height: 1px;\n margin: 1px 1px 8px 1px;\n overflow: hidden;\n background-color: #ececec;\n border-bottom: 1px solid #d0d0d0;\n line-height: 10px;\n}\n.sh_menu_container ul li.sh_menu_disabled {\n color: #d0d0d0;\n}\n.sh_menu_container ul li.sh_menu_disabled:hover {\n cursor: not-allowed;\n color: #d0d0d0;\n background: #ececec;\n}\n" ; ( require ( "browserify-css" ) . createStyle ( css , { "href" : "src/component/menu.css" } ) ) ; module . exports = css ;
109
+ var css = ".sh_menu_container {\n position: fixed;\n height: auto;\n background: #ececec;\n z-index: 90001;\n min-width: 150px;\n border: 0.5px solid rgba(0,0,0,0.2);\n border-radius: 2.5px;\n box-shadow: 0px 0px 10px 2px rgba(0,0,0,0.1);\n}\n.sh_menu_container ul {\n list-style: none;\n padding: 5px 0;\n margin: 0;\n}\n.sh_menu_container ul.sh_menu_rtl {\n direction: rtl;\n}\n.sh_menu_container ul li {\n padding-right: 10px;\n padding-left: 15px;\n padding-bottom: 5px;\n padding-top: 5px;\n transition: all 0.15s;\n}\n.sh_menu_container ul li.sh_menu_item:hover {\n cursor: pointer;\n background: #4b8bec;\n color: white;\n}\n.sh_context_mask {\n position: fixed;\n top: 0;\n bottom: 0;\n left: 0;\n right: 0;\n z-index: 90000;\n}\n.sh_menu_divider {\n height: 1px;\n margin: 1px 1px 8px 1px;\n overflow: hidden;\n background-color: #ececec;\n border-bottom: 1px solid #d0d0d0;\n line-height: 10px;\n}\n.sh_menu_container ul li.sh_menu_disabled {\n color: #d0d0d0;\n}\n.sh_menu_container ul li.sh_menu_disabled:hover {\n cursor: not-allowed;\n color: #d0d0d0;\n background: #ececec;\n}\n" ; ( require ( "browserify-css" ) . createStyle ( css , { "href" : "src/component/menu.css" } , { "insertAt" : "bottom" } ) ) ; module . exports = css ;
84
110
} , { "browserify-css" :1 } ] , 4 :[ function ( require , module , exports ) {
85
111
require ( './component/menu.component.js' ) ;
86
112
require ( './component/menu.css' ) ;
@@ -96,7 +122,8 @@ angular
96
122
return {
97
123
scope : {
98
124
menuOptions : '<' ,
99
- contextData : '<'
125
+ contextData : '<' ,
126
+ options : '<'
100
127
} ,
101
128
bindToController : true ,
102
129
controllerAs : '$ctrl' ,
@@ -105,30 +132,42 @@ angular
105
132
var menuElement ,
106
133
maskElement ;
107
134
135
+ var defaultOptions = {
136
+ rtl : false
137
+ }
138
+
108
139
ctrl . destroyElements = function ( ) {
109
140
destroyElements ( ) ;
110
141
}
111
142
143
+ ctrl . options = ctrl . options || defaultOptions ;
144
+
112
145
element . on ( 'contextmenu' , function ( event ) {
113
146
event . preventDefault ( ) ;
114
147
var body = angular . element ( document . body ) ;
115
148
116
149
menuElement = buildMenuElement ( ) ;
117
150
maskElement = buildMaskElement ( ) ;
118
151
119
- setMenuPosition ( menuElement , event ) ;
120
-
121
152
body . append ( menuElement ) ;
122
153
body . append ( maskElement ) ;
154
+
155
+ setMenuPosition ( menuElement , event , ctrl . options ) ;
123
156
} ) ;
124
157
125
- function setMenuPosition ( menuElement , event ) {
158
+ function setMenuPosition ( menuElement , event , options ) {
159
+ var elmWidth = menuElement [ 0 ] . offsetWidth ;
160
+ var clientX = event . clientX ;
161
+
162
+ if ( options . rtl )
163
+ clientX = clientX - elmWidth ;
164
+
126
165
menuElement [ 0 ] . style . top = event . clientY + "px" ;
127
- menuElement [ 0 ] . style . left = event . clientX + "px" ;
166
+ menuElement [ 0 ] . style . left = clientX + "px" ;
128
167
}
129
168
130
169
function buildMenuElement ( ) {
131
- var $elm = angular . element ( '<context-menu close-menu="$ctrl.destroyElements()" menu-options="$ctrl.menuOptions" data="$ctrl.contextData" class="sh_menu_container"></context-menu>' ) ;
170
+ var $elm = angular . element ( '<context-menu options="$ctrl.options" close-menu="$ctrl.destroyElements()" menu-options="$ctrl.menuOptions" data="$ctrl.contextData" class="sh_menu_container"></context-menu>' ) ;
132
171
var linkFun = $compile ( $elm ) ;
133
172
var content = linkFun ( $scope ) ;
134
173
0 commit comments